what's the difference between yield() and sleep()?

前端 未结 4 1283
情书的邮戳
情书的邮戳 2021-01-01 00:31

I know one difference:

If we say thread.sleep(1000), that thread will sleep for 1000 milliseconds for sure, whereas with yield()

4条回答
  •  無奈伤痛
    2021-01-01 00:54

    yield merely says: now is a good time to let another thread run and is a hint to the scheduler. sleep really does that: sleep at least the given time.

提交回复
热议问题