package com.konghao.test;
//闹钟类
public class Alarm implements Runnable {
private boolean isWork; //闹钟是否工作
public Alarm() {
super();
this.isWork = false; //没在响;
}
public boolean isWork() {
return isWork;
}
public void setWork(boolean isWork) {
this.isWork = isWork;
}
//闹方法
public void work(){
synchronized (this) {
//闹钟运行时,打印字符
if(isWork){
System.out.println("it's time for up!");
this.notify();
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}else{
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}