Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads trying to get InterruptedException  RSS feed

 
shuba gopal
Ranch Hand
Posts: 86
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55292
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell, sorry about the indentation.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!