Are there any tools available to track the creation and lifetime of Java threads? I would be interested in all of the following:
I have written and published an open source tool to answer this question.
Java Live Thread Analyser
I have blogged about the tool here.
I don't know of any framework like this. You certainly could subclass the Thread class and store this information on your own like the following. This however will not track Threads that are allocated in other classes such as Executors, etc..
public class MyThread extends Thread {
StackTraceElement[] constructorTrace;
StackTraceElement[] startTrace;
long runStartTimeMillis;
long runFinishTimeMillis;
// you'll need to duplicate the constructors you need
public MyThread() {
super();
constructorTrace = Thread.currentThread().getStacktrace();
}
@Override
public void start() {
super.start();
startTrace = Thread.currentThread().getStacktrace();
}
@Override
public void run() {
runStartTimeMillis = System.currentTimeMillis();
super.run();
runFinishTimeMillis = System.currentTimeMillis();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With