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 6 mandatory procedures for iso 9001?
What is a Presistent Object?
Why charat is used in java?
What is final keyword in java?
Difference between == and .equals() ?
what is encapsulation in java? Explain
Can we write a class without main method in java?
How do you check if a string is lexicographically in java?
What is the purpose of abstract class?
How do you convert boolean to boolean?
Can a abstract class be defined without any abstract methods?
In how many ways we can do synchronization in java?
Which data type is class in java?
What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
What is a variable and constant?