[IOTDB-17268] Optimize: replace unbounded thread pool with bounded ThreadPoolExecutor in SessionPoolExample#17287
Open
ShauryaChauhan1411 wants to merge 1 commit intoapache:masterfrom
Conversation
…or in SessionPoolExample
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the current SessionPoolExample.java, the ExecutorService was using Executors.newFixedThreadPool(10). While it limits the number of active threads, it uses an unbounded LinkedBlockingQueue by default. In a high-throughput scenario, this can lead to an excessive number of queued tasks, potentially causing an OutOfMemoryError (OOM).
This PR replaces the default fixed thread pool with a manually configured ThreadPoolExecutor that uses:
Core/Max Pool Size: 10 threads.
Bounded Queue: ArrayBlockingQueue with a capacity of 1000 tasks.
Rejection Policy: CallerRunsPolicy to throttle the submission of new tasks when the queue is full, ensuring system stability.
Changes
Modified SessionPoolExample.java to use ThreadPoolExecutor instead of Executors.newFixedThreadPool.
Added necessary imports for ArrayBlockingQueue, ThreadPoolExecutor, and TimeUnit.
Cleaned up the thread pool initialization to follow best practices for resource management.
Test Result
Built successfully using mvn clean install -DskipTests -pl example/session -am.
Verified that the example runs correctly and executes queries without resource exhaustion.