how do I set time limits for individual threads in a thread pool?
how do I set time limits for individual threads in a thread pool..? The parent thread need not wait until eve开发者_如何学Gory thread finishes and returns back. Instead it should fetch the next job(runnable/callable) and submit to the thread pool...
More context would be useful.
You might try using ExecutorCompletionService
:
http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ExecutorCompletionService.html
You can add a task to the same pool, or another one which will cancel the first task after a given amount of time. If it has completed this does nothing.
精彩评论