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

Answer Posted / tisty

Simply speaking, we will use sleep() for pausing a thread
intentionally for some amount of time which we mentions in
milliseconds as the argument of sleep() method and,
wait() method is used whenever there is a communication is
needed between the threads, say if one thread's execution
is depended on the the execution of others.

The thread went on sleep will continue its execution after
the timeperiod. on the other hand, the thread undergone
wait will get activated on a notify() or notifyall() method.

Is This Answer Correct ?    6 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we sort set in java?

542


What is complexity and its types?

526


What is passing by reference in java?

543


Can variables be used in java without initialization?

554


How do I compare two strings in word in java?

541






What is nullpointerexception?

558


What are the differences between c++ and java?

584


Add a value x to array from index l to r where 0 <= l <= r <= n-1

633


What do you understand by the term polymorphism?

631


How do you change an int to a string?

547


What is tree in java?

491


What is the static keyword?

592


What are the two ways in which thread can be created?

598


How long will it take to learn java?

508


Define interface in java?

609