Quartz is a full-featured, open source job scheduling service that can be integrated with, or used along side virtually any Java EE or Java SE application - from the smallest stand-alone application to the largest e-commerce system.
package perso.tests.timer;
import java.util.Timer;
import java.util.TimerTask;
public class TimerExample extends TimerTask{
Timer timer;
int executionsPerSecond;
public TimerExample(int executionsPerSecond){
this.executionsPerSecond = executionsPerSecond;
timer = new Timer();
long period = 1000/executionsPerSecond;
timer.schedule(this, 200, period);
}
public void functionToRepeat(){
System.out.println(executionsPerSecond);
}
public void run() {
functionToRepeat();
}
public static void main(String args[]) {
System.out.println("About to schedule task.");
new TimerExample(3);
new TimerExample(6);
new TimerExample(9);
System.out.println("Tasks scheduled.");
}
}
看看http://quartz-scheduler.org/
轻量级选项是ScheduledExecutorService。在
与python代码片段大致相当的Java代码是:
留给读者的练习:
看看java.util.Timer. 在
您可以找到使用here的示例
你也可以考虑石英,这是更强大的,可以结合使用 有了春天 这是一个example
这是我的等效用法java.util.Timer你提到的代码片段
相关问题 更多 >
编程相关推荐