• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread pool

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic