public class SystemTimer extends Object
Detects and reports the timer resolution of the current running platform.
Unfortunately, Thread.sleep(long) on many platforms has a resolution of 1 ms
or even of 10 ms, so calling Thread.sleep(2) often results in a 10 ms sleep.
The same applies for Thread.sleep(long, int) and Object.wait(long, int):
they are not accurate, especially on virtualized platforms (like Amazon EC2, where the
resolution can be as high as 64 ms).
System.nanoTime() is precise enough, but we would need to loop continuously
checking the nano time until the sleep period is elapsed; to avoid busy looping pegging
the CPUs, Thread.yield() is called to attempt to reduce the CPU load.
| Modifier and Type | Method and Description |
|---|---|
static SystemTimer |
detect() |
long |
getEmulatedResolution() |
long |
getNativeResolution() |
static void |
main(String[] args) |
void |
sleep(long micros) |
String |
toString() |
public long getNativeResolution()
public long getEmulatedResolution()
public void sleep(long micros)
public static SystemTimer detect()
public static void main(String[] args)
Copyright © 2008-2013 Dojo Foundation. All Rights Reserved.