我浏览了一下春季计划程序支持文档。
我在那里发现:
ScheduledFuture schedule (Runnable task, Date startTime);但是在@EnableScheduling的情况下,在各种例子中没有线程实现。
为什么??任何人都可以事先解释谢谢。
发布于 2015-03-23 11:04:02
使用@EnableScheduling,您只需启用spring调度程序功能即可。
要运行一个任务,您需要使用@Scheduled注释一个公共方法。因此,您可以看到,您不需要运行/线程,因为您的烦恼方法将被调用使用反射。
@EnableScheduling
public class Tasks {
@Scheduled(... options here)
public void myTasks(){
//doSomethingHere...
}
}发布于 2018-04-19 12:31:46
我们的类至少必须有以下注释:
封装org.springframework.scheduling.annotation
@Configuration
@EnableScheduling您可以使用fixedDelay设置它。
@Scheduled(fixedDelay = 1000)对于initialDelay,还可以:
@Scheduled(fixedDelay = 1000, initialDelay = 1000)或者使用fixedRate (当任务的每次执行都是独立的)
@Scheduled(fixedRate = 1000)您还可以在运行时使用
org.springframework.scheduling.annotation.SchedulingConfigurer
public class SchedulerContextconfig implements SchedulingConfigurer
@Override
public void configureTasks(ScheduledTaskRegistrar register) {
register.addCronTask(Runnable task, String expression)
}https://stackoverflow.com/questions/29208149
复制相似问题