62,614
社区成员
发帖
与我相关
我的任务
分享
public class InterruptTest {
public static void main(String[] args) throws Exception {
for (int i = 1; i <= 10000; i++) {
Thread t = new Interrupt();
t.setName("thread" + i);
t.start();
}
}
private static class Interrupt extends Thread {
public void run() {
Thread t = new Sleep();
t.setName( getName() + "-sleep" );
t.start();
t.interrupt();
System.out.println( System.currentTimeMillis() + " " +
t.getName() + " " + t.isInterrupted() );
}
}
private static class Sleep extends Thread {
public void run() {
try {
Thread.sleep(1000);
} catch (Exception e) {
return;
}
System.err.println( System.currentTimeMillis() + " No! " +
getName() + " " + isInterrupted() );
}
}
}
1304393164531 No! thread949-sleep true
1304393164562 No! thread1128-sleep false
1304393163531 thread949-sleep true
1304393164531 No! thread949-sleep true
1304393163562 thread1128-sleep true
1304393164562 No! thread1128-sleep false
for (int i = 1; i <= 10000; i++) {
Thread t = new Interrupt();
t.setName("thread" + i);
t.start();
Thread.sleep(1);
}