What happens if sleep() and wait() executes in synchronized block?

Options
- The object still under lock in both the cases
- sleep() still under lock ,wait() the lock is removed
- sleep() the lock is removed ,wait() still under lock
- Sleep() and wait(),for both the method lock is removed


CORRECT ANSWER : sleep() still under lock ,wait() the lock is removed

Discussion Board
core java

no comment

Ajeet Raj 07-1-2017 12:32 PM

wait & sleep

@Narendra Babu : first thing is wait() is method of Object class, so its used mainly for Inter thread communication in multi-threaded environment. You can check this link for producer consumer problem which clearly lets you know how to use wait, notify & notifyAll.

Sleep : is thread class method and so it acts only on the current executing thread. say Thread.sleep(), will always make current active thread to sleep.

Ram 11-26-2014 01:01 PM

doubt.

how to use wait in synchronization block?

nitika 07-30-2014 10:25 AM

doubt regarding wait and sleep

can you please explain me how wait and sleep works in synchronized block??

Narendra Babu 06-25-2014 10:10 PM

Write your comments

 
   
 
 

Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement