[concurrency-interest] ThreadPoolExecutor with corePoolSize = 0

Sam Berlin sberlin at gmail.com
Wed Dec 20 19:17:42 EST 2006

Hi David,

We're designing this to be a general purpose construct for any part of
the application that needs to do sequential asynchronous processing.
This could be for HTTP GET requests to servers, writing / reading to /
from disk, DNS lookups, or any other potentially long-lived task.
Each part of the program (LimeWire, in this case) needs its own
executor to be sure another part isn't holding the executor-thread
hostage.  We did this previously with a custom 'ProcessingQueue' (see:
), but have decided to make better use of the built-in concurrent
features (for better compatibility, etc..).

What this means is that there could potentially be many of these
executor objects, which makes the resource issue more of a problem.
It's also compounded by the fact that the application will run on
consumer-level machines, so the less resources used, the better.

Your suggestion of using the Java 6 TPE code is likely what we'll end
up doing.  Is the public domain version different from the one in the
Java 6 source?  Where would I go to find that version?


On 12/20/06, David Holmes <dcholmes at optusnet.com.au> wrote:
> Sam,
> I agree that there is no simple way to do this in the Java 5 TPE. Only
> threads above "coreSize" have the idle-timeout that you are looking for, and
> they are only created after the queue is full and that doesn't fit your
> needs.
> What is the problem with having the one thread live forever? If there is no
> work for it then it consumes no CPU. If you are worried about application
> termination and don't have a good hook at which to shutdown the pool then
> define a ThreadFactory that provides a daemon thread. One thread should not
> cause any resource issues.
> Otherwise, you can always take the public domain version of the Java 6 TPE
> and use that instead.
> Cheers,
> David Holmes
> > -----Original Message-----
> > From: concurrency-interest-bounces at cs.oswego.edu
> > [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Sam
> > Berlin
> > Sent: Thursday, 21 December 2006 8:17 AM
> > To: concurrency-interest at cs.oswego.edu
> > Subject: [concurrency-interest] ThreadPoolExecutor with corePoolSize = 0
> >
> >
> > Hi Folks,
> >
> > We're interested in creating a ThreadPoolExecutor that lives with zero
> > live threads but will create a single thread and run any offered or
> > queued tasks when there are tasks to be run.  The rationale behind
> > this is to run occasional long-lived tasks that aren't time-critical
> > (and some requiring they be processed sequentially).  This is
> > different than the executor offered by Executors.singleThreadExecutor
> > because we don't want the thread it creates to live forever.
> >
> > It appears that this is impossible, because using a core pool size of
> > 0 causes no threads to ever be created.  (This is because of code in
> > execute(Runnable) that returns if poolSize < corePoolSize &&
> > addIfUnderCorePoolSize(runnable) both return true.
> > addIfUnderCorePoolSize doesn't add the thread because the core pool
> > size is 0, which the current size is not below.)
> >
> > We unfortunately cannot use Java 1.6's corePoolSize timeout (which I
> > suspect would allow things to work by setting the core size to 1 and
> > adding a timeout).
> >
> > Is there a way of doing this in Java 1.5?  Subclassing and adding
> > hooks will work fine, if it's possible to do it that way.
> >
> > Thanks,
> >  Sam
> > _______________________________________________
> > Concurrency-interest mailing list
> > Concurrency-interest at altair.cs.oswego.edu
> > http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list