Are Thread.sleep(0) and Thread.yield() statements equivalent?

后端 未结 12 1745
太阳男子
太阳男子 2020-11-27 02:42

Are these two statement equivalent?

Thread.sleep(0);
Thread.yield();
12条回答
  •  情话喂你
    2020-11-27 03:24

    Thread.Sleep() has a slightly larger overhead because it creates a system that includes some kind of timer that will wake the process. (Depends on implementation basically)
    Bottom line it will call a Yield() in the end.

    Thread.Yield() Will just give-up the thread's turn, and gain it in the next round.

    Thread.Sleep(0) might have an optimization to just call yield. (Again, implementation)

提交回复
热议问题