I am using Executors.newFixedThreadPool(5) to create Thread pool. and then use ExecutorService.submit(Callable<> to start a thread out of that. Now my question is - once one thread has completed its task, how can we kill that thread in this scenario.
Once the callable task is finished, the thread used for the task is returned to the threadpool to execute more tasks. These threads stay alive, waiting for more work, until you shutdown() the executor.
Henry [ April 25, 2008: Message edited by: Henry Wong ]
Originally posted by Pat Farrell: Normally, you just let the thread finish its work and ignore it. The Garbage collector will clean up after you.
Java threads are designed to be cheap.
While I normally agree here, keep in mind that the Original Poster is talking about executors. Executors need to be shutdown. If you simply dereference the executor, the GC won't be able to clean up after it.