Package org.apache.logging.log4j.util
Class Timer
java.lang.Object
org.apache.logging.log4j.util.Timer
- All Implemented Interfaces:
Serializable
,StringBuilderFormattable
Primarily used in unit tests, but can be used to track elapsed time for a request or portion of any other operation
so long as all the timer methods are called on the same thread in which it was started. Calling start on
multiple threads will cause the times to be aggregated.
- Since:
- 2.12.0
- See Also:
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
void
formatTo
(StringBuilder buffer) Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.long
Access the elapsed time.long
Access the elapsed time.getName()
Accessor for the name.Returns the name of the last operation performed on this timer (Start, Stop, Pause or Resume).int
hashCode()
void
pause()
Pause the timer.void
resume()
Resume the timer.void
start()
Start the timer.void
stop()
Stop the timer.toString()
Returns the String representation of the timer based upon its current state
-
Constructor Details
-
Timer
Constructor.- Parameters:
name
- the timer name.
-
Timer
Constructor.- Parameters:
name
- the timer name.
-
-
Method Details
-
start
public void start()Start the timer. -
startOrResume
public void startOrResume() -
stop
Stop the timer. -
pause
public void pause()Pause the timer. -
resume
public void resume()Resume the timer. -
getName
Accessor for the name.- Returns:
- the timer's name.
-
getElapsedTime
public long getElapsedTime()Access the elapsed time.- Returns:
- the elapsed time.
-
getElapsedNanoTime
public long getElapsedNanoTime()Access the elapsed time.- Returns:
- the elapsed time.
-
getStatus
Returns the name of the last operation performed on this timer (Start, Stop, Pause or Resume).- Returns:
- the string representing the last operation performed.
-
toString
Returns the String representation of the timer based upon its current state -
formatTo
Description copied from interface:StringBuilderFormattable
Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.- Specified by:
formatTo
in interfaceStringBuilderFormattable
- Parameters:
buffer
- the StringBuilder to write into
-
equals
-
hashCode
public int hashCode()
-