1.在后台java代码中实现
写一个定时器任务类,此类继承TimerTask类。其中有个润run()方法,方法中即可写定时要执行的任务。
然后设置时间间隔调用上面的任务就可以了。
eg:public class ReportShow extends TimerTask {
public ReportShow(){
}
public void run() {
//此段是要执行的任务代码
int i=0;
System.out.println("i="+(i++));
}
public static void main(String[] args){
Long interval=1000l;
Timer timer=new Timer();
timer.schedule(new ReportShow(),0l, interval);
}
}
2.在页面使用js中重复发送请求,执行一个固定任务
function showMessage(){
//要执行的任务
alert(" dddd");
}
function autoFlus(){
//重复执行
showMessage();
setTimeout('autoFlus()',5000);
}
<input class="wen1" type="button" name="show" value="查看运行情况"
onclick="autoFlus();"> //触发动作