[concurrency-interest] Questions about ThreadPoolExecutor

Joe Bowbeer joe.bowbeer at gmail.com
Wed Mar 1 22:14:23 EST 2006


On 3/1/06, Kwok, Grace (MSCIBARRA) <Grace.Kwok at mscibarra.com> wrote:
>
> Do you mind explain this further?
> "This could be done by having all of the dedicated executors submit
> their work to one master executor."
>
>

We call this beast a composite executor.  There's an example in the
Executor javadoc:

http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Executor.html

The SerialExecutor example serializes the execution of a set of tasks
on another executor.

In your case, you'd write a BatchExecutor that submitted its tasks to
a master executor.  The master executor could be a cached ThreadPool
(Executors.newCachedThreadPool) with a maximumPoolSize to prevent
thread explosion.

Btw, another way to get a handle on thread creation across a set of
executors is to assign the same ThreadFactory to them all.  I wouldn't
make your factory too smart because then you'd be rewriting
ThreadPoolExecutor, but at least you'd be able to name the threads
logically and keep track of the total count, etc.


> -----Original Message-----
> From: Joe Bowbeer [mailto:joe.bowbeer at gmail.com]
> Sent: Wednesday, March 01, 2006 5:17 PM
> To: Kwok, Grace (MSCIBARRA)
> Cc: Brian Goetz; concurrency-interest at cs.oswego.edu
> Subject: Re: [concurrency-interest] Questions about ThreadPoolExecutor
>
> On 3/1/06, Kwok, Grace (MSCIBARRA) <Grace.Kwok at mscibarra.com> wrote:
> > "You can create a custom Executor for each batch of Callables.  You
> > will probably want to use some other bounding mechanism to ensure that
>
> > aggregate number of threads created by such executors doesn't exceed
> > some threshold."
> >
>
> This could be done by having all of the dedicated executors submit their
> work to one master executor.
>
>
> > If I am to create an Executor for each batch of Callables, the threads
>
> > from Executor 1 could not be reused by threads from Executor 2, is
> > that correct?  Is this optimal?  Is this like a pool of Executors?
> >
>
> ThreadPoolExecutor per batch seems right to me.  If you want to cleanup
> when a batch is done, you can call executorService.shutdown().
>
> You can also call executorService.setKeepAliveTime() so that the idle
> threads will self-terminate more or less automatically.
> --------------------------------------------------------
>



More information about the Concurrency-interest mailing list