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 Details

    • CallerTrace

      public CallerTrace()
      Constructs a new CallerTrace for the current thread and its current stack trace.
    • CallerTrace

      public CallerTrace(Thread thread)
      Constructs a new CallerTrace for the given thread and its current stack trace.
      For performance reasons do not call this method using Thread.currentThread(). Use the constructors without Thread-parameter instead.
      Parameters:
      thread - the thread for which to create the trace
    • CallerTrace

      public CallerTrace(int trimStackTrace)
      Constructs a new CallerTrace for the current thread and its current stack trace. The top trimStackTrace 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 new CallerTrace for the given thread and its current stack trace. The top trimStackTrace 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 using Thread.currentThread(). Use the constructors without Thread-parameter instead.
      Parameters:
      thread - the thread for which to create the trace
      trimStackTrace - the number of stack trace elements (from the top) that should be cut off
    • CallerTrace

      public CallerTrace(Thread thread, StackTraceElement[] stackTrace)
      Constructs a new CallerTrace for the given thread and the given stack trace.
      Parameters:
      thread - the thread for which to create the trace
      stackTrace - the stack trace to be logged
    • CallerTrace

      protected CallerTrace(StackTraceElement[] threadStack, Thread thread, int trimStackTrace)
      Creates a new CallerTrace 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 Details

    • getThread

      public Thread getThread()
      Returns the calling thread. The thread is only linked with a weak 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