You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "David J. M. Karlsen" <da...@davidkarlsen.com> on 2003/11/19 03:09:38 UTC
Question on Threadpool
Hi!
I use DefaultThreadpool to dispatch work to in a standalone java-app.
The problem is that the application never terminates, even after all my
worker threads I added to Threadpool terminate (exit their run() methods).
Why doesn't threadpool stop to run() when it's queue is empty?
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?
--
David J. M. Karlsen - +47 90 68 22 43
http://www.davidkarlsen.com
http://mp3.davidkarlsen.com
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: Question on Threadpool
Posted by Serge Knystautas <se...@lokitech.com>.
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