全屏
scheduleAtFixedRate(TimerTask task,Date firstTime,long period)方法用于安排指定的任务进行重复的固定速率执行,开始在指定的时间。
声明
以下是java.util.Timer.scheduleAtFixedRate()方法的声明。public void scheduleAtFixedRate(TimerTask task,Date firstTime,long period)
参数task--这是被调度的任务。
firstTime--这是首次在该任务将被执行。
period-- 这是在连续执行任务之间的毫秒的时间。
返回值
NA
异常IllegalArgumentException--下面的例子显示java.util.Timer.scheduleAtFixedRate()方法的使用
IllegalStateException--这将被抛出,如果任务已经安排或取消,计时器被取消,或者计时器线程已终止。
例子
下面的例子显示java.util.Timer.scheduleAtFixedRate()方法的使用package cn.sxt;
import java.util.*;
public class TimerDemo {
public static void main(String[] args) {
// creating timer task, timer
TimerTask tasknew = new TimerScheduleFixedRate();
Timer timer = new Timer();
// scheduling the task at fixed rate
timer.scheduleAtFixedRate(tasknew,new Date(),1000);
}
// this method performs the task
public void run() {
System.out.println("working at fixed rate");
}
}
现在编译和运行上面的代码示例,将产生以下结果。working at fixed rate
working at fixed rate
working at fixed rate
working at fixed rate and so on ...
分享到:
0评论