How to suspend a java thread for a small period of time, like 100 nanoseconds?

前端 未结 6 1107
后悔当初
后悔当初 2020-12-09 02:09

I know Thread.sleep() can make a java thread suspend for a while, like certain milliseconds and certain nanoseconds. But the problem is the invocation of th

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 02:50

    One more problem with Thread.sleep() is that it is not guaranteed to wakeup after the specified time. A sleeping thread is guarenteed to sleep for the specified nano/micro seconds but not guarenteed to wakeup immediately after that. Since you are talking interms of nanoseconds, you might want to try Object.wait(long, int).

    I ve been quite consistent with the order of 10s of nanoseconds with the above method.

提交回复
热议问题