Does a thread gives up monitor lock when Thread.sleep() is called?

Recommended Answers

All 2 Replies

From the Javadocs:

Causes the currently executing thread to sleep (cease execution) for the specified number of milliseconds plus the specified number of nanoseconds. The thread does not lose ownership of any monitors.

No. However, Thread.wait() does, until it is notified, at which point it regains the monitor if it is the chosen thread that is woken up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.