[英]Java function to perform task every minute using computer's clock
Can someone please help me? 有人可以帮帮我吗? I have this java program that needs to perform a task every minute of the computer's clock. 我有这个Java程序,它需要在计算机时钟的每一分钟执行一次任务。
May I know if this is possible, and if yes what is the best way to do this? 我是否可以知道,如果可以,最好的方法是什么?
Thank you very much! 非常感谢你!
Use the ScheduledExecutorService . 使用ScheduledExecutorService 。 See a complete example here . 在这里查看完整的示例 。
You may try this: 您可以尝试以下方法:
int delay = 60000; // delay for 1 min.
int period = 5000; // repeat every 5 sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
// Task here ...
}
}, delay, period);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.