用callable接口,callable接口类似于runnable,但是callable具有返回值,调用其get()或者isalive()均可以判断线程,get()是阻塞的,isalive()是非阻塞的。
其中一个线程?使用类变量判断就可以了。
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;
}
}
}