Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
<cflow-stack name="mainConstructor">
<called expr="threadtree.Main->new(..)" />
</cflow-stack>
<bind pointcut="execution(void threadtree.Main->init())" cflow="mainConstructor">
<interceptor class="threadtree.aspects.MyInterceptor" />
</bind>
public class Main {
public Main() {
init();
}
public void init() {
}
public static void main(String[] args) throws Exception {
Main m = new Main();
m.init();
}
}
InheritableThreadLocal. У него есть метод childValue(), который вызывается в родительской нити, до того как дочерняя нить стартует. Ясно, что таким образом можно сделать так, чтобы дети знали про своих родителей. PROFIT!!!public class ThreadingTest {
private static InheritableThreadLocal<Thread> threadTracker = new InheritableThreadLocal<Thread>() {
@Override
protected Thread childValue(Thread parentValue) {
return Thread.currentThread();
}
};
public static void main(String[] args)
{
new Thread("parent")
{
@Override
public void run() {
System.out.println("parent: my parent is " + threadTracker.get() );
new Thread("child")
{
@Override
public void run() {
System.out.println("child: my parent is " + threadTracker.get() );
new Thread("grand_child")
{
@Override
public void run() {
System.out.println("grand_child: my parent is " + threadTracker.get() );
}
}.start();
}
}.start();
}
}.start();
}
}
* This source code was highlighted with Source Code Highlighter.
«Танцы с бубном» вокруг Thread