• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interruptinh thread

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.................
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.....
 
Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic