What is the difference between yielding and sleeping?



What is the difference between yielding and sleeping?..

Answer / Raj Bhushan Rai

Yielding in Java is a method used by a running thread to voluntarily give up its CPU time, allowing another thread of the same or lower priority to execute. Sleeping, on the other hand, causes the current thread to pause execution for a specific amount of time before it continues running. The key difference between yielding and sleeping is that yielding allows for cooperative multitasking while sleeping does not.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is the purpose of a statement block?

1 Answers  


How to change the priority of thread or how to set priority of thread?

1 Answers  


what is the output ? Math.floor(-2.1) a)2 b)-2 c)-3.0 d)0

4 Answers   Accenture,


When to use runnable interface vs thread class in java?

1 Answers  


What is the advantage of preparedstatement over statement?

1 Answers  


How can we create objects if we make the constructor private ?

1 Answers  


What is fail fast in java?

1 Answers  


What is array list in java?

1 Answers  


Why should we create an object? what is a need of it? Apart from access members of a class i want what is a need of object what does it contain?? In normal class to access any member of thaht class we create object where as for static class we access its members using class name. what is a difference between them... thanks in advance.

1 Answers  


How do you check if a string is lexicographically in java?

1 Answers  


What one should take care of, while serializing the object?

1 Answers  


Can we have static methods in an interface?

1 Answers  


Categories