timer是java那个包_java.util.Timer.scheduleAtFixedRate()方法实例

全屏

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评论

14487a65ea137d8f9ac97cdce44a0324.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值