public abstract class CloseableStopwatch extends Stopwatch implements AutoCloseable
Stopwatch
.
Once a CloseableStopwatch
is closed no more checkpoints can be
created and sinceStart()
and sinceLast()
return durations
based on the stopwatches stopping time.
Extending class are meant to be used inside try-with-resource blocks.
close()
can be called multiple times while all but the first call
are ignored.
Stopwatch.Checkpoint
Constructor and Description |
---|
CloseableStopwatch()
Abstract and synchronized implementation of a closeable
Stopwatch . |
Modifier and Type | Method and Description |
---|---|
Stopwatch.Checkpoint |
checkpoint(String name)
Adds a new checkpoint referenced by
name . |
void |
close() |
Optional<Instant> |
getStopInstant()
Instant at the stopwatches stopping or empty if the stopwatch is not stopped,
yet.
|
boolean |
isStopped()
Returns
true if the stopwatch is stopped. |
Duration |
sinceLast()
Duration since the last created
Stopwatch.Checkpoint or the stopwatches
starting time if no checkpoint was created |
Duration |
sinceStart()
Duration since the stopwatches start
|
String |
toString() |
getCheckpoints, getLastCheckpoint, getLastInstant, getStartInstant, stream, waitFor, waitFor
public CloseableStopwatch()
Stopwatch
.
Once a CloseableStopwatch
is closed no more checkpoints can be
created and sinceStart()
and sinceLast()
return durations
based on the stopwatches stopping time.
Extending class are meant to be used inside try-with-resource blocks.
close()
can be called multiple times while all but the first call
are ignored.
public Stopwatch.Checkpoint checkpoint(String name)
name
.
name
does not need to be unique. Multiple checkpoints with the same
name might exist.
checkpoint
in class Stopwatch
name
- name to reference the checkpointCompletedException
- Once the CloseableStopwatch
is closed no
more checkpoints can be added.public void close()
close
in interface AutoCloseable
public boolean isStopped()
true
if the stopwatch is stopped.true
if the stopwatch is stoppedpublic Duration sinceLast()
Stopwatch.Checkpoint
or the stopwatches
starting time if no checkpoint was createdpublic Duration sinceStart()
sinceStart
in class Stopwatch
public Optional<Instant> getStopInstant()
Copyright © 2025. All rights reserved.