Skip to content

Latest commit

 

History

History
65 lines (49 loc) · 3.51 KB

README.md

File metadata and controls

65 lines (49 loc) · 3.51 KB

Build

Thread Origin Agent

In many situations is it helpful to find out who created a Thread.

To find the origin of a thread, this project provides a javaagent which logs the stacktrace at Thread creation.

Installation

Installation guide for the latest release

Usage

Insert -javaagent:<pathToThread-origin-agent.jar>=<packagesToIgnore> into the JVM-arguments (at the beginning!)
Examples:

java -javaagent:thread-origin-agent-1.0.0.jar -jar <appToInspect>.jar
java -javaagent:"C:\temp\thread-origin-agent-1.0.0.jar"=sun/awt,sun/java2d -jar <appToInspect>.jar

Note

Please note that it's not possible to monitor all Thread starts as the Thread class is loaded and used extremely early.
Some static instantiations that use Threads e.g. ForkJoinPool#common are therefore not affected by changing the underlying bytecode.

Example output for a Spring Boot application
[TOA] Arg: null
[TOA] Ignoring excluded:
[TOA] Trying to retransform loaded classes
[TOA] Ignoring javassist.CtField
...
[TOA] Retransformed loaded classes; 820x successful, 150x unmodifiable
[TOA] Detected java.lang.Thread.start() id: 46 name: background-preinit
[TOA]   org.springframework.boot.autoconfigure.BackgroundPreinitializer.performPreinitialization(BackgroundPreinitializer.java:129)
[TOA]   org.springframework.boot.autoconfigure.BackgroundPreinitializer.onApplicationEvent(BackgroundPreinitializer.java:85)
[TOA]   org.springframework.boot.autoconfigure.BackgroundPreinitializer.onApplicationEvent(BackgroundPreinitializer.java:55)
...
[TOA] Detected java.lang.Thread.start() id: 47 name: Thread-0
[TOA]   org.springframework.boot.autoconfigure.condition.OnClassCondition$ThreadedOutcomesResolver.<init>(OnClassCondition.java:147)
...

Additional configuration options

These options can be configured as system properties. Example:
-DTOA_LOG_CALLER_THREADS

Option Description
TOA_LOG_THREAD_JOINS Also logs Thread#join calls
TOA_LOG_CALLER_THREADS Displays additional information about the thread that started the new thread
TOA_DISPLAY_METHOD_INSTRUMENTATION_FAILURES Displays method instrumentation failures.
This happens when a method is not present or can't be instrumented due to other reasons (e.g. JDK internal method).
Produces a lot of log output so it's recommended to only enable it for debugging

Support

If you need support as soon as possible and you can't wait for any pull request, feel free to use our support.

Contributing

See the contributing guide for detailed instructions on how to get started with our project.

Dependencies and Licenses

View the license of the current project or the summary including all dependencies

This project was inspired by kreyssel/maven-examples