Meaningless Drivel is fun!
The moose likes Threads and Synchronization and the fly likes 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 "sleep()" Watch "sleep()" New topic


Matthew B

Joined: Jul 14, 2002
Posts: 1
Will calling sleep on a thread release the threads lock an an obect/class?
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
No. See the sample code below:
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

This comes directly from the SDK. Try to read the docs, they contain the information you seek.
public static void sleep(long millis)
throws InterruptedExceptionCauses the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. The thread does not lose ownership of any monitors.
millis - the length of time to sleep in milliseconds.
InterruptedException - if another thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
See Also:
I agree. Here's the link:
subject: sleep()
It's not a secret anymore!