Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


com.tangosol.util
Class SafeClock

java.lang.Object
  extended by com.tangosol.util.SafeClock


public class SafeClock
extends java.lang.Object

SafeClock maintains a "safe" time in milliseconds.

Unlike the System.currentTimeMillis() this clock guarantees that the time never "goes back". More specifically, when queried twice on the same thread, the second query will never return a value that is less then the value returned by the first.

If we detect the system clock moving backward, an attempt will be made to gradually compensate the safe clock (by slowing it down), so in the long run the safe time is the same as the system time.

The SafeClock supports the concept of "clock jitter", which is a small time interval that the system clock could fluctuate by without a corresponding passage of wall time.

Since:
Coherence 3.6
Author:
mf 2009.12.09

Field Summary
static long DEFAULT_JITTER_THRESHOLD
          The default jitter threshold.
protected  long m_ldtLastSafe
          The last known safe time value.
protected  long m_ldtLastUnsafe
          The last recorded unsafe time value.
protected  long m_lJitter
          The maximum expected jitter exposed by the underlying unsafe clock.

 

Constructor Summary
SafeClock(long ldtUnsafe)
          Create a new SafeClock with the default maximum expected jitter as specified by the "tangosol.coherence.safeclock.jitter" system property.
SafeClock(long ldtUnsafe, long lJitter)
          Create a new SafeClock with the specified jitter threshold.

 

Method Summary
 long getLastSafeTimeMillis()
          Returns the last "safe" time as computed by a previous call to the getSafeTimeMillis(long) method.
 long getSafeTimeMillis(long ldtUnsafe)
          Returns a "safe" current time in milliseconds.
protected  long updateSafeTimeMillis(long ldtUnsafe)
          Updates and returns a "safe" current time in milliseconds based on the "unsafe" time.

 

Field Detail

m_ldtLastSafe

protected long m_ldtLastSafe
The last known safe time value.

m_ldtLastUnsafe

protected long m_ldtLastUnsafe
The last recorded unsafe time value.

m_lJitter

protected final long m_lJitter
The maximum expected jitter exposed by the underlying unsafe clock.

DEFAULT_JITTER_THRESHOLD

public static final long DEFAULT_JITTER_THRESHOLD
The default jitter threshold.

Constructor Detail

SafeClock

public SafeClock(long ldtUnsafe)
Create a new SafeClock with the default maximum expected jitter as specified by the "tangosol.coherence.safeclock.jitter" system property.
Parameters:
ldtUnsafe - the current unsafe time

SafeClock

public SafeClock(long ldtUnsafe,
                 long lJitter)
Create a new SafeClock with the specified jitter threshold.
Parameters:
ldtUnsafe - the current unsafe time
lJitter - the maximum expected jitter in the underlying system clock

Method Detail

getSafeTimeMillis

public final long getSafeTimeMillis(long ldtUnsafe)
Returns a "safe" current time in milliseconds.
Parameters:
ldtUnsafe - the current unsafe time
Returns:
the difference, measured in milliseconds, between the corrected current time and midnight, January 1, 1970 UTC.

getLastSafeTimeMillis

public final long getLastSafeTimeMillis()
Returns the last "safe" time as computed by a previous call to the getSafeTimeMillis(long) method.

Note: Since the underlying field is non-volatile, the returned value is only guaranteed to be no less than the last value returned by getSafeTimeMillis() call on the same thread.

Returns:
the last "safe" time in milliseconds

updateSafeTimeMillis

protected long updateSafeTimeMillis(long ldtUnsafe)
Updates and returns a "safe" current time in milliseconds based on the "unsafe" time.
Parameters:
ldtUnsafe - the unsafe current time in milliseconds
Returns:
the corrected safe time

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.