下面给出了一个join和interrupt互动的例子,还是主线程要join子线程。
例:1.5.3_1
class ThreadMark_to_win extends Thread {
Thread mainT;
int e;
public void run() {
for (int i = 0; i < 10; i++)
{
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
if(i==4) mainT.interrupt();
e = e + i;
}
System.out.println("完成"+"e 在子线程"+e);
}
public void setMainThread(Thread t1) {
mainT=t1;
}
}
public class Test {
public static void main(String[] args) {
Thread mainT = Thread.currentThread();
ThreadMark_to_win tm = new ThreadMark_to_win();
tm.setMainThread(mainT);
tm.start();
try {
更多请见:https://blog.csdn.net/qq_44639795/article/details/103096786