I am listing here differences between wait() and sleep() methods in java. Please feel free to suggest if you can think of anything apart from those listed below.
|Wait method release the acquired monitor while the thread waits||Sleep method holds the monitor while the thread goes to sleep|
|Wait method should be called from inside a synchronized block||There is not such mandate for sleep method|
|wait() is an instance specific method and only resumes execution only if some other thread calls notify method on same object||Thread.sleep() method is a static method and applies on current thread|
|In case of wait, waiting thread first acquires the lock and then goes into Runnable state||In case of sleep, sleeping thread immediately goes to Runnable state after waking up|
|Use wait() method when you want to implement inter-thread communication.||Use sleep method if you want your thread to pause for a fixed/known amount of time|