[concurrency-interest] Access to pool size

Claude Hussenet chussenet at yahoo.com
Sun Aug 21 12:43:57 EDT 2005


Thx Tim,it works for me.Rgds-Claude

--- Tim Peierls <tim at peierls.net> wrote:

> Claude Hussenet wrote:
> > Is there a way to have access to the pool size of
> an
> > ExecutorService created through the factory
> methods
> > of the Executors class?
> > 
> > It looks like that I would have to instantiate
> > directly
> > ThreadPoolExecutor if I want to monitor the pool
> size
> > of an ExecutorService.
> > 
> > Please confirm...
> 
> It's true: the Executors factory methods aren't
> specified to return a 
> ThreadPoolExecutor, even though they do in practice.
> 
> If all you want is to retrieve the count of active
> threads in the pool, 
> however, you don't have to use a TPE constructor:
> 
>    int getActiveThreadCount(ExecutorService exec) {
>        if (exec instanceof ThreadPoolExecutor) {
>            return ((ThreadPoolExecutor)
> exec).getActiveCount();
>        else // probably obtained with
> newSingleThreadExecutor
>            return 1;
>    }
> 
> That else-clause is a bit of a gamble; you might
> prefer to return some 
> distinguished value to indicate "unknown".
> 
> --tim
> 
> 


Claude Hussenet
Independent J2EE Architect Consultant
http://claudehussenet.com


		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 


More information about the Concurrency-interest mailing list