为什么我的thread终止( thread.interrupt();)无效, 还是一直输出
public class App
{
public static void main( String[] args ) throws InterruptedException {
Thread thread = new Thread(new A());
thread.start();
System.out.println(" start===========");
Thread.sleep(3000);
System.out.println(" sleep===========");
thread.interrupt();
System.out.println(" interrupt===========");
Thread.sleep(3000);
System.out.println(" stop===========");
}
}
class A extends Thread {
@Override
public void run() {
boolean result = false;
while (!result) {
System.out.println("=====thread run");
long time = System.currentTimeMillis();
if (System.currentTimeMillis() - time < 1000) {
// break;
}
}
System.out.println("while end");
}
}