Skip to content

fix: replace unmanaged thread creation with bounded ExecutorService in JobConfigurationServiceImpl#796

Open
CodeBySayak wants to merge 2 commits into
mosip:masterfrom
CodeBySayak:excthdl
Open

fix: replace unmanaged thread creation with bounded ExecutorService in JobConfigurationServiceImpl#796
CodeBySayak wants to merge 2 commits into
mosip:masterfrom
CodeBySayak:excthdl

Conversation

@CodeBySayak
Copy link
Copy Markdown

Summary

This PR fixes unmanaged thread proliferation in JobConfigurationServiceImpl.java where raw new Thread().start() calls were used to execute missed job triggers during application startup. Previously, each missed job spawned an unbounded unmanaged thread, which could lead to resource exhaustion when a large number of sync jobs were configured.


Changes

  • Added a bounded ExecutorService using:
Executors.newFixedThreadPool(5)

as a class-level field to manage lifecycle and concurrency of background tasks.

  • Replaced:
new Thread(() -> executeMissedTrigger(...)).start();

with:

missedTriggerExecutor.submit(...)

to ensure thread creation is controlled and centrally managed.


Why is this needed?

On every application startup, executeMissedTriggers() iterates over all active sync jobs and creates a new thread per missed trigger execution. The previous implementation had no upper bound on thread creation, which could result in:

  • Thread exhaustion under heavy configuration
  • Increased JVM resource usage
  • No graceful shutdown mechanism
  • Silent exception swallowing inside anonymous threads
  • Poor observability and thread lifecycle management
    Using a fixed thread pool of size 5 ensures missed triggers are still processed concurrently while keeping concurrency within safe, bounded limits.

Impact

  • Prevents unbounded thread creation during startup
  • Improves application stability and resource management
  • Adds controlled concurrency for missed trigger execution
  • Maintains existing asynchronous behavior with no functional changes

fixes #795

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Warning

Rate limit exceeded

@CodeBySayak has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 32 minutes and 18 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7e171d97-32ca-4173-88b0-0f341cce36e7

📥 Commits

Reviewing files that changed from the base of the PR and between 22fe01f and bd63435.

📒 Files selected for processing (2)
  • registration/registration-services/src/main/java/io/mosip/registration/context/ApplicationContext.java
  • registration/registration-services/src/main/java/io/mosip/registration/service/config/impl/JobConfigurationServiceImpl.java

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Unmanaged thread proliferation in JobConfigurationServiceImpl causes potential resource exhaustion

1 participant