我需要安排一个任务以固定的时间间隔运行。如何在支持长时间间隔的情况下执行此操作(例如每8小时一次)?
我目前正在使用java.util.Timer.scheduleAtFixedRate
。这个方法是否支持长时间间隔?
我需要安排一个任务以固定的时间间隔运行。如何在支持长时间间隔的情况下执行此操作(例如每8小时一次)?
我目前正在使用java.util.Timer.scheduleAtFixedRate
。这个方法是否支持长时间间隔?
你尝试过使用注解的 Spring Scheduler 吗?
@Scheduled(cron = "0 0 0/8 ? * * *")
public void scheduledMethodNoReturnValue(){
//body can be another method call which returns some value.
}
<task:scheduled-tasks>
<task:scheduled ref = "reference" method = "methodName" cron = "<cron expression here> -or- ${<cron expression from property files>}"
<task:scheduled-tasks>
if(bt.equals("accept")) {
ScheduledExecutorService scheduler=Executors.newScheduledThreadPool(1);
String lat=request.getParameter("latlocation");
String lng=request.getParameter("lnglocation");
requestingclass.updatelocation(lat,lng);
}
在java.util.concurrent中有一个名为ScheduledFuture
的类,它可能会对你有所帮助。