aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question with interrupt () Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question with interrupt ()" Watch "Question with interrupt ()" New topic
Author

Question with interrupt ()

Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

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 ??


OCJP-90%,OCPWCD-95%
Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

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
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jun 07, 2011
Posts: 208

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

Joined: Jan 28, 2008
Posts: 5575

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

You are welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question with interrupt ()