This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I've a problem and am unable to solve it. I have a tool got from a .jar running on a thread. I am creating this thread in another method. I want to stop the execution of this thread after 'x' seconds.
Now here's my problem. I tried to do this using join(), and also by using wait and notify. This works well when the thread is put to sleep and while the thread is asleep, it gets interrupted. But when the actual tool is running and active, the thread is not getting interrupted and the tool goes all the way and completes executing.
Can anyone suggest what I've done wrong and what I can do to solve this problem?
I want to stop the execution of this thread after 'x' seconds.
Sun recommends NOT stopping a thread by using stop(). They do recommend changing the thread code to look for a flag setting and to stop itself by exiting if flag set. If you can't change the code for the "tool" ???
Joined: Jul 19, 2008
The tool is external and I am calling the tool within the run() method. Now I want this thread to be interrupted after a pre-defined length of time.
As I've mentioned earlier, this works fine when the thread is asleep, but when the actual tool is at work, the thread doesn't get interrupted.......
Do you mean you�re calling the interrupt() method on the new thread? The tool may not be doing anything that checks the interrupted status, or it could be detecting it and ignoring it. Can you tell us what you�re running?