Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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

What does the Thread method interrupt() mean?  RSS feed

 
sam huang
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks in advence.
Sam
 
Jasper Vader
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if a thread might need to be killed from another thread, don't use the stop() method, instead, call interrupt() on it.
\
if a thread is sleeping and it receives an interrupt() call, it moves immediately into the Ready state, and when it runs, it will execute its InterruptedException handler.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam,
Thread.interrupted()
Thread.isInterrupted()
can be used for testing if a thread was err.. interrupt()
Please check the API for the difference between them.
If a thread is joining, sleeping or waiting and it is interrupted, it would abandon the state and its "InterruptedException" handler would be executed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!