aspose file tools*
The moose likes Threads and Synchronization and the fly likes Interruptinh thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Interruptinh thread" Watch "Interruptinh thread" New topic
Author

Interruptinh thread

Raj Miandad
Greenhorn

Joined: Jul 19, 2008
Posts: 4
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

Joined: Aug 10, 2005
Posts: 690
    
    1
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

Joined: Jul 19, 2008
Posts: 4
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

Joined: May 27, 2008
Posts: 225

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?
 
 
subject: Interruptinh thread