aspose file tools*
The moose likes Threads and Synchronization and the fly likes Difference between interrupt() and sleep() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Difference between interrupt() and sleep()" Watch "Difference between interrupt() and sleep()" New topic
Author

Difference between interrupt() and sleep()

veena bijur
Ranch Hand

Joined: May 16, 2011
Posts: 67
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
veena bijur
Ranch Hand

Joined: May 16, 2011
Posts: 67
Thanks.

Now i got it.

Thanks a lot.
 
jQuery in Action, 2nd edition
 
subject: Difference between interrupt() and sleep()