org.apache.commons.id.uuid.clock
Class ThreadClockImpl

java.lang.Object
  extended by java.lang.Thread
      extended by org.apache.commons.id.uuid.clock.ThreadClockImpl
All Implemented Interfaces:
java.lang.Runnable, Clock

public final class ThreadClockImpl
extends java.lang.Thread
implements Clock

Clock provides a timing mechanism for returning the current time in 100-nano second intervals since 00:00:00.00, 15 October 1582.

This Class consumes a single thread which will die off if not utilized before the expiration. Subsequent calls after a thread expires start a new thread. Compensates for jvm time resolution issues. This clock should be used in instances where the system resolution does not perform adequately - the clocking resolution on some windows virtual machines can range from 10 to 50 milliseconds before the System.currentTimeMillis changes. In instances where 10,000 or more uuid's may be generated in a millisecond this Clock implementation may be required.

Version:
$Revision: 480488 $ $Date: 2006-11-29 08:57:26 +0000 (Wed, 29 Nov 2006) $
Author:
Commons-Id Team

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static long DEFAULT_THREAD_LIFE
          Default time to live of the Clock thread in milliseconds
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface org.apache.commons.id.uuid.clock.Clock
DEFAULT_CLOCK_IMPL, GREGORIAN_CHANGE_OFFSET, INTERVALS_PER_MILLI
 
Constructor Summary
ThreadClockImpl()
          Public constructor to instantiate a Clock instance.
 
Method Summary
static long getThreadLife()
          Returns the thread life in milliseconds.
 long getUUIDTime()
          Method returns the clocks current time in 100-nanosecond intervals since the Gregorian calander change.
 void run()
          Threads run method that increments the clock and resets the generated nano seconds counter.
static void setThreadLife(long threadLifeLen)
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_THREAD_LIFE

public static final long DEFAULT_THREAD_LIFE
Default time to live of the Clock thread in milliseconds

See Also:
Constant Field Values
Constructor Detail

ThreadClockImpl

public ThreadClockImpl()

Public constructor to instantiate a Clock instance.

Method Detail

getThreadLife

public static long getThreadLife()
Returns the thread life in milliseconds. If the clock thread is not accessed within this time span the thread will die off.

Returns:
thread life time span in milliseconds

setThreadLife

public static void setThreadLife(long threadLifeLen)
Parameters:
threadLifeLen - milliseconds this thread should live for. Each call to getCurrentTime resets the expiration time value.

run

public void run()
Threads run method that increments the clock and resets the generated nano seconds counter.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getUUIDTime

public long getUUIDTime()
                 throws OverClockedException
Method returns the clocks current time in 100-nanosecond intervals since the Gregorian calander change. Calendar.GREGORIAN_OFFSET

Specified by:
getUUIDTime in interface Clock
Returns:
Coordinated Universal Time (UTC) as a count of 100- nanosecond intervals since 00:00:00.00, 15 October 1582.
Throws:
OverClockedException - an exception when the number of timestamps generated exceeds the allowable timestamps for the system time interval.


Copyright © 2003-2008 The Apache Software Foundation. All Rights Reserved.