Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between interrupt() and sleep()

 
veena bijur
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could any one please tell me,

1. Difference between interrupt() and sleep() in threads

2. In which situation those are used being used?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
veena bijur wrote:1. Difference between interrupt() and sleep() in threads
Tell me: what is the difference between slapping someone in the face, and taking a nap? That is the difference between interrupt() and sleep(). They are completely different, not used for the same purpose, and have no relation except that one (taking a nap) can be affected if someone else does the other to you (slap in the face).

2. In which situation those are used being used?
You use interrupt() when you want to interrupt() another Thread which may be waiting on something. You use sleep() when you want this thread to pause for a bit.
 
veena bijur
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

Now i got it.

Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic