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 is the significance of listiterator?

569


What is super keyword explain with example?

535


What is fail first in java?

571


Is integer immutable in java?

549


Can we cast any other type to boolean type with type casting?

539






What is meant by overloading?

590


How do I compare two strings in word in java?

541


What means public static?

562


Can we override data members in java?

632


List some oops concepts in java?

584


What is the multi-catch block in java?

537


What is used of static keyword in java?

592


Is constructor inherited?

532


What do you mean by hashing?

645


What a static class can contains?

700