所以我想弄清楚如何创建一个计时器,我遇到了这个: 使用ScheduledExecutorService来启动和停止计时器
他们的例子看起来效果很好.我只是想知道我是否正确使用它:
public class TimerTest
{
private ScheduledExecutorService es = null;
private boolean timeIsUp = false;
private ScheduledFuture futureHandler = null;
private TimeKeeper timeKeeper = null;
private String subject = "";
private int siteNo;
private long time;
private boolean stop;
public void endTimer()
{
System.out.println("we should shutdown everything here");
es.shutdownNow();
}
public boolean stopTimer()
{
if (timeKeeper != null)
{
timeKeeper.deactivate();
}
futureHandler.cancel(true);
return true;
}
public boolean isTimeup()
{
return timeKeeper.isTimeUp();
}
public void startTimer(long mseconds, String subj, …Run Code Online (Sandbox Code Playgroud)