org.cometd.benchmark
Class SystemTimer

java.lang.Object
  extended by org.cometd.benchmark.SystemTimer

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.


Method Summary
static SystemTimer detect()
           
 long getEmulatedResolution()
           
 long getNativeResolution()
           
static void main(String[] args)
           
 void sleep(long micros)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getNativeResolution

public long getNativeResolution()

getEmulatedResolution

public long getEmulatedResolution()

sleep

public void sleep(long micros)

toString

public String toString()
Overrides:
toString in class Object

detect

public static SystemTimer detect()

main

public static void main(String[] args)


Copyright © 2008-2011 Dojo Foundation. All Rights Reserved.