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

前端 未结 6 1136
后悔当初
后悔当初 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:54

    Do a busy wait , ( ie have a while loop cycle through so many numbers doing nothing ). A the start of your program you can time the amount of time it took it execute this busy wait and increase or decrease it to get to 5 nano seconds

    I have found object.wait gets hairy with this frequency also make note that a busy wait solution would most likely be machine dependent Hence why you should have a calibration step at the start of your program

提交回复
热议问题