你永远叫不醒一个装睡的人
2016-12-15 本文已影响67人
brzhang
public class TheManPossumsleep implements Runnable {
@Override
public void run() {
doWork();
}
private void doWork() {
int i=1;
while (true) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
//e.printStackTrace();
System.out.println("第"+i+"被叫醒一次...");
}
i++;
System.out.println("继续睡觉...");
}
}
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(new TheManPossumsleep());
thread.start();
while (true){
if (!thread.isInterrupted()) {
System.out.println("发现那家伙在睡觉,叫醒他...");
thread.interrupt();
}
Thread.sleep(1000);
}
}
}