class BeeperControl {
private final static ScheduledExecutorService scheduler =
Executors.newScheduledThreadPool(1);
public static void main(String[] args){
beepForAnHour();
}
public static void beepForAnHour() {
final Runnable beeper = new Runnable() {
public void run() {
System.out.println(“beep”);
}
};
final ScheduledFuture beeperHandle =
scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
scheduler.schedule(new Runnable() {
public void run() {
beeperHandle.cancel(true);
}
}, 60 * 60, SECONDS);
}
}
此代码每 10 秒发出一声哔哔声,持续一个小时。我如何让它永远每 10 分钟响一次。因为它应该永远每 10 分钟发出一次哔哔声(不仅仅是一个小时)