Access to pool size

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Access to pool size

Claude Hussenet
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...

Rgds-Claude







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 
 
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Access to pool size

tpeierls
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

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Access to pool size

Claude Hussenet
Thx Tim,it works for me.Rgds-Claude

--- Tim Peierls <[hidden email]> 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 
 
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest