What is the difference between wait and sleep method?
- Wait method is called from synchronized context only while sleep can be called without synchronized block.
- Wait is called on object instance; while sleep is called on current thread.
- Waiting thread can be awaken by calling notify/notifyAll whereas sleeping thread can't.
- Wait is normally done on condition while sleep is just to put your thread on sleep.(Producer-Consumer)
- Wait release lock on object while waiting whereas sleep doesn't release lock while waiting.