What is difference between sleep() method and yield() method of multi threading?

前端 未结 12 1767
野的像风
野的像风 2020-12-22 17:02

As currently executing thread while it encounters the call sleep() then thread moves immediately into sleeping stat. Whereas for yield() thread moves into runnable

12条回答
  •  执笔经年
    2020-12-22 17:29

    yield(): yield method is used to pause the execution of currently running process so that other waiting thread with the same priority will get CPU to execute.Threads with lower priority will not be executed on yield. if there is no waiting thread then this thread will start its execution.

    join(): join method stops currently executing thread and wait for another to complete on which in calls the join method after that it will resume its own execution.

    For detailed explanation, see this link.

提交回复
热议问题