Top Description Constructors Methods
org.eclipse.jetty.util

public Class NanoTime

extends Object
Class Inheritance
Imports
java.util.concurrent.TimeUnit

Utility class with methods that deal with System#nanoTime().

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static long

Returns:

the nanoseconds elapsed
elapsed
(long
the begin nanoTime
beginNanoTime
,
long
the end nanoTime
endNanoTime
)

Calculates the nanoseconds elapsed between two nanoTimes.

public static boolean

Returns:

whether the first nanoTime is strictly before the second nanoTime
isBefore
(long
the first nanoTime
nanoTime1
,
long
the second nanoTime
nanoTime2
)

Returns whether the first nanoTime is strictly before the second nanoTime.

public static boolean

Returns:

whether the first nanoTime is before or the same as the second nanoTime
isBeforeOrSame
(long
the first nanoTime
nanoTime1
,
long
the second nanoTime
nanoTime2
)

Returns whether the first nanoTime is before or the same as the second nanoTime.

public static long

Returns:

the milliseconds elapsed
millisElapsed
(long
the begin nanoTime
beginNanoTime
,
long
the end nanoTime
endNanoTime
)

Calculates the milliseconds elapsed between two nanoTimes.

public static long

Returns:

the milliseconds elapsed between the given begin nanoTime and the current nanoTime
millisSince
(long
the begin nanoTime
beginNanoTime
)

Calculates the milliseconds elapsed between a begin nanoTime and the current nanoTime.

public static long

Returns:

the milliseconds remaining between the current nanoTime and the given end nanoTime
millisUntil
(long
the end nanoTime
endNanoTime
)

Calculates the milliseconds remaining between the current nanoTime and an end nanoTime.

public static long
now()

Returns: the current nanoTime via System#nanoTime()

public static long

Returns:

the seconds elapsed
secondsElapsed
(long
the begin nanoTime
beginNanoTime
,
long
the end nanoTime
endNanoTime
)

Calculates the seconds elapsed between two nanoTimes.

public static long

Returns:

the seconds elapsed between the given begin nanoTime and the current nanoTime
secondsSince
(long
the begin nanoTime
beginNanoTime
)

Calculates the seconds elapsed between a begin nanoTime and the current nanoTime.

public static long

Returns:

the seconds remaining between the current nanoTime and the given end nanoTime
secondsUntil
(long
the end nanoTime
endNanoTime
)

Calculates the seconds remaining between the current nanoTime and an end nanoTime.

public static long

Returns:

the nanoseconds elapsed since the given begin nanoTime and the current nanoTime
since
(long
the begin nanoTime
beginNanoTime
)

Calculates the nanoseconds elapsed since a begin nanoTime and the current nanoTime.

public static void
spinWait(long
the amount of nanoseconds to spin wait
nanos
)

Spin waits for the specified number of nanoseconds.

public static long

Returns:

the nanoseconds remaining from the current nanoTime until the given end nanoTime
until
(long
the end nanoTime
endNanoTime
)

Calculates the nanoseconds remaining from the current nanoTime until an end nanoTime.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NanoTimeback to summary
private NanoTime()

Method Detail

elapsedback to summary
public static long elapsed(long beginNanoTime, long endNanoTime)

Calculates the nanoseconds elapsed between two nanoTimes.

Parameters
beginNanoTime:long

the begin nanoTime

endNanoTime:long

the end nanoTime

Returns:long

the nanoseconds elapsed

isBeforeback to summary
public static boolean isBefore(long nanoTime1, long nanoTime2)

Returns whether the first nanoTime is strictly before the second nanoTime.

Reads as: "is nanoTime1 strictly before nanoTime2?".

Avoids the common mistake of comparing the 2 nanoTimes with the less-than < operator, which cannot be used when comparing nanoTimes, as specified in System#nanoTime().

Parameters
nanoTime1:long

the first nanoTime

nanoTime2:long

the second nanoTime

Returns:boolean

whether the first nanoTime is strictly before the second nanoTime

See Also
isBeforeOrSame(long, long)
isBeforeOrSameback to summary
public static boolean isBeforeOrSame(long nanoTime1, long nanoTime2)

Returns whether the first nanoTime is before or the same as the second nanoTime.

Parameters
nanoTime1:long

the first nanoTime

nanoTime2:long

the second nanoTime

Returns:boolean

whether the first nanoTime is before or the same as the second nanoTime

See Also
isBefore(long, long)
millisElapsedback to summary
public static long millisElapsed(long beginNanoTime, long endNanoTime)

Calculates the milliseconds elapsed between two nanoTimes.

Parameters
beginNanoTime:long

the begin nanoTime

endNanoTime:long

the end nanoTime

Returns:long

the milliseconds elapsed

millisSinceback to summary
public static long millisSince(long beginNanoTime)

Calculates the milliseconds elapsed between a begin nanoTime and the current nanoTime.

Parameters
beginNanoTime:long

the begin nanoTime

Returns:long

the milliseconds elapsed between the given begin nanoTime and the current nanoTime

millisUntilback to summary
public static long millisUntil(long endNanoTime)

Calculates the milliseconds remaining between the current nanoTime and an end nanoTime.

Parameters
endNanoTime:long

the end nanoTime

Returns:long

the milliseconds remaining between the current nanoTime and the given end nanoTime

nowback to summary
public static long now()
Returns:long

the current nanoTime via System#nanoTime()

secondsElapsedback to summary
public static long secondsElapsed(long beginNanoTime, long endNanoTime)

Calculates the seconds elapsed between two nanoTimes.

Parameters
beginNanoTime:long

the begin nanoTime

endNanoTime:long

the end nanoTime

Returns:long

the seconds elapsed

secondsSinceback to summary
public static long secondsSince(long beginNanoTime)

Calculates the seconds elapsed between a begin nanoTime and the current nanoTime.

Parameters
beginNanoTime:long

the begin nanoTime

Returns:long

the seconds elapsed between the given begin nanoTime and the current nanoTime

secondsUntilback to summary
public static long secondsUntil(long endNanoTime)

Calculates the seconds remaining between the current nanoTime and an end nanoTime.

Parameters
endNanoTime:long

the end nanoTime

Returns:long

the seconds remaining between the current nanoTime and the given end nanoTime

sinceback to summary
public static long since(long beginNanoTime)

Calculates the nanoseconds elapsed since a begin nanoTime and the current nanoTime.

Parameters
beginNanoTime:long

the begin nanoTime

Returns:long

the nanoseconds elapsed since the given begin nanoTime and the current nanoTime

spinWaitback to summary
public static void spinWait(long nanos)

Spin waits for the specified number of nanoseconds.

Parameters
nanos:long

the amount of nanoseconds to spin wait

untilback to summary
public static long until(long endNanoTime)

Calculates the nanoseconds remaining from the current nanoTime until an end nanoTime.

Parameters
endNanoTime:long

the end nanoTime

Returns:long

the nanoseconds remaining from the current nanoTime until the given end nanoTime