• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread pool  RSS feed

 
Indradeep Saha
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would like to use a thread pool to do a job requiring several asynchronous tasks. I looked up some TP implementations available including the one in Java 1.5.0. When I assign a Runnable task to a thread in the TP what happens to this thread when the task is finished. Is this thread returned back to the TP or does it just hang on being in an idle state waiting for the main thread to clean it up? To be specific java 1.5s java.util.concurrent package talks about "automatic thread reclamation" for the method Executors.newCachedThreadPool(). Does this reclamation imply that the worker threads which have already been assigned a task and have finished it and are ready to accept new tasks, reclaimed to be assigned new tasks?

Thanks
Indradeep.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't seen the 1.5 thread pool but in one I have seen the threads block on a queue "get next command" method. If there is anything in the queue, the method returns the next command immediately and the thread executes it. If there is nothing in the queue the method blocks the thread. When some client puts in a new command, the queue notifies waiting threads and one of them gets the new command. Zat make sense?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the case of Executors.newCachedThreadPool(), the Executors API specifies that newCachedThreadPool() (no-argument version) creates a pool in which threads which are unused for sixty seconds (after they've completed their current task) will be terminated and removed from the cache. That's presumably what "automatic thread reclamation" refers to in the ThreadPoolExecutor API.
[ May 22, 2004: Message edited by: Jim Yingst ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!