[concurrency-interest] Adding ForkJoinPool.setPoolSizeLimit

Doug Lea dl at cs.oswego.edu
Thu Jan 12 09:37:43 EST 2012

A series of early prereleases of ForkJoinPool included some
configuration methods/options similar to those of ThreadPoolExecutor.
But we found that setting them almost never did anything
sensible, so they were removed. The main reason is that
the pool must be able to create "continuation" threads to
avoid starvation when tasks become blocked on joins;
any dynamic configuration changes that interfere with this
can lead to either starvation or runaway growth, and there's
pretty much nothing users can do about it until it is too late.

However, there are some legitimate use cases for supporting
some advisory dynamic resource control. So I'm contemplating
adding the following. Opinions are welcome from those of you who
have come up against a situation where this kind of control,
or something else, would be necessary or helpful.

      * Sets the limit for the number of worker threads created when
      * new tasks or subtasks become available to execute. This value
      * may be either less than or greater than the parallelism level
      * (but at least 1 and at most an implementation-defined capacity
      * serving as the default value). Setting this value need not
      * immediately decrease or increase the pool size, but will
      * gradually take effect as new threads are needed or existing
      * threads complete tasks. Setting to a value too low to
      * accommodate the minimum required parallelism of a set of
      * dependent tasks may cause starvation -- all processing may
      * stall indefinitely. But assuming this constraint is met, using
      * setPoolSizeLimit may be preferable to constructing a
      * ForkJoinPool with non-default parallelism value.
      * @param limit the new target limit
      * @throws IllegalArgumentException if limit is less than one
      * or greater than this implementation's maximum capacity.
     public void setPoolSizeLimit(int limit) { ...

More information about the Concurrency-interest mailing list