what is the difference between sleep() and Wait()?
Answer Posted / amitasite
Thread.sleep() is static method which make current running
thread "not runnable" for specific time. Sleeping thread
doesn't release lock. It will transit to "ready to run"
state after specified time elapsed or other thread interrupts.
wait() can be call on shared object. Wait can be call only
if thread has lock. On calling thread it releases lock on
object and transit to "not runnable" state. It wake ups and
transit to "ready to run" state after other thread that got
lock call notify() or notifyAll() on shared object or call
interrupt().
| Is This Answer Correct ? | 11 Yes | 1 No |
Post New Answer View All Answers
What are the types of inner classes (non-static nested class) used in java?
Can a static class have a constructor?
What is the purpose of using break in each case of switch statement?
What is ordered map in java?
Why is the main method declared static?
What does the “static” keyword mean?
Which is the class in java?
What is array class in java?
How can you handle java exceptions?
Why is a constant variable important?
How are destructors defined in java?
What is the difference between a method and a function in alice?
How do you check if a number is a perfect square?
What are the files generated after using IDL to java compiler?
What is the benefit of using enum to declare a constant?