commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Serge Knystautas <ser...@lokitech.com>
Subject Re: Question on Threadpool
Date Wed, 19 Nov 2003 15:29:46 GMT
David J. M. Karlsen wrote:
> Also I do not understand the DefaultThreadPool(int size) constructor:
> it calls startThread size times. startThread then does:
> 
> 
>   Thread thread = new Thread( this );
>         thread.start();
>         return thread;
> 
> so the DefaultThreadPool replaces it's Thread object size times - what's 
> the point in that?
> 
> what am I missing out on?

I think reading up on the Thread class and Runnable interface will help 
you understand what's going on here.  The phrase "replace it's Thread 
object" doesn't really make any sense.

The thread pool is creating a new Thread object that will call the 
DefaultThreadPool's run() method.  This run() method takes your worker 
tasks (that you handed the pool using invokeLater()), and runs that 
worker task.  This run() method loops until you call stop() on the 
ThreadPool.

If you want your stand-alone java app to stop, you'll need to call 
stop() on the pool.  Another alternate is to modify the 
DefaultThreadPool (or create another thread pool implementation) that 
creates these threads as daemon's, as the JVM will exit if only daemon 
threads are running.

-- 
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message