What is yielding and sleeping? how they different?

Answers were Sorted based on User's Feedback



What is yielding and sleeping? how they different?..

Answer / ranganathkini

When a thread yields, its execution is paused and loses
ownership of the monitor lock giving other waiting threads a
chance to run.

When a thread sleeps, its execution is paused for the
specified duration during such an idle period, the thread
continues to retain the ownership of the monitor lock.

Is This Answer Correct ?    3 Yes 1 No

What is yielding and sleeping? how they different?..

Answer / ravikiran

yield() method will suspend all the same priority thread
which is running and gives chance to next thread to run
which is of the same priority
sleep() method will make the thread to sleep for a
particular period of time which is specified in the
argument list

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More Core Java Interview Questions

what is mean by thread lock?

2 Answers   Infosys, TCS,


What is a list in java?

0 Answers  


what is associative array

1 Answers   Tech Mentro,


Can we override the static methods?

0 Answers  


describe synchronization in respect to multithreading? : Java thread

0 Answers  






What is difference between c++ and java ?

0 Answers  


Does a class inherit the constructor of its super class?if it does, how can you hide that constructor? if it doesnot how can you call it from the sub class?

2 Answers  


What is meant by wrapper classes?

3 Answers  


What is a private class in java?

0 Answers  


How many functional interfaces does java 8 have?

0 Answers  


which method throws exception of type Throwable

2 Answers  


In the below example, how many string objects are created?

0 Answers  


Categories