• 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

Interrupted Exception

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I read that Threads can throw Interrupted Exception when the Thread that is executing is interrupted. But how to get this Exception? I mean can any one explain me with a small program which generates this Interrupted Exception??

Thanks in advance
 
Ranch Hand
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use sleep() or wait() method on a running thread. This will throw the InterruptedException.
Hope this helps.
 
Anudeep Duvvuri
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya that is ok but can you give me in a piece of code?
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should find something in the Java Tutorials section.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's my answer from your duplicate thread on this topic:


There are only certain method calls that can throw it, and you'll know when you call one of them, because InterruptedException is a checked exception, so the compiler will require you to declare or catch it.

The exception is thrown when some other thread calls Thread.interrupt() on your thread while it is blocked on one of those methods (such as wait()).


In the future, please UseOneThreadPerQuestion.(⇐click)
 
Anudeep Duvvuri
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for the answer.

Regarding duplicate question.
I have posted 1st in java in general as i does for the previous concepts but after posting i found a seperate forum for Threads so i posted again over there
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anudeep Duvvuri wrote:Regarding duplicate question.
I have posted 1st in java in general as i does for the previous concepts but after posting i found a seperate forum for Threads so i posted again over there


This can happen, there is a lot of forums here. Next time, please ask a moderator to move the thread (you can use the button for it).
reply
    Bookmark Topic Watch Topic
  • New Topic