Thread.sleep vs. TimeUnit.SECONDS.sleep

前端 未结 2 1914
忘了有多久
忘了有多久 2020-12-12 15:51

If I\'m going to have a call to have a Java Thread go to sleep, is there a reason to prefer one of these forms over the other?

Thread.sleep(x)
2条回答
  •  一整个雨季
    2020-12-12 16:32

    They are the same. I prefer the latter because it is more descriptive and allows to choose time unit (see TimeUnit): DAYS, HOURS, MICROSECONDS, MILLISECONDS, MINUTES, NANOSECONDS, SECONDS.

提交回复
热议问题