Difference between Sleep vs Wait.

sleepvswait

 

synchronized(LOCK) {
    Thread.sleep(100); // here LOCK is held
}

synchronized(LOCK) {
    LOCK.wait(); // here LOCK is not held
}
Thread.sleep(5000);   // Wait until the time has passed.

Object.wait();        // Wait until some other thread tells me to wake up.

Leave a Reply

Your email address will not be published. Required fields are marked *