JavaIntermediate#concurrency

What is the difference between Thread.sleep() and Object.wait()?

Thread.sleep() pauses the current thread for a set time without releasing any locks it holds. Object.wait() releases the object's monitor lock and pauses until notified, and must be called within a synchronized block.

Example
Thread.sleep(1000); // holds any locks it has
// vs
synchronized(lock) { lock.wait(1000); } // releases lock while waiting

Related Questions

1
JavaAdvanced#concurrency

What is the difference between ReentrantLock and synchronized?

Open
2
JavaAdvanced#concurrency#java8

What is a CompletableFuture and how does it improve async programming?

Open
3
JavaIntermediate#concurrency

What are the different thread pool types provided by Executors?

Open