[concurrency-interest] Best way to cause short delays

Holger Hoffstätte holger.hoffstaette at googlemail.com
Mon Jan 18 07:10:07 EST 2010

Peter Veentjer wrote:
> The main back off implementation I use is an exponential one that
> delays from a few microseconds to a few milliseconds by calling the
> Thread.sleep(ms, ns). The problem is that a delay of a few
> microseconds is not possible;
> I automatically get a delay of a few milliseconds, so the accuracy is
> very low. So what is the best way to let a thread delay for such small
> amounts of time?

Required reading:

Another blog on the the Thread.sleep(ms, ns) misbehaviour:

So LockSupport.parkNanos should work better than sleep() as long as CPU,
JVM and OS all play along. After having a good time with rt-Linux and
low-latency messaging last year I can assure you that this is rather
unlikely. :-)


More information about the Concurrency-interest mailing list