Package org.apache.logging.log4j.util
Class Timer
- java.lang.Object
-
- org.apache.logging.log4j.util.Timer
-
- All Implemented Interfaces:
Serializable
,StringBuilderFormattable
public class Timer extends Object implements 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.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Timer.Status
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
void
formatTo(StringBuilder buffer)
Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.long
getElapsedNanoTime()
Access the elapsed time.long
getElapsedTime()
Access the elapsed time.String
getName()
Accessor for the name.Timer.Status
getStatus()
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
startOrResume()
String
stop()
Stop the timer.String
toString()
Returns the String representation of the timer based upon its current state
-
-
-
Method Detail
-
start
public void start()
Start the timer.
-
startOrResume
public void startOrResume()
-
stop
public String stop()
Stop the timer.
-
pause
public void pause()
Pause the timer.
-
resume
public void resume()
Resume the timer.
-
getName
public String 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
public Timer.Status 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
public String toString()
Returns the String representation of the timer based upon its current state
-
formatTo
public void formatTo(StringBuilder buffer)
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
-
-