Don't they perform the same task - expecting other threads to be able to execute?
It does not close because yield() does not expect anything.
Each thread can be in one of several different states: Running means that the thread is actually running on the processor, Runnable means that nothing prevents the thread from starting, except, perhaps, having a processor to run it on. All other states can be combined into a category called blocked. A blocked thread is a thread that is waiting for something that can happen before it can become operational.
The operating system launches threads regularly: every time (from 10 times per second to 100 times per second on most operating systems) the OS loses each thread and says: "Your turn is up, go to (i.e. change the state from start to runnable) Then it allows any thread at the head of the execution queue to use this CPU (ie, start it again).
When your program calls Thread.yield() , it tells the operating system: “I still have work, but it may not be as important as the work that some other thread does. Please send me to the back of the line launch right now. " If there is an available CPU for the thread to be executed, then it will continue to work efficiently (i.e., the call to yield () will return immediately).
When your program calls foobar.wait() , on the other hand, it tells the operating system: "Block me until some other thread calls foobar.notify() .
Disposal was first implemented on unmanaged operating systems and in uncaught thread libraries. On a computer with one processor, the only way that ever had to run more than one thread was that the threads were clearly inferior to each other.
Accounting is also useful for lively waiting. That the stream expects something to happen, sitting in a tight loop, testing the same condition again and again. If the condition depended on some other thread to do some work, the waiting thread will give () each time around the loop to let the other thread do its work.
Now that we have security and multiprocessing systems and libraries that provide us with higher-level synchronization objects, there are basically no reasons why applications need to call yield() .