Skip to content

[IOTDB-17268] Optimize: replace unbounded thread pool with bounded ThreadPoolExecutor in SessionPoolExample#17287

Open
ShauryaChauhan1411 wants to merge 1 commit intoapache:masterfrom
ShauryaChauhan1411:fix-final-fresh-branch
Open

[IOTDB-17268] Optimize: replace unbounded thread pool with bounded ThreadPoolExecutor in SessionPoolExample#17287
ShauryaChauhan1411 wants to merge 1 commit intoapache:masterfrom
ShauryaChauhan1411:fix-final-fresh-branch

Conversation

@ShauryaChauhan1411
Copy link
Contributor

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.

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.

1 participant