Unresolved task of tracking the tree of running Java threads using AOP
This opus appeared in connection with the article habrahabr.ru/blogs/java/74208
UPD. Much more suitable option solutions and discussion - habrahabr.ru/blogs/java/74208/#comment_2141270
Below is information on how it is conceived, but it does not work (can be and generally does not work :() We need to do 3 things:.
In -first, we create an interface and want the class
Secondly, we need to save the value somewhere
Thirdly, we need to somehow “take off with all this garbage.”
First 2 points are resolved as follows:
Create the class
and says, JBoss AOP, we want to mix our interface
The agent itself will already read the contents of the file myapp.jar! /META-INF/jboss-aop.xml and perform the necessary manipulations with the bytecode.
And now the saddest thing is that, apparently, JBoss AOP does not want to work with JRE classes, although everything works fine with project classes (well, or I “don’t know how to cook it”). Can someone tell me a solution? At AspectJ, at least in the documentation it is directly written that they do not support system classes (all with classLoader == null).
UPD. Much more suitable option solutions and discussion - habrahabr.ru/blogs/java/74208/#comment_2141270
Below is information on how it is conceived, but it does not work (can be and generally does not work :() We need to do 3 things:.
In -first, we create an interface and want the class
java.lang.Threadto implement it: public interface TreeInfo {
public Thread getParentThread();
}
Secondly, we need to save the value somewhere
Thread.currentThread()when calling the constructor of the Thread class. Thirdly, we need to somehow “take off with all this garbage.”
First 2 points are resolved as follows:
Create the class
public class ThreadTreeMixin {
Object target;
Thread parent;
public ThreadTreeMixin(Object target)
{
this.target = target;
this.parent = Thread.currentThread();
}
public Thread getParentThread() {
return parent;
}
}
//* поле Object target не обязательно - оставил его лишь для "примера".
and says, JBoss AOP, we want to mix our interface
TreeInfoclassThreadTreeMixina java.lang.Thread. To do this, we create the META-INF / jboss-aop.xml file in the program resources with the following contents:
And the final “non-working” part (point 3).
We take off with this as usual - with the help of javaagent:
threadtree.TreeInfo
threadtree.aspects.ThreadTreeMixin new threadtree.aspects.ThreadTreeMixin(this)
java -javaagent: jboss-aop-single.jar -classpath myapp.jar: ... myapp.Main
The agent itself will already read the contents of the file myapp.jar! /META-INF/jboss-aop.xml and perform the necessary manipulations with the bytecode.
And now the saddest thing is that, apparently, JBoss AOP does not want to work with JRE classes, although everything works fine with project classes (well, or I “don’t know how to cook it”). Can someone tell me a solution? At AspectJ, at least in the documentation it is directly written that they do not support system classes (all with classLoader == null).