@ThreadSafe public abstract class Stopwatch extends Object
| Modifier and Type | Class and Description |
|---|---|
protected static class |
Stopwatch.BaseDurations
Abstract base class for
Stopwatch.Durations implementations. |
static interface |
Stopwatch.Durations
The average and total durations as measured by one or more stopwatches.
|
private static class |
Stopwatch.MultipleDurations
A
Stopwatch.Durations implementation that accumulates all added durations. |
private static class |
Stopwatch.SingleDuration
A
Stopwatch.Durations implementation that only remembers the most recently added duration. |
static interface |
Stopwatch.Statistics
The timing statistics for a recorded set of samples.
|
static interface |
Stopwatch.StopwatchSet
A set of stopwatches whose durations are combined.
|
| Constructor and Description |
|---|
Stopwatch() |
| Modifier and Type | Method and Description |
|---|---|
static Stopwatch |
accumulating()
Create a new
Stopwatch that records all of the measured durations of the stopwatch. |
protected static String |
asString(Duration duration)
Compute the readable string representation of the supplied duration.
|
private static Stopwatch.Statistics |
createStatistics(LongSummaryStatistics stats) |
protected static Stopwatch |
createWith(Stopwatch.BaseDurations duration,
Runnable uponStart,
Runnable uponStop)
Create a new stopwatch that updates the given
duration, and optionally has functions to
be called after the stopwatch is started and stopped. |
abstract Stopwatch.Durations |
durations()
Get the total and average durations measured by this stopwatch.
|
static Stopwatch.StopwatchSet |
multiple()
Create a new set of stopwatches.
|
static Stopwatch |
reusable()
Create a new
Stopwatch that can be reused. |
abstract Stopwatch |
start()
Start the stopwatch.
|
abstract Stopwatch |
stop()
Stop the stopwatch.
|
public abstract Stopwatch start()
stop()public abstract Stopwatch stop()
start()public abstract Stopwatch.Durations durations()
private static Stopwatch.Statistics createStatistics(LongSummaryStatistics stats)
public static Stopwatch reusable()
Stopwatch that can be reused. The resulting durations(), however,
only reflect the most recently completed stopwatch interval.
For example, the following code shows this behavior:
Stopwatch sw = Stopwatch.reusable(); sw.start(); sleep(3000); // sleep 3 seconds sw.stop(); print(sw.durations()); // total and average duration are each 3 seconds sw.start(); sleep(2000); // sleep 2 seconds sw.stop(); print(sw.durations()); // total and average duration are each 2 seconds
public static Stopwatch accumulating()
Stopwatch that records all of the measured durations of the stopwatch.
For example, the following code shows this behavior:
Stopwatch sw = Stopwatch.accumulating(); sw.start(); sleep(3000); // sleep 3 seconds sw.stop(); print(sw.durations()); // total and average duration are each 3 seconds sw.start(); sleep(2000); // sleep 2 seconds sw.stop(); print(sw.durations()); // total duration is now 5 seconds, average is 2.5 seconds
public static Stopwatch.StopwatchSet multiple()
Stopwatch created by
Stopwatch.StopwatchSet.create() is also threadsafe.protected static Stopwatch createWith(Stopwatch.BaseDurations duration, Runnable uponStart, Runnable uponStop)
duration, and optionally has functions to
be called after the stopwatch is started and stopped.
The resulting stopwatch is threadsafe.
duration - the duration that should be updated; may not be nulluponStart - the function that should be called when the stopwatch is successfully started (after not running); may be
nulluponStop - the function that should be called when the stopwatch is successfully stopped (after it was running); may
be nullCopyright © 2021 JBoss by Red Hat. All rights reserved.