If the thread is in a thread pool, you even more must not stop() it, because it might not even be running the task you think it is running.
To stop an in-progress task, you have to code some sort of interruption protocol into the task. It could check a stop-flag every now and then, or maybe use Thread.interrupt() and Thread.interrupted() (though some people have told me off for that). If you use a stop-flag, make sure it is either accessed within a synchronized block or it is declared volatile.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
You can tell if one of your tasks didn't finish in time, even though you can't stop it. Your Future has a get() method with a timeout parameter. Start up a bunch of these things, then go back through the list and try to get the results.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: May 15, 2005
I wanted to assign some time for all threads to complete its operation. So there is a method at executor -- await...(1000). After the executor awaits, I iterate over all the tasks & call the get method like get(1000, TimeUnit.Millisecond). If it fails, it throws the exception. But still the task does'nt stop. I guess thats because, the thread calls an http request, the thread won't get stopped till the request returns. I probably have to set some kind of time out in the thread itself....
After the executor awaits, I iterate over all the tasks & call the get method like get(1000, TimeUnit.Millisecond). If it fails, it throws the exception. But still the task does'nt stop.
get method time out just indicates that the task is not completed after the wait period. It does not terminate the task.
I guess thats because, the thread calls an http request, the thread won't get stopped till the request returns.
Which library are you using to make HTTP requests? You can set the socket timeout to some value if you are sure thats where the thread is hung for a long time. This will throw a SocketTimeOutException from the future and when you call get() method on the future, it willl throw the ExecutionException with the SocketTimeOutException as the cause. [ July 12, 2007: Message edited by: Nitesh Kant ]