package cn.java.threadcoreknowledge.stopthread;
public class RightStopThreadInProd implements Runnable {
@Override
public void run() {
while(true && !Thread.currentThread().isInterrupted()) {
System.out.println("go");
try {
throwInMethod();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void throwInMethod() throws InterruptedException {
Thread.sleep(2000);
}
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(new RightStopThreadInProd());
thread.start();
Thread.sleep(1000);
thread.interrupt();
}
}
这是照着课程敲的代码,我有两个地方不懂: