1
已经创建了具有全局变量的下面的类。 但是,为什么我的线程没有结束或死亡。Java多核线程 - 线程未结束
public class MTTest {
private static boolean isRequestToStop = false;
public static void main(String [] args) throws Exception{
Thread T = new Thread (new Runnable(){
public void run(){
while(!getRequestToStop()) {
//System.out.println(" Value is " +getRequestToStop());
//System.out.println("Thread");
}
}
});
T.start();
Thread.sleep(1000);
setRequestToStop();
//isRequestToStop = true;
}
public static void setRequestToStop(){
System.out.println("--- setRequestToStop()--- Called");
isRequestToStop = true;
}
public static boolean getRequestToStop(){
return isRequestToStop;
}
}