wood burning stoves
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 Building Microservices this week in the Design 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: 44048
    
  33
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
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Threads trying to get InterruptedException
 
It's not a secret anymore!