标签:star 参数 blank join oid int 文章 system net
下面这个例子和上面一样,除了说是子线程要join主线程。本例中还教会了大家,如何从主线程传参数到子线程。
例:1.5.3_2
class ThreadMark_to_win extends Thread {
Thread mainT;
Test t;
public void run() {
try {
mainT.join();
} catch (InterruptedException e) {
System.out.println("我是子程序, 也被打断");
}
System.out.println("完成"+"e 在子线程"+t.e);
}
public void setMainThread(Thread t1, Test tTest) {
mainT=t1;
t=tTest;
}
}
public class Test {
int e;
public static void main(String[] args) {
Test t=new Test();
Thread mainT = Thread.currentThread();
ThreadMark_to_win tm = new ThreadMark_to_win();
tm.setMainThread(mainT,t);
tm.start();
for (int i = 0; i < 10; i++)
{
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
if(i==4) tm.interrupt();
t.e = t.e + i;
}
System.out.println("主线程e = " + t.e);
}
}
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_43650923/article/details/101215957
标签:star 参数 blank join oid int 文章 system net
原文地址:https://www.cnblogs.com/xiaolongxia1922/p/14620970.html