• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Hao Zhang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!