| Author |
Question with interrupt ()
|
Sagar Shroff
Ranch Hand
Joined: Jun 07, 2011
Posts: 196
|
|
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: 196
|
|
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: 196
|
|
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
|
 |
 |
|
|
subject: Question with interrupt ()
|
|
|