昨天写的一个定时器类, 可以在设定的时间内屏蔽特定操作:
调用VarTimer类的Start()函数开始计时,在需要进行定时休眠的功能开始时通过getCanDo()判断是否可以苏醒!
调用VarTimer类的Start()函数开始计时,在需要进行定时休眠的功能开始时通过getCanDo()判断是否可以苏醒!
package test;
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;
MailProperties mp = new MailProperties(true);
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 getCanFlag(){
return !bRuning;
}
}
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;
MailProperties mp = new MailProperties(true);
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 getCanFlag(){
return !bRuning;
}
}