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
-
Field Summary
-
Method Summary
Modifier and Type Method Description static java.lang.String
makeStackTraceString()
Produces a string representation of the current thread's stack tracestatic java.lang.String
makeStackTraceString(java.lang.StackTraceElement[] elements)
Produces a string representation of the provided stack trace elements arraystatic 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 tracestatic 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 0static java.lang.String
startThread(int delay)
Starts a stackTracePrinter thread with a delay of 0Methods 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
-
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 interfacejava.lang.Runnable
- Overrides:
run
in classjava.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 elementsseparator
- the separator between frames- Returns:
- the string representation
-