public abstract class Clock
extends java.time.Clock
As of Oak 1.20, this extends from Clock
.
Modifier and Type | Class and Description |
---|---|
static class |
Clock.Fast
Fast clock implementation whose
Clock.Fast.getTime() method returns
instantaneously thanks to a background task that takes care of the
actual time-keeping work. |
static class |
Clock.Virtual
A virtual clock that has no connection to the actual system time.
|
Modifier and Type | Field and Description |
---|---|
static Clock |
ACCURATE
Accurate clock implementation that uses interval timings from the
System.nanoTime() method to calculate an as accurate as possible
time based on occasional calls to System.currentTimeMillis()
to prevent clock drift. |
static Clock |
SIMPLE
Simple clock implementation based on
System.currentTimeMillis() ,
which is known to be rather slow on some platforms. |
Constructor and Description |
---|
Clock() |
Modifier and Type | Method and Description |
---|---|
java.util.Date |
getDate()
Convenience method that returns the
getTime() value
as a Date instance. |
java.util.Date |
getDateIncreasing()
Convenience method that returns the
getTimeIncreasing() value
as a Date instance. |
java.util.Date |
getDateMonotonic()
Convenience method that returns the
getTimeMonotonic() value
as a Date instance. |
abstract long |
getTime()
Returns the current time in milliseconds since the epoch.
|
long |
getTimeIncreasing()
Returns a strictly increasing timestamp based on the current time.
|
long |
getTimeMonotonic()
Returns a monotonically increasing timestamp based on the current time.
|
java.time.ZoneId |
getZone() |
java.time.Instant |
instant() |
void |
waitUntil(long timestamp)
Waits until the given point in time is reached.
|
java.time.Clock |
withZone(java.time.ZoneId zone) |
public static Clock SIMPLE
System.currentTimeMillis()
,
which is known to be rather slow on some platforms.public static Clock ACCURATE
System.nanoTime()
method to calculate an as accurate as possible
time based on occasional calls to System.currentTimeMillis()
to prevent clock drift.public abstract long getTime()
System.currentTimeMillis()
,
Clock.millis()
public long getTimeMonotonic()
public long getTimeIncreasing() throws java.lang.InterruptedException
getTimeMonotonic()
, with the exception
that two calls of this method will never return the same timestamp.
Instead this method will explicitly wait until the current time
increases beyond any previously returned value. Note that the wait
may last long if this method is called frequently from many concurrent
thread or if the system time is adjusted backwards. The caller should
be prepared to deal with an explicit interrupt in such cases.java.lang.InterruptedException
- if the wait was interruptedpublic java.util.Date getDate()
getTime()
value
as a Date
instance.public java.util.Date getDateMonotonic()
getTimeMonotonic()
value
as a Date
instance.public java.util.Date getDateIncreasing() throws java.lang.InterruptedException
getTimeIncreasing()
value
as a Date
instance.java.lang.InterruptedException
public void waitUntil(long timestamp) throws java.lang.InterruptedException
getTimeIncreasing()
method returns
a time that's equal or greater than the given point in time.timestamp
- time in milliseconds since epochjava.lang.InterruptedException
- if the wait was interruptedpublic java.time.ZoneId getZone()
getZone
in class java.time.Clock
public java.time.Instant instant()
instant
in class java.time.Clock
public java.time.Clock withZone(java.time.ZoneId zone)
withZone
in class java.time.Clock
Copyright © 2010 - 2020 Adobe. All Rights Reserved