Package tenapull.util

Class StackTracePrinter

java.lang.Object
java.lang.Thread
tenapull.util.StackTracePrinter
All Implemented Interfaces:
java.lang.Runnable

public class StackTracePrinter
extends java.lang.Thread
A debugging utility only (thus the use of println statements...) for multi-thread concurrency issues. Obtains the stack traces of all threads, grouping threads with the same stack trace together, and showing any threads blocking other threads, then determining if there are any circular blocks.
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Thread

    java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
  • Field Summary

    Fields inherited from class java.lang.Thread

    MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String makeStackTraceString()
    Produces a string representation of the current thread's stack trace
    static java.lang.String makeStackTraceString​(java.lang.StackTraceElement[] elements)
    Produces a string representation of the provided stack trace elements array
    static java.lang.String makeStackTraceString​(java.lang.StackTraceElement[] elements, java.lang.String separator)
    Produces a string representation of the provided stack trace elements array using the provided separator between frames of the stack.
    static java.lang.String makeStackTraceString​(java.lang.Thread thread)
    Produces a string representation of the provided thread's stack trace
    static void print()
    The main working method that obtains and analyzes the stack traces and thread blocking patterns.
    void run()  
    static java.lang.String startThread()
    Starts a stackTracePrinter thread with a delay of 0
    static java.lang.String startThread​(int delay)
    Starts a stackTracePrinter thread with a delay of 0

    Methods inherited from class java.lang.Thread

    activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • startThread

      public static java.lang.String startThread()
      Starts a stackTracePrinter thread with a delay of 0
      Returns:
      the name of the new thread
    • startThread

      public static java.lang.String startThread​(int delay)
      Starts a stackTracePrinter thread with a delay of 0
      Parameters:
      delay - the number of millseconds to wait before performing the stack trace analysis and printing
      Returns:
      the name of the new thread
    • run

      public void run()
      Specified by:
      run in interface java.lang.Runnable
      Overrides:
      run in class java.lang.Thread
    • print

      public static void print()
      The main working method that obtains and analyzes the stack traces and thread blocking patterns. This may also be invoked by any thread from outside of the StackTracePrinter class
    • makeStackTraceString

      public static java.lang.String makeStackTraceString()
      Produces a string representation of the current thread's stack trace
      Returns:
      the string
    • makeStackTraceString

      public static java.lang.String makeStackTraceString​(java.lang.Thread thread)
      Produces a string representation of the provided thread's stack trace
      Parameters:
      thread - the thread
      Returns:
      the string
    • makeStackTraceString

      public static java.lang.String makeStackTraceString​(java.lang.StackTraceElement[] elements)
      Produces a string representation of the provided stack trace elements array
      Parameters:
      elements - the stack trace elements
      Returns:
      the string representation
    • makeStackTraceString

      public static java.lang.String makeStackTraceString​(java.lang.StackTraceElement[] elements, java.lang.String separator)
      Produces a string representation of the provided stack trace elements array using the provided separator between frames of the stack. This can be used, for example, to indent the entire stack trace by a tab, or the like
      Parameters:
      elements - the stack trace elements
      separator - the separator between frames
      Returns:
      the string representation