[concurrency-interest] How to dynamically adapt the pool size of a ForkJoinPool

Alexander.Berger at finnova.ch Alexander.Berger at finnova.ch
Mon Jun 4 09:13:29 EDT 2012

Hello everybody

I am experimenting with a special kind of ForkJoinPool which uses some heuristics to detect if
some of its worker threads are blocked (by other means than ManagedBlocker, e.g. sleeping, waiting, I/O, ...) and
which will automatically add new worker threads to compensate for blocked threads.

To add new worker threads I use tryCompensate(null,null) which works as expected, but I found no way
to later on decrease the number of worker threads (once there are no blocked workers anymore). I tried
using incrementActiveCount() but without any success. I just don't get rid of the extra threads.

So here comes my question:

How can I instruct a ForkJoinPool instance to release its extra worker threads (those that exceed parallelism)?

Please note, I have read the comments (in ForkJoinPool.java) about the problems such an approach
could cause (unwanted positive feedback control loops, etc.). Nevertheless I want to experiment
with such a solution as in our use case we want to share a ForkJoinPool instance with some legacy
and third party code, over which we have no control and which might submit blocking tasks to
the ExecutorService represented by that ForkJoinPool instance.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120604/0a98ff5b/attachment.html>

More information about the Concurrency-interest mailing list