Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将Spring计划任务配置为在具有特定延迟的时间范围内运行?_Java_Spring_Cron_Scheduled Tasks - Fatal编程技术网

Java 如何将Spring计划任务配置为在具有特定延迟的时间范围内运行?

Java 如何将Spring计划任务配置为在具有特定延迟的时间范围内运行?,java,spring,cron,scheduled-tasks,Java,Spring,Cron,Scheduled Tasks,我需要设置从下午5点到早上8点每隔15分钟执行一次spring计划时间,如何指定这样的表达式?而且,我希望任务在工作日执行,不仅是周一到周五,而且要根据我对isBusinessDay逻辑的实现。Maven Dependency 部分 在指定的Cron上激发的方法 文档 弹簧靴 这个链接可能对您有所帮助。 在安全站点上,您需要添加相应国家的时区 // 0/15 -> Every 15 minutes on the clock // 17-20 -> Between 5pm and

我需要设置从下午5点到早上8点每隔15分钟执行一次spring计划时间,如何指定这样的表达式?而且,我希望任务在工作日执行,不仅是周一到周五,而且要根据我对isBusinessDay逻辑的实现。

Maven Dependency

部分

在指定的Cron上激发的方法

文档

弹簧靴


这个链接可能对您有所帮助。

在安全站点上,您需要添加相应国家的时区

// 0/15 -> Every 15 minutes on the clock
// 17-20 -> Between 5pm and 8pm 
@Scheduled(cron="0 0/15 17-20 * * ?",zone="Your time zone")
Ex:--
@Scheduled(cron="0 0/15 17-20 * * ?",zone="Asia/Calcutta")
public void yourJob(){
..........
..........your code
..........
}
下面是一些基本的玉米表达

The pattern is a list of six single space-separated fields: representing second, minute, hour, day, month, weekday. Month and weekday names can be given as the first three letters of the English names.

Example patterns:

"0 0 * * * *" = the top of every hour of every day.
"*/10 * * * * *" = every ten seconds.
"0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day.
"0 0 6,19 * * *" = 6:00 AM and 7:00 PM every day.
"0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30, 10:00 and 10:30 every day.
"0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays
"0 0 0 25 12 ?" = every Christmas Day at midnight
// 0/15 -> Every 15 minutes on the clock
// 17-20 -> Between 5pm and 8pm on the JVM timezone
// if you want timezone specific there is a 'zone' parameter: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/annotation/Scheduled.html#zone--
@Scheduled(cron="0 0/15 17-20 * * ?")
public void doSomething() {
    // ..
}
// 0/15 -> Every 15 minutes on the clock
// 17-20 -> Between 5pm and 8pm 
@Scheduled(cron="0 0/15 17-20 * * ?",zone="Your time zone")
Ex:--
@Scheduled(cron="0 0/15 17-20 * * ?",zone="Asia/Calcutta")
public void yourJob(){
..........
..........your code
..........
}
The pattern is a list of six single space-separated fields: representing second, minute, hour, day, month, weekday. Month and weekday names can be given as the first three letters of the English names.

Example patterns:

"0 0 * * * *" = the top of every hour of every day.
"*/10 * * * * *" = every ten seconds.
"0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day.
"0 0 6,19 * * *" = 6:00 AM and 7:00 PM every day.
"0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30, 10:00 and 10:30 every day.
"0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays
"0 0 0 25 12 ?" = every Christmas Day at midnight