• 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

why you have to catch InterruptedException

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have a basic doubt in the Thread concept.?Pls help me to find the sol.Thank you..
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when you have a thread and you want to stop it you can call on this thread the method interrupt(), but this interrupt method will only set a variable of type boolean to true, every call to this.isInterrupted() will return the value of this variable. The only problem is: your thread goes to the not running state, any call to interrupt() will, specially in this case, restart the thread and then throw new InterruptedException(), conclusion: InterruptedException must be catch whenever you intend to make the thread sleep, or wait, if the thread is interrupted in the running state no exceptions are thrown, if it is sleeping, it's dreams will be interrupted and then a new InterruptedException will be created!!!
Please, correct me if I'm wrong. Hope this helps!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic