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

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

    Sleep() causes the currently executing thread to sleep (temporarily cease execution).

    Yield() causes the currently executing thread object to temporarily pause and allow other threads to execute.

    enter image description here

    Read [this] (Link Removed) for a good explanation of the topic.

提交回复
热议问题