Java threadpool redirection

I have basically CPU intensive work that runs in a thread pool. However, the operation has a certain number of external events awaiting the enemies that do not occur evenly in time. Since in Java, as far as I know, there is no thread pool implementation that automatically determines the number of threads based on the observed throughput of the task (as in Microsoft CLR 4), is there at least one way to manually tell the thread pool to increase its size when the blocking operation begins and decreases when it ends?

For example, with 8 cores, the pool size is 8. If the operation is associated with a 100% processor, just use this fixed pool. If there is some kind of blocking operation, you should do this:

pool.increase();
waitForSpecialKeyPress();
pool.decrease();

Here's how to do it in Microsoft's Async C ++ library: Use Unsubscribe Offset Delay

+5
source share
2 answers

Java 7 ForkJoinPool has a ManagedBlocker that can be used to inform the pool about blocked threads so that it can schedule more threads if necessary.

EDIT: I forgot to mention that classes are also available for Java 6 as jsr166y .

+3
source

You can expand ThreadPoolExecutorto add your own functions increase()and decrease()that make it simple setMaximumPoolSize(getMaximumPoolSize() +/- 1).

Be sure to synchronize the methods to make sure that you don't accidentally spoil the pool size.

+4

All Articles