• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interruptinh thread

 
Raj Miandad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?

Hope for a reply soon.................
 
Norm Radder
Ranch Hand
Posts: 728
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" ???
 
Raj Miandad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.......

Hope its clearer now.....
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic