• 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

interrupt()

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. suppose a thread is in waiting state, and another thread invokes
interrupt on this thread, InterruptedException is thrown and the thread
is move to runnable state. the same when notify is invoked.
my question is: when is the InterruptedException block specified in
the catch construct executed. is it
-- after the thread scheduler enables this thread for running
OR

-- immediately on invocation of notify or interrupt() methods.
because according to my understanding, for sleep () method, interrupt()
causes InterruptedException, and this exception block is executed
AFTER the thread scheduler enables the thread for running.
2.does it mean that the code of resumption of thread always is always
specified in the catch(InterruptedException e) block?
3.also, since the above exception is a checked exception, we will
ALWAYS have to declare methods like sleep() , wait() etc. in a
try-catch(InterruptedException e) block or else the compiler will
enforce an error, right?
please specify the steps taken after invocation of interrupt()

please help
chetan
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chetan,
Look at one of our old discussions on this topic. This should help you understand the concepts better.
As for the methods that throw the InterruptedException, they can either be enclosed in a try-catch block OR the enclosing method can be declared with the throws clause to satisfy the compiler.
Hope this helps,
Ajith
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic