java如何查看子线程是否执行完

2025-03-07 04:25:56
推荐回答(2个)
回答1:

用callable接口,callable接口类似于runnable,但是callable具有返回值,调用其get()或者isalive()均可以判断线程,get()是阻塞的,isalive()是非阻塞的。

回答2:

其中一个线程?使用类变量判断就可以了。

class A{
static boolean aStop = false;

static void test(){
new AThread().start();

while(! aStop){
}
System.out.println("AThread stoped.");

}

class AThread extends Thread{
public void run(){
/////////////////////////
aStop = true;

}

}

}