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


Please Help Members By Posting Answers For Below Questions

What are the 6 mandatory procedures for iso 9001?

535


What is a Presistent Object?

654


Why charat is used in java?

565


What is final keyword in java?

560


Difference between == and .equals() ?

583






what is encapsulation in java? Explain

674


Can we write a class without main method in java?

490


How do you check if a string is lexicographically in java?

508


What is the purpose of abstract class?

537


How do you convert boolean to boolean?

536


Can a abstract class be defined without any abstract methods?

574


In how many ways we can do synchronization in java?

539


Which data type is class in java?

567


What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?

649


What is a variable and constant?

560