Hi,
I need to submit a job in it's own
thread, but cancel the job (and kill the thread) if the job takes more than 5000ms to complete. I'm attempting to achieve this by using the facilities in java.util.concurrent like this:
However, it seems that the threads which are created to submit these jobs are not being killed. Initially, I thought this was happening because I only call future.cancel() when a TimeoutException is thrown and considered moving this call to the finally block instead. But according to the
API docs, this method will fail if the job has already completed.
My guess is that the cancel() method only cancels the execution of the job, and never kills the thread that is used to execute the job. If this is correct, then presumably I need to add some code to the finally block that kills the thread whether the job has completed successfully or not, BUT I need to be sure that this won't happen until the timeout of 5000 has expired.
Thanks in Advance,
Dan
[ January 14, 2008: Message edited by: Dan Murphy ]
[ January 14, 2008: Message edited by: Dan Murphy ]