0

Difference between wait and sleep in Java?

Difference between wait and sleep in Java?

21st May 2019, 7:12 PM
TheEngineerIN
TheEngineerIN - avatar
2 Answers
+ 2
As far as I know, wait is to wait for a certain task to be completed and the sleep is simply to stand in wait for a while. (Translation direct of words is right).
21st May 2019, 7:33 PM
JĂŽnatas Araripe
JĂŽnatas Araripe - avatar
0
wait call only returns when either it was notified or on spurious wakeups. On the other hand sleep call returns when the interval as finished or also on spurious wakeups. Don't forget that both can throw InterruptedException wheneaver the thread is interrupted.
22nd May 2019, 1:15 AM
Chriptus13
Chriptus13 - avatar