*
The moose likes Threads and Synchronization and the fly likes Threads trying to get InterruptedException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threads trying to get InterruptedException" Watch "Threads trying to get InterruptedException" New topic
Author

Threads trying to get InterruptedException

shuba gopal
Ranch Hand

Joined: May 12, 2011
Posts: 76
Hi I am trying to get InterruptedException during thread execution. I expected that t.join() after t.start() will throw this exception. But the program runs without exception.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Please indent your code correctly; your inconsistent indentation makes it difficult to read. Have you seen the circumstance in which this exception can occur in the InterruptedException documentation? It doesn't say anything about join(). Have you read about interruption in the Java™ Tutorials?

I shall move this thread as too difficult for "beginning".
shuba gopal
Ranch Hand

Joined: May 12, 2011
Posts: 76
This is actually part of a question that I have reconstructed from my memory. I am not sure I can quote the exact source. According to the solution, for "Interrupted" to be printed, t.join() had to be used.
shuba gopal
Ranch Hand

Joined: May 12, 2011
Posts: 76
Campbell, sorry about the indentation.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I can't imagine why thread A trying to join thread B would cause thread A to be interrupted. And according to your test, it isn't. So the world is working as it should.
 
 
subject: Threads trying to get InterruptedException
 
Similar Threads
re-starting a dead thread
Thread once again (Join)
thread start in k&b
wait( ) method behind the scene ...
regarding start()