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

前端 未结 12 1786
野的像风
野的像风 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:13

    Sleep causes thread to suspend itself for x milliseconds while yield suspends the thread and immediately moves it to the ready queue (the queue which the CPU uses to run threads).

提交回复
热议问题