• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Question with interrupt ()  RSS feed

 
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider i have 1 Thread and i started it.In the run method when i call interrupt () on that Thread nothing happens.In java Docs it is simply written that it interrupts the Thread.

Can Someone explain me what does interrupt () do and what is the us of it ??
 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sagar shroff wrote:Consider i have 1 Thread and i started it.In the run method when i call interrupt () on that Thread nothing happens.In java Docs it is simply written that it interrupts the Thread.

Can Someone explain me what does interrupt () do and what is the us of it ??








This was the code which i tried and the Output was
t1
t
 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you call interrupt on a thread, then that thead status set to true. this is one of the technique used to stop a thread. if that Thread sleep or wait then , it throws InterruptedException.
so, just print Thread.currentThread.isInterrupted() return value and check
 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Seetharaman Venkatasamy wrote:if you call interrupt on a thread, then that thead status set to true. this is one of the technique used to stop a thread. if that Thread sleep or wait then , it throws InterruptedException.
so, just print Thread.currentThread.isInterrupted() return value and check



Thank you Seetharam So Much !!! . I really Appreciate you
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sagar Shroff wrote:Thank you Seetharam So Much !!!


You are welcome
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!