use*_*347 5 java calendar quartz-scheduler
我需要安排一个任务在java中自动运行..我需要相同的窗口调度功能.我已经做了每天,每年但是当我来到每周调度时卡住了......没有得到如何做到这一点.我正在使用java calendar.Please帮助找到一个很好的解决方案.
任何帮助或想法都会很明显
在Spring中调度任务可以通过4种方式完成,如下所示.
1.在@Scheduled注释中使用固定延迟属性的任务调度.
public class DemoServiceBasicUsageFixedDelay {
@Scheduled(fixedDelay = 5000)
// @Scheduled(fixedRate = 5000)
public void demoServiceMethod() {
System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date());
}
}
Run Code Online (Sandbox Code Playgroud)
2.在@Scheduled注释中使用cron表达式的任务调度
@Scheduled(cron = "*/5 * * * * ?")
public void demoServiceMethod() {
System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date());
}
Run Code Online (Sandbox Code Playgroud)
3.使用属性文件中的cron表达式进行任务调度.
@Scheduled(cron = "${cron.expression}")
public void demoServiceMethod() {
System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date());
}
Run Code Online (Sandbox Code Playgroud)
4.使用在上下文配置中配置的cron表达式的任务调度
public class DemoServiceXmlConfig {
public void demoServiceMethod() {
System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date());
}
}
Run Code Online (Sandbox Code Playgroud)
#4的XML配置
<task:scheduled-tasks>
<task:scheduled ref="demoServiceXmlConfig" method="demoServiceMethod" cron="#{applicationProps['cron.expression']}"></task:scheduled>
</task:scheduled-tasks>
Run Code Online (Sandbox Code Playgroud)
关于http://howtodoinjava.com/2013/04/23/4-ways-to-schedule-tasks-in-spring-3-scheduled-example/的更多解释
希望这对你有所帮助.