当前位置:编程学习 > JSP >>

一个简单的定时器应用: VarTimer (java)

答案:package cn.com.softwise.mailplug.service;

import java.util.Timer;
import java.util.TimerTask;

public class VarTimer {
private Timer timer;
private int iFreq;
private boolean bRuning;

public VarTimer() {
timer = null;
bRuning = false;

iFreq = 10;
}

public void start(){
if(!bRuning){
timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
bRuning = false;
timer.cancel();
}
} , iFreq * 60 * 1000);
bRuning = true;
}
}

public boolean getCanSendDo(){
return !bRuning;
}
}

上一个:java.util.Collection
下一个:用Java编写扫雷游戏--代码思想

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,