• Post Reply Bookmark Topic Watch Topic
  • New Topic

handling isInterrupted() when impl. Runnable I/F  RSS feed

 
Sri Bala
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I implement Runnable interface and check isInterrupted() in the run method, it won't compile because isInterrupted() is a member of Thread. Since it's a non static member, I can't also invoke like Thread.isInterrupted(). How do I handle that? I can use the static method interrupted(), but that's going to reset the interrupted flag and I don't want that.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're looking for Thread.currentThread().isInterrupted()?
- Peter
 
Sri Bala
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool! I learn't currentThread() today. Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!