aspose file tools
The moose likes Threads and Synchronization and the fly likes In pool, how to judge that all tasks are done? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "In pool, how to judge that all tasks are done?" Watch "In pool, how to judge that all tasks are done?" New topic
Author

In pool, how to judge that all tasks are done?

Hao Zhang
Greenhorn

Joined: May 10, 2004
Posts: 4
Hello.
Because no jdk5.0 installed, I'm using EDU.oswego.cs.dl.util.concurrent.PooledExecutor for thread pooling. I know using Thread.join() can let main thread wait until that thread dies, but in PooledExecutor, how to do the same thing?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Can you get access to the underlying queue of commands? You could maybe check to see if it's empty.

Or if you will be coding all the commands to be executed, you could make them increment a static (global) counter when they start, decrement when they end. Any time the counter is zero then all tasks are done. Make sure the task has a try-catch with the decrement code in a finally clause so it's as reliable as possible.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
You can construct the PooledExecutor with a pre-built Channel instead of letting it create its own. This would give you access to check if it's empty. Look at the source for PE to see what kind of Channel it creates by default, or pick your own implementation.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: In pool, how to judge that all tasks are done?
 
Similar Threads
Maintain Session with Thread Safe
killing a Thread ?
protocol
reg threads
How do I "sleep" when using WorkManagers?