[concurrency-interest] ThreadPoolExecutor

Joe Bowbeer joe.bowbeer at gmail.com
Wed Oct 5 17:22:31 EDT 2005


Patrick Eger <peger at automotive.com> wrote:
>
> This code is basically the first thing that is run with the  below settings.

Scratch those settings...

Though I think workQueue.offer is executed when corePoolSize == 0.

  if (poolSize < corePoolSize && addIfUnderCorePoolSize(command))
      return;
  if (workQueue.offer(command))
      return;
  int status = addIfUnderMaximumPoolSize(command);
  if (status > 0)      // created new thread
      return;
  if (status == 0) {   // failed to create thread
      reject(command);
      return;
  }

SO you want a decent core pool size, and maxPoolSize is mostly
irrelevant because the queue is effectively unbounded.

If you want the thread pool to shrink to 0 when idle, then you can use

allowCoreThreadTimeOut(true)

which was added in 1.6.


On 10/5/05, Patrick Eger <peger at automotive.com> wrote:
>
> Thank you for the quick response.
> Looking at the code  for ThreadPoolExecutor (from JDK 1.6):
>
> public void execute(Runnable command), line  ~876
> -------------------------------------------------
> Runnable r =  addIfUnderMaximumPoolSize(command);
> -------------------------------------------------
>
> This code is basically the first thing that is run with the below settings.
> So basically it will operate the same way it seems, IE adding a
> new thread unconditionally and not reusing existing idle threads.
> I will  write up a quick test to confirm this behaviour but i'm pretty
> sure we explored  this option as well.
>
> Thanks again for your help.
>
> Best regards,
>
> Patrick
>
>  ________________________________
 From: Joe Bowbeer [mailto:joe.bowbeer at gmail.com]
> Sent: Wednesday, October 05, 2005 1:38 PM
> To: Patrick  Eger
> Cc: concurrency-interest at altair.cs.oswego.edu
> Subject:  Re: [concurrency-interest] ThreadPoolExecutor
>
> I've probably missed something but it occurs to me that you want to
> be using maxPoolSize instead of corePoolSize.
>
> In other words, have you  tried the following?
>
> corePoolSize = 0
> maxPoolSize =  MAX
> keepAliveTime = tuned so that pool shrinks to 0 when executor is  idle
>
> On 10/5/05, Patrick  Eger <peger at automotive.com>  wrote:
> Basically, we need a ThreadPoolExecutor with the following properties:
> >
> > 1) {infinite | bounded} linked list request    queue, where the bound is
> > really high to avoid OOM (100000+)
> > 2) MIN of 0    threads in pool
> > 3) MAX # of threads in pool, configurable on pool create
> > 4) reuse existing threads if available
> > 5) allow pool to shrink to zero    threads if there are no outstanding
> > requests
> >
> >



More information about the Concurrency-interest mailing list