public abstract class ThreadTracingRunnable extends Object implements Runnable
A stacktrace, together with the origin thread name, is going to be "saved" at the time this
class is instantiated and appended as "cause" to whatever is thrown from the run()
method.
To use this class, just extends it instead of implementing Runnable
. Then just
implement tracedRun(ThreadTracingRunnable)
.
If the runnable is created ahead of time and used somewhere else later, a new, more relevant,
stacktrace can be created calling resetTrace()
.
If you need to chain another Runnable from your run method, you can pass the Throwable
parameter from tracedRun(ThreadTracingRunnable)
to the constructor tracedRun(ThreadTracingRunnable)
. Therefore, the crash can now be tracked
across boundaries of multiple threads.
Constructor and Description |
---|
ThreadTracingRunnable() |
ThreadTracingRunnable(ThreadTracingRunnable prevTracingRunnable)
If you are chaining multiple Runnable together that are going to schedule each other within
their run() method, use this constructor to track their stacktraces across threads.
|
Modifier and Type | Method and Description |
---|---|
void |
resetTrace()
Reset the stacktrace of this Runnable to this point.
|
void |
run() |
abstract void |
tracedRun(ThreadTracingRunnable prevTracingRunnable)
Implement here your
Runnable.run() code. |
public ThreadTracingRunnable()
public ThreadTracingRunnable(ThreadTracingRunnable prevTracingRunnable)
tracedRun(ThreadTracingRunnable)
.public abstract void tracedRun(ThreadTracingRunnable prevTracingRunnable)
Runnable.run()
code.prevTracingRunnable
- If this ThreadTracingRunnable schedule another ThreadTracingRunnable
to another thread, pass this parameter to the new ThreadTracingRunnable class with ThreadTracingRunnable(ThreadTracingRunnable)
.public void resetTrace()