Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Who Created a Thread (w. Eclipse)

Tags:

How can I find out who created a Thread in Java?

Imagine the following: You use ~30 third party JARs in a complex plugin environment. You start it up, run lots of code, do some calculations and finally call shutdown().

This life-cycle usually works fine, except that on every run some (non-daemonic) threads remain dangling. This would be no problem if every shutdown was the last shutdown, I could simply run System.exit() in that case. However, this cycle may run several times and it's producing more garbage every pass.

So, what should I do? I see the threads in Eclipse's Debug View. I see their stack traces, but they don't contain any hint about their origin. No creator's stack trace, no distinguishable class name, nothing.

Does anyone have an idea how to address this problem?

like image 871
EoH Avatar asked Aug 04 '09 12:08

EoH


1 Answers

Okay, I was able to solve (sort of) the problem on my own: I put a breakpoint into

Thread.start()  

and manually stepped through each invocation. This way I found out pretty quickly that Class.forName() initialized lot of static code which in return created these mysterious threads.

While I was able to solve my problem I still think the more general task still remains unaddressed.

like image 113
EoH Avatar answered Sep 19 '22 04:09

EoH