Saturday, 15 May 2010

multithreading - How to cancel a particular task by timeout when using ThreadPoolExecutor in Java? -


I am using Threadpool Extractor in Java to parallel item processing. Each processing processing is a different task, which I keep in line for the executor in the process. Unfortunately, some tasks can take a very long time, and I want to cancel these types of tasks and continue with the rest. I do not want to wait for the shutdown method and its time-duration (it takes complete processing days). I want something like looping on the currently executed tasks and how long it's going on and cancel it if it is more than the limit.

ThreadPoolExecutor will return future items to you, when you submit the work for it.

Use the method on your futures, and if you get timeout, call the call on them.


No comments:

Post a Comment