File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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: 40027
    
  28
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: 18985
    
    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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads trying to get InterruptedException