Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between wait and sleep

What is difference between wait and sleep?

like image 452
ziiweb Avatar asked Nov 08 '12 20:11

ziiweb


People also ask

What are the wait () and sleep () methods?

wait() – when synchronized multiple threads access same Object one by one. sleep() – when synchronized multiple threads wait for sleep over of sleeping thread.

What is the difference between sleep and delay?

Sleep relinquishes the CPU for specified amount , so that other process can execute. While Delay is just busy waiting for the amount to expire and then continue once expires, it do not execute any other process during this period.

What is the difference between sleep and wait Mcq?

wait() is a non-static method of Object class. sleep() is a static method of Thread class. Waiting threads can be woken up by other threads by calling notify() or notifyAll() methods. Sleeping threads can not be woken up by other threads.

What is the difference between wait sleep and yield in Java?

The major difference between yield and sleep in Java is that yield() method pauses the currently executing thread temporarily for giving a chance to the remaining waiting threads of the same priority to execute.


1 Answers

wait waits for a process to finish; sleep sleeps for a certain amount of seconds.

like image 69
MRAB Avatar answered Sep 20 '22 16:09

MRAB