Class CallerTrace
- java.lang.Object
-
- de.aristaflow.adept2.util.objectpool.generic.CallerTrace
-
public class CallerTrace extends Object
Records information about the caller of a method: the current thread, its stack trace at the moment this trace was created (unless a custom stack trace is explicitly specified in the constructor) and a timestamp. This class is used to log who checked out a certain object from an object pool.- Author:
- Patrick Schmidt
-
-
Constructor Summary
Constructors Modifier Constructor Description CallerTrace()
Constructs a newCallerTrace
for the current thread and its current stack trace.CallerTrace(int trimStackTrace)
Constructs a newCallerTrace
for the current thread and its current stack trace.protected
CallerTrace(StackTraceElement[] threadStack, Thread thread, int trimStackTrace)
Creates a newCallerTrace
for the designated stack trace, thread and trims the stack appropriately.CallerTrace(Thread thread)
Constructs a newCallerTrace
for the given thread and its current stack trace.CallerTrace(Thread thread, int trimStackTrace)
Constructs a newCallerTrace
for the given thread and its current stack trace.CallerTrace(Thread thread, StackTraceElement[] stackTrace)
Constructs a newCallerTrace
for the given thread and the given stack trace.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StackTraceElement[]
getStackTrace()
Returns the thread's stack trace at the time of calling.Thread
getThread()
Returns the calling thread.String
getThreadName()
Returns the name of the calling thread.long
getTimestamp()
Returns a timestamp of when this trace was created.
-
-
-
Constructor Detail
-
CallerTrace
public CallerTrace()
Constructs a newCallerTrace
for the current thread and its current stack trace.
-
CallerTrace
public CallerTrace(Thread thread)
Constructs a newCallerTrace
for the given thread and its current stack trace.
For performance reasons do not call this method usingThread.currentThread()
. Use the constructors withoutThread
-parameter instead.- Parameters:
thread
- the thread for which to create the trace
-
CallerTrace
public CallerTrace(int trimStackTrace)
Constructs a newCallerTrace
for the current thread and its current stack trace. The toptrimStackTrace
stack trace elements are cut off.- Parameters:
trimStackTrace
- the number of stack trace elements (from the top) that should be cut off
-
CallerTrace
public CallerTrace(Thread thread, int trimStackTrace)
Constructs a newCallerTrace
for the given thread and its current stack trace. The toptrimStackTrace
stack trace elements are cut off.
If the stack trace cannot be retrieved from the thread due to security issues, an empty stack trace will be used.
For performance reasons do not call this method usingThread.currentThread()
. Use the constructors withoutThread
-parameter instead.- Parameters:
thread
- the thread for which to create the tracetrimStackTrace
- the number of stack trace elements (from the top) that should be cut off
-
CallerTrace
public CallerTrace(Thread thread, StackTraceElement[] stackTrace)
Constructs a newCallerTrace
for the given thread and the given stack trace.- Parameters:
thread
- the thread for which to create the tracestackTrace
- the stack trace to be logged
-
CallerTrace
protected CallerTrace(StackTraceElement[] threadStack, Thread thread, int trimStackTrace)
Creates a newCallerTrace
for the designated stack trace, thread and trims the stack appropriately.- Parameters:
threadStack
- The stack trace to be logged.thread
- The thread for which to create the trace.trimStackTrace
- The number of stack trace elements (from the top) that should be cut off.
-
-
Method Detail
-
getThread
public Thread getThread()
Returns the calling thread. The thread is only linked with aweak reference
, i.e. this trace does not prevent the thread from being garbage collected.- Returns:
- the calling thread or
null
if the thread was already garbage collected
-
getThreadName
public String getThreadName()
Returns the name of the calling thread.- Returns:
- the name of the calling thread
-
getStackTrace
public StackTraceElement[] getStackTrace()
Returns the thread's stack trace at the time of calling. If security prevents the stack from being retrieved from the thread, an empty stack trace will be returned.- Returns:
- the thread's stack trace at the time of calling
-
getTimestamp
public long getTimestamp()
Returns a timestamp of when this trace was created.- Returns:
- a timestamp of when this trace was created
-
-