67,513
社区成员
发帖
与我相关
我的任务
分享
public class Interrupt {
public static void main(String[] args) {
Runnable it=new InterruptTest();
Thread thread=new Thread(it);
thread.start();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
thread.interrupt();
}
}
class InterruptTest implements Runnable {
@Override
public void run() {
int i=0;
while(true){
System.out.println(i++);
}
}
}