Class DefaultTimer

  extended by org.e2etrace.timer.DefaultTimer
All Implemented Interfaces:

public class DefaultTimer
extends Object
implements ITimer

Default ITimer implementation.

This implementation uses System.currentTimeMillis() to measure the duration between the start() and measure() calls on the timer. The advantage of this approach is that it works with all JDK releases. The disadvantage is that the accuracy of currentTimeMillis depends on the underlying operating systems. On Windows, for example, currentTimeMillis will typically provide an accuracy of about 10ms, which is too coarse for measuring short intervals. However, on Linux the accuracy is 1ms, which is exactly what we want. For details on this issue, please refer to the article "My kingdom for a good timer!" by Vladimir Roubtsov on JavaWorld (see link below).

Gunther Popp
See Also:
Article "My kingdom for a good timer!"

Method Summary
 long measure()
          Returns the duration in ms since start().
 void start()
          Starts the timer.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail


public void start()
Starts the timer.

Specified by:
start in interface ITimer


public long measure()
Returns the duration in ms since start().

Specified by:
measure in interface ITimer
duration in ms

Copyright © 2013 Gunther Popp. All Rights Reserved.