日期:2014-05-20 浏览次数:20663 次
public class Runner2 implements Runnable {
public void run() {
try {
for (int i = 0; i < 30; i++) {
System.out.println(i);
Thread.sleep(1000);
}
} catch (InterruptedException ex) {
System.out.println("线程被中断");
return;
}
}
}
public class TestInterupt {
public static void main(String[] args) {
Runner2 runner2 = new Runner2();
Thread t = new Thread(runner2);
t.start();
try {
Thread.sleep(10000);
t.interrupt();
} catch (InterruptedException ex) {
System.out.println("主线程被中断");
}
}
}
public class Runner2 implements Runnable {
public void run() {
try {
for (int i = 0; i < 30; i++) {
Thread.sleep(1000);
System.out.println(i);
}
} catch (InterruptedException ex) {
System.out.println("线程被中断");
return;
}
}
}