• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question with interrupt ()

 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • 0
  • 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
  • 0
  • 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
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 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
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Shroff wrote:Thank you Seetharam So Much !!!

You are welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic