如何在這種情況下爲父母和孩子設置同名?如何從父級獲取線程名稱?
public class ComponentA {
public static void main(String[] args){
Bye bye = new Bye();
Thread t = new Thread(bye);
t.start();
}
}
我不能添加t.setName(Thread.currentThread().getName());
,因爲我需要避免更改代碼。我正在尋找可以從AspectJ類申請的解決方案。 有什麼方法可以將方法的參數置入run
?或者,也許在子線程中,我們可以得到parent name
?
編輯:
我的意思是:
- 母公司 - 主要在ComponentA
- 孩子 - 在再見
你所說的 「父」 與 「子」 是什麼意思?你是否將'Bye'(它必須位於包含'Runnable'的繼承樹)作爲子對象並將'Thread'對象't'作爲父對象? – 2012-08-07 13:56:15
什麼是父母?什麼名字?你想從啓動的線程('t')獲取主線程的名字嗎? – 2012-08-07 13:56:17
相關:http://stackoverflow.com/questions/11722749/how-to-find-the-name-of-the-parent-thread – Gray 2012-08-07 13:56:59