[concurrency-interest] Sharing threads across executors

Dibyendu Majumdar concurrency-interest at majumdar.org.uk
Sat Mar 13 20:09:01 EST 2010


Hi,

I am building a system where there are many modules that need to run
background tasks. The requirement is that the tasks execute without blocking
as otherwise performance will be impacted. On the other hand I want to avoid
having too many threads sitting idle.

I may have misunderstood, but it seems to me that there is no mechanism for
sharing a single threadpool across multiple executors. Conceptually, I'd
like each executor to have its task queue, but share the thread pool with
other executors, so that the pool of threads is optimised.

I also need the ability to run certain tasks at scheduled intervals.

For now, the solution I have implemented is as follows:

I use a single ThreadPoolExecutor to run all tasks.
I use a separate ScheduledThreadPoolExecutor to manage scheduled tasks. This
executor does not run the tasks, instead it submits the tasks when ready to
the first ThreadPoolExecutor. This pool has only 1 thread allocated.

With this solution I am close to what I wanted, but I cannot avoid having
one thread (ScheduledThreadPoolExecutor) being idle most of the time.

Is there a better way of achieving this?
Why is the scheduling function tied to the threadpool management? It would
seem to me that these are separate concerns.

Thanks very much in advance for your help and advice.

Regards

Dibyendu Majumdar
http://www.simpledbm.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20100314/1f7abf5b/attachment.html>


More information about the Concurrency-interest mailing list