Thank you for your suggestion Junilu. But I did not find any api suitable for this task.
To be more specific suppose I have below code which runs for a very long time in a thread but I want to kill that thread after 2 seconds no matter whether it is finished or not. How can I achieve that. Below is a small piece of code which does not work as my expectation(because invokeAll does not kill the thread after specified time).
Please guide me for a suitable solution.