what is the difference between sleep() and Wait()?

Answer Posted / suresh

Yes, sleep() and wait() methods are doing same work like prevent Thread Execution some amount of time in different ways.

where wait() is used only in Synchronization area this is called on object.wait(), it is overloaded method.if a thread object calls wait() then that thread will release the lock and wait for notification( notify(), notifyAll()) after getting notification thread will make Runnable.

where as sleep() is used any where it is static method. when sleep() called then thread will enter into sleep state particular amount of time if time expires thread will move into Runnable or Ready state.

In both cases Thread will Interrupted by interrupt().It will checked Exception we have take care of that with try n catch or throws.

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does .length start 0 java?

558


Explain about static imports in java?

593


What are 4 pillers of object orinted programming?

576


What does singleton class mean?

531


What is comparable and comparator interface? List their differences

575






What is lexicographically smallest string?

591


Give me some null interfaces in java?

598


Can we restart a thread already started in java?

577


Where can I find jdk in my computer?

459


What is a class reference?

550


What is the difference between variable & constant?

536


what is the difference between a threads start() and run() methods? : Java thread

516


what is server side caching?

1598


How arrays are stored in memory in java?

505


What is javac in java?

554