What is yielding and sleeping? how they different?




Answers were Sorted based on User's Feedback



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

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

explain the clone method and clonable interface

1 Answers  


What are the two major components of JDBC?

5 Answers   CMC, Mind Tree,


Explain Stream Tokenizer?

4 Answers  


what is aberivation of java?

14 Answers  


how can u create the object with out new operator

2 Answers  


write a code, we have two thread, one is printing even no and other print the odd no.

1 Answers   Global Logic,


could you run the java program without main method?

6 Answers  


We can write any Java Logics in our JSP. Then why we are using servlets(Controller Layer) to interact with the DAO ?

6 Answers   TCS,


how to make a un-checked exception as a checked exception one.

2 Answers  


using equals method overriding which objects are compared?i.e same class objects or other class objects?Explain me.

4 Answers  


in a console we r giving java <class name> if r pressing enter where it'll goes

2 Answers   CSC,


What is the difference between serialization and deserialization?

3 Answers   ABC,




Categories