com.croftsoft.core.util.loop
Class NanoTimeLoopGovernor

java.lang.Object
  extended by com.croftsoft.core.util.loop.NanoTimeLoopGovernor
All Implemented Interfaces:
LoopGovernor

public final class NanoTimeLoopGovernor
extends Object
implements LoopGovernor

Uses System nanoTime() to measure time between calls.

Since:
2005-08-04
Version:
$Date: 2008/02/15 21:18:30 $
Author:
David Wallace Croft

Constructor Summary
NanoTimeLoopGovernor()
          Initializes with a periodNanos of zero (maximum frequency).
NanoTimeLoopGovernor(double frequency)
          Constructs a LoopGovernor with the specified target frequency.
 
Method Summary
 void govern()
          This method puts the Thread to sleep for a limited time.
static void main(String[] args)
          Test method.
 void setFrequency(double frequency)
          If the frequency is set to Double.POSITIVE_INFINITY, periodNanos will be set to zero.
 void setPeriodNanos(long periodNanos)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NanoTimeLoopGovernor

public NanoTimeLoopGovernor(double frequency)
Constructs a LoopGovernor with the specified target frequency.

Parameters:
frequency - The targeted loop frequency in loops per second.

NanoTimeLoopGovernor

public NanoTimeLoopGovernor()
Initializes with a periodNanos of zero (maximum frequency).

Method Detail

main

public static void main(String[] args)
                 throws Exception
Test method.

Throws:
Exception

setFrequency

public void setFrequency(double frequency)
If the frequency is set to Double.POSITIVE_INFINITY, periodNanos will be set to zero.


setPeriodNanos

public void setPeriodNanos(long periodNanos)

govern

public void govern()
            throws InterruptedException
Description copied from interface: LoopGovernor
This method puts the Thread to sleep for a limited time.

Specified by:
govern in interface LoopGovernor
Throws:
InterruptedException

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)