What is the difference between join() method and yield() method in multithreading?

What is the difference between join() method and yield() method in multithreading?

Ninja Asked on 18th September 2018 in Java.
Add Comment
1 Answer(s)
Best answer

join() method will wait for the current thread to complete execution.

Let us assume that t1 and t2 are two executing threads. If t1 calls join() on t2 i.e.; t2.join() immediately t1 will enter into waiting state until t2 completes its execution.

yield() method gives a hint to the scheduler that the current thread is willing to yield its current use of a processor.

yield() method pauses the currently executing thread temporarily for giving a chance to the remaining waiting threads of the same priority to execute. If there is no waiting thread or all the waiting threads have a lower priority then the same thread will continue its execution. The chance for execution of the yielded thread is decided by the thread scheduler whose behavior is vendor dependent.

Ninja Answered on 18th September 2018.
Add Comment