注:调度任务类上有注解@Component,调度方法上带注解@Scheduled,启动引导类上有注解@EnableScheduling,调度任务是单线程执行
一、@Scheduled参数说明
@Scheduled(cron = "0/3 * * * * ?") 从0秒开始,每隔3秒执行一次
@Scheduled(initialDelay = 1000, fixedRate = 2000) 第一次延迟1秒执行,然后在上一次开始执行时间点后2秒再次执行
@Scheduled(initialDelay=1000, fixedDelay = 2000) 第一次延迟1秒执行,然后在上一次执行完毕时间点后2秒再次执行
二、cron表达式说明
### cron表达式
* @Scheduled(cron = "* * * * * *")
* 顺序:{秒数} {分钟} {小时} {日期} {月份} {星期}
* 范围:{0~59} {0~59} {0~23} {1~31} {1~12} {1~7}
* 日期(1~7)字符串表示:SUN, MON, TUE, WED, THU, FRI, SAT
### cron表达式各占位符说明:
* “*” 代表每个单位时刻触发;
* “,” 代表在指定的秒数触发,比如”0,15,35”代表0秒、15秒和35秒时触发1次
* “-“ 代表在指定的范围内触发,比如”10-40”代表从10秒开始触发到40秒结束触发,每隔1秒触发1次
* “/” 代表触发步进(step),”/”前面的值代表初始值(““等同”0”),后面的值代表偏移量
* 例1:”0/10”或者”/10”代表从0秒钟开始,每隔10秒钟触发1次
* 即0秒触发1次,10秒、20秒、30秒、40秒、50秒各触发1次;
* 例2:”5/10”代表5秒触发1次,15秒、25秒、35秒、45秒、55秒各触发1次;
* 例3:”10-40/20”代表在[10,40]内,每步进20秒触发,即10秒触发1次,30秒触发1次
* “?” 只在日期中和星期中使用,用来表示任意值,表示每月的某一天,或周的某一天
* ”W” 只在日期中出现,用于指定最接近给定日期的工作日(星期一至星期五)
* 例1:“15W”含义是:“离月15日最近的工作日”。
* 如果15号是星期六,那么触发器将在14号星期五触发。
* 如果15日是星期日,则触发器将在16日星期一触发。
* 如果15号是星期二,那么它将在15号星期二触发。
* “#” 只在星期中出现
* 例1:“6#3”代表“每月的第三个星期五”
* ”L” 只在日期中和星期中出现,表示月或周的最后时间
* 例1:“L”用在星期中,表示‘7’或者‘SAT’
* 例2:带数字用在星期中,“6L”表示一个月的最后一个星期五
### 案例:
* “20 * * * * ?” 每分钟的20秒触发1次
* “20 10 * * * ?” 每小时的10分20秒触发1次
* “20 10 17 * * ?” 每天17点10分20秒触发1次
* “20 10 17 20 * ?” 每月20号17点10分20秒触发1次
* “20 10 17 20 10 ? *” 每年10月20号17点10分20秒触发1次
* “20 10 17 22 04 ? 2020” 2020年04月22号17点10分20秒触发1次
* “20 10 17 ? 04 * 2020” 2020年04月每天17点10分20秒触发1次
* “20 10 17 ? 10 SUN 2020” 2020年10月每周日17点10分20秒触发1次
* “15,30,45 * * * * ?” 每个15秒、30秒、45秒时各触发1次
* “15-45 * * * * ?” 15到45秒内,每秒都触发1次
* “15/5 * * * * ?” 每分钟的每15秒开始触发,每隔5秒触发一次
* “15-30/5 * * * * ?” 每分钟的15秒到30秒之间开始触发,每隔5秒触发一次
* “0 0/3 * * * ?” 每小时的第0分0秒开始,每三分钟触发一次
* “0 15 17 ? * MON-SAT” 星期一到星期六的17点15分0秒触发1次
* “0 15 17 L * ?” 每个月最后一天的17点15分0秒触发1次
* “0 15 17 LW * ?” 每个月最后一个工作日的17点15分0秒触发1次
* “0 15 17 ? * 5L” 每个月最后一个星期四的17点15分0秒触发1次
* “0 15 17 ? * 5#3” 每个月第三周的星期四的17点15分0秒触发1次
* ”0 0/5 13,18 * * ?” 每天从13点开始到13:55结束,然后从18点开始到18:55结束,每5分钟触发一次
* ”0 0 12 * * ? 2020” 2020年中每天的12:00触发一次
* “0 0-5 13 * * ?” 每天从13点开始到13:05结束的每分钟触发一次
* “0 15,45 13 ? 6 Tue” 6月的每个星期二的13:15和13:45触发一次
* “0 30 9 ? * MON-FRI” 每个星期一到星期五的9:30触发一次
* “0 30 9 15 * ?” 每月15日9:30触发一次
* “0 0 18 L * ?” 每个月的最后一天18点触发一次
* “0 0 18 L-3 * ?” 每个月的第三天至最后一天18点触发一次
* “0 30 10 ? * 5L” 每个月的最后一个星期四10:30触发一次
* ”0 0 18 ? * 6L 2018-2020“ 2018-2020每个月的最后一个星期五18点触发一次
* “0 0 10 ? * 2#3” 每个月的第三个星期一的10点触发一次
* “0 0 0 10/5 * ?” 从该月的第10天开始,每天从0点开始,为期5天各触发一次
三、demo详解
1. 创建调度任务类ScheduledTask
package com.zsx.action;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
@Component
@Slf4j
public class ScheduledTask {
/**
* {秒数:0~59} {分钟:0~59} {小时:0~23}
* {日期:1~31} {月份:1~12} {星期:1~7}
*/
@Scheduled(cron = "0/3 * * * * ?")
public void runA() throws InterruptedException {
log.info(Thread.currentThread().getName() + "AAA Start");
}
}
2. 创建引导类并启动
package com.zsx;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class MyTestApplication {
public static void main(String[] args) {
SpringApplication.run(MyTestApplication.class, args);
}
}
3. 查看控制台输出结果
E:\jdk\jdk-13.0.1\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:E:\JetBrains\IntelliJ IDEA 2019.2.3\lib\idea_rt.jar=59731:E:\JetBrains\IntelliJ IDEA 2019.2.3\bin" -Dfile.encoding=UTF-8 -classpath D:\MyIdeaProjects\my-test\target\classes;E:\maven\repository\org\springframework\boot\spring-boot-starter-web\2.2.0.RELEASE\spring-boot-starter-web-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter\2.2.0.RELEASE\spring-boot-starter-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-logging\2.2.0.RELEASE\spring-boot-starter-logging-2.2.0.RELEASE.jar;E:\maven\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;E:\maven\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;E:\maven\repository\org\apache\logging\log4j\log4j-to-slf4j\2.12.1\log4j-to-slf4j-2.12.1.jar;E:\maven\repository\org\apache\logging\log4j\log4j-api\2.12.1\log4j-api-2.12.1.jar;E:\maven\repository\org\slf4j\jul-to-slf4j\1.7.28\jul-to-slf4j-1.7.28.jar;E:\maven\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;E:\maven\repository\org\yaml\snakeyaml\1.25\snakeyaml-1.25.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-json\2.2.0.RELEASE\spring-boot-starter-json-2.2.0.RELEASE.jar;E:\maven\repository\com\fasterxml\jackson\core\jackson-databind\2.10.0\jackson-databind-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\core\jackson-annotations\2.10.0\jackson-annotations-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\core\jackson-core\2.10.0\jackson-core-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.10.0\jackson-datatype-jdk8-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.10.0\jackson-datatype-jsr310-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.10.0\jackson-module-parameter-names-2.10.0.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-tomcat\2.2.0.RELEASE\spring-boot-starter-tomcat-2.2.0.RELEASE.jar;E:\maven\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.27\tomcat-embed-core-9.0.27.jar;E:\maven\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.27\tomcat-embed-el-9.0.27.jar;E:\maven\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.27\tomcat-embed-websocket-9.0.27.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-validation\2.2.0.RELEASE\spring-boot-starter-validation-2.2.0.RELEASE.jar;E:\maven\repository\jakarta\validation\jakarta.validation-api\2.0.1\jakarta.validation-api-2.0.1.jar;E:\maven\repository\org\hibernate\validator\hibernate-validator\6.0.17.Final\hibernate-validator-6.0.17.Final.jar;E:\maven\repository\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;E:\maven\repository\com\fasterxml\classmate\1.5.0\classmate-1.5.0.jar;E:\maven\repository\org\springframework\spring-web\5.2.0.RELEASE\spring-web-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-beans\5.2.0.RELEASE\spring-beans-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-webmvc\5.2.0.RELEASE\spring-webmvc-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-aop\5.2.0.RELEASE\spring-aop-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-context\5.2.0.RELEASE\spring-context-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-expression\5.2.0.RELEASE\spring-expression-5.2.0.RELEASE.jar;E:\maven\repository\org\slf4j\slf4j-api\1.7.28\slf4j-api-1.7.28.jar;E:\maven\repository\org\springframework\spring-core\5.2.0.RELEASE\spring-core-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-jcl\5.2.0.RELEASE\spring-jcl-5.2.0.RELEASE.jar;E:\maven\repository\org\glassfish\jaxb\jaxb-core\2.3.0.1\jaxb-core-2.3.0.1.jar;E:\maven\repository\javax\xml\bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;E:\maven\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;E:\maven\repository\org\glassfish\jaxb\txw2\2.3.2\txw2-2.3.2.jar;E:\maven\repository\com\sun\istack\istack-commons-runtime\3.0.5\istack-commons-runtime-3.0.5.jar;E:\maven\repository\com\sun\xml\bind\jaxb-impl\2.3.2\jaxb-impl-2.3.2.jar;E:\maven\repository\org\projectlombok\lombok\1.18.10\lombok-1.18.10.jar;E:\maven\repository\org\springframework\boot\spring-boot-devtools\2.2.0.RELEASE\spring-boot-devtools-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot\2.2.0.RELEASE\spring-boot-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-autoconfigure\2.2.0.RELEASE\spring-boot-autoconfigure-2.2.0.RELEASE.jar com.zsx.MyTestApplication
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.0.RELEASE)
2020-04-23 11:57:29.710 INFO 5872 --- [ restartedMain] com.zsx.MyTestApplication : Starting MyTestApplication on zsx with PID 5872 (D:\MyIdeaProjects\my-test\target\classes started by 18273 in D:\MyIdeaProjects\my-test)
2020-04-23 11:57:29.716 INFO 5872 --- [ restartedMain] com.zsx.MyTestApplication : No active profile set, falling back to default profiles: default
2020-04-23 11:57:29.744 INFO 5872 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in E:\maven\repository\org\glassfish\jaxb\jaxb-core\2.3.0.1\jaxb-core-2.3.0.1.jar referenced one or more files that do not exist: file:/E:/maven/repository/org/glassfish/jaxb/jaxb-core/2.3.0.1/jaxb-api-2.3.0.jar,file:/E:/maven/repository/org/glassfish/jaxb/jaxb-core/2.3.0.1/txw2-2.3.0.1.jar,file:/E:/maven/repository/org/glassfish/jaxb/jaxb-core/2.3.0.1/istack-commons-runtime-3.0.5.jar
2020-04-23 11:57:29.745 INFO 5872 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in E:\maven\repository\com\sun\xml\bind\jaxb-impl\2.3.2\jaxb-impl-2.3.2.jar referenced one or more files that do not exist: file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/jaxb-runtime-2.3.2.jar,file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/txw2-2.3.2.jar,file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/istack-commons-runtime-3.0.8.jar,file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/stax-ex-1.8.1.jar,file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/FastInfoset-1.2.16.jar,file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/jakarta.activation-api-1.2.1.jar
2020-04-23 11:57:29.745 INFO 5872 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-04-23 11:57:29.745 INFO 5872 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-04-23 11:57:30.243 INFO 5872 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-04-23 11:57:30.249 INFO 5872 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-04-23 11:57:30.249 INFO 5872 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2020-04-23 11:57:30.286 INFO 5872 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-04-23 11:57:30.286 INFO 5872 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 541 ms
2020-04-23 11:57:30.381 INFO 5872 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-04-23 11:57:30.439 INFO 5872 --- [ restartedMain] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2020-04-23 11:57:30.448 INFO 5872 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-04-23 11:57:30.593 INFO 5872 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-04-23 11:57:30.596 INFO 5872 --- [ restartedMain] com.zsx.MyTestApplication : Started MyTestApplication in 1.051 seconds (JVM running for 1.509)
2020-04-23 11:57:33.004 INFO 5872 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA Start
2020-04-23 11:57:36.002 INFO 5872 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA Start
2020-04-23 11:57:39.002 INFO 5872 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA Start
2020-04-23 11:57:42.001 INFO 5872 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA Start
从结果看出每隔3秒执行一次
4. 修改调度方法runA()内容
/**
* {秒数:0~59} {分钟:0~59} {小时:0~23}
* {日期:1~31} {月份:1~12} {星期:1~7}
*/
@Scheduled(cron = "0/3 * * * * ?")
public void runA() throws InterruptedException {
log.info(Thread.currentThread().getName() + "AAA Start");
TimeUnit.SECONDS.sleep(5);
log.info(Thread.currentThread().getName() + "AAA End");
}
5. 重新启动引导类,查看结果
E:\jdk\jdk-13.0.1\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:E:\JetBrains\IntelliJ IDEA 2019.2.3\lib\idea_rt.jar=59851:E:\JetBrains\IntelliJ IDEA 2019.2.3\bin" -Dfile.encoding=UTF-8 -classpath D:\MyIdeaProjects\my-test\target\classes;E:\maven\repository\org\springframework\boot\spring-boot-starter-web\2.2.0.RELEASE\spring-boot-starter-web-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter\2.2.0.RELEASE\spring-boot-starter-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-logging\2.2.0.RELEASE\spring-boot-starter-logging-2.2.0.RELEASE.jar;E:\maven\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;E:\maven\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;E:\maven\repository\org\apache\logging\log4j\log4j-to-slf4j\2.12.1\log4j-to-slf4j-2.12.1.jar;E:\maven\repository\org\apache\logging\log4j\log4j-api\2.12.1\log4j-api-2.12.1.jar;E:\maven\repository\org\slf4j\jul-to-slf4j\1.7.28\jul-to-slf4j-1.7.28.jar;E:\maven\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;E:\maven\repository\org\yaml\snakeyaml\1.25\snakeyaml-1.25.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-json\2.2.0.RELEASE\spring-boot-starter-json-2.2.0.RELEASE.jar;E:\maven\repository\com\fasterxml\jackson\core\jackson-databind\2.10.0\jackson-databind-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\core\jackson-annotations\2.10.0\jackson-annotations-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\core\jackson-core\2.10.0\jackson-core-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.10.0\jackson-datatype-jdk8-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.10.0\jackson-datatype-jsr310-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.10.0\jackson-module-parameter-names-2.10.0.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-tomcat\2.2.0.RELEASE\spring-boot-starter-tomcat-2.2.0.RELEASE.jar;E:\maven\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.27\tomcat-embed-core-9.0.27.jar;E:\maven\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.27\tomcat-embed-el-9.0.27.jar;E:\maven\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.27\tomcat-embed-websocket-9.0.27.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-validation\2.2.0.RELEASE\spring-boot-starter-validation-2.2.0.RELEASE.jar;E:\maven\repository\jakarta\validation\jakarta.validation-api\2.0.1\jakarta.validation-api-2.0.1.jar;E:\maven\repository\org\hibernate\validator\hibernate-validator\6.0.17.Final\hibernate-validator-6.0.17.Final.jar;E:\maven\repository\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;E:\maven\repository\com\fasterxml\classmate\1.5.0\classmate-1.5.0.jar;E:\maven\repository\org\springframework\spring-web\5.2.0.RELEASE\spring-web-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-beans\5.2.0.RELEASE\spring-beans-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-webmvc\5.2.0.RELEASE\spring-webmvc-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-aop\5.2.0.RELEASE\spring-aop-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-context\5.2.0.RELEASE\spring-context-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-expression\5.2.0.RELEASE\spring-expression-5.2.0.RELEASE.jar;E:\maven\repository\org\slf4j\slf4j-api\1.7.28\slf4j-api-1.7.28.jar;E:\maven\repository\org\springframework\spring-core\5.2.0.RELEASE\spring-core-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-jcl\5.2.0.RELEASE\spring-jcl-5.2.0.RELEASE.jar;E:\maven\repository\org\glassfish\jaxb\jaxb-core\2.3.0.1\jaxb-core-2.3.0.1.jar;E:\maven\repository\javax\xml\bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;E:\maven\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;E:\maven\repository\org\glassfish\jaxb\txw2\2.3.2\txw2-2.3.2.jar;E:\maven\repository\com\sun\istack\istack-commons-runtime\3.0.5\istack-commons-runtime-3.0.5.jar;E:\maven\repository\com\sun\xml\bind\jaxb-impl\2.3.2\jaxb-impl-2.3.2.jar;E:\maven\repository\org\projectlombok\lombok\1.18.10\lombok-1.18.10.jar;E:\maven\repository\org\springframework\boot\spring-boot-devtools\2.2.0.RELEASE\spring-boot-devtools-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot\2.2.0.RELEASE\spring-boot-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-autoconfigure\2.2.0.RELEASE\spring-boot-autoconfigure-2.2.0.RELEASE.jar com.zsx.MyTestApplication
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.0.RELEASE)
2020-04-23 11:59:16.924 INFO 7660 --- [ restartedMain] com.zsx.MyTestApplication : Starting MyTestApplication on zsx with PID 7660 (D:\MyIdeaProjects\my-test\target\classes started by 18273 in D:\MyIdeaProjects\my-test)
2020-04-23 11:59:16.926 INFO 7660 --- [ restartedMain] com.zsx.MyTestApplication : No active profile set, falling back to default profiles: default
2020-04-23 11:59:16.957 INFO 7660 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in E:\maven\repository\org\glassfish\jaxb\jaxb-core\2.3.0.1\jaxb-core-2.3.0.1.jar referenced one or more files that do not exist: file:/E:/maven/repository/org/glassfish/jaxb/jaxb-core/2.3.0.1/jaxb-api-2.3.0.jar,file:/E:/maven/repository/org/glassfish/jaxb/jaxb-core/2.3.0.1/txw2-2.3.0.1.jar,file:/E:/maven/repository/org/glassfish/jaxb/jaxb-core/2.3.0.1/istack-commons-runtime-3.0.5.jar
2020-04-23 11:59:16.958 INFO 7660 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls : The Class-Path manifest attribute in E:\maven\repository\com\sun\xml\bind\jaxb-impl\2.3.2\jaxb-impl-2.3.2.jar referenced one or more files that do not exist: file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/jaxb-runtime-2.3.2.jar,file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/txw2-2.3.2.jar,file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/istack-commons-runtime-3.0.8.jar,file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/stax-ex-1.8.1.jar,file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/FastInfoset-1.2.16.jar,file:/E:/maven/repository/com/sun/xml/bind/jaxb-impl/2.3.2/jakarta.activation-api-1.2.1.jar
2020-04-23 11:59:16.958 INFO 7660 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-04-23 11:59:16.958 INFO 7660 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-04-23 11:59:17.461 INFO 7660 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-04-23 11:59:17.467 INFO 7660 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-04-23 11:59:17.467 INFO 7660 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2020-04-23 11:59:17.505 INFO 7660 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-04-23 11:59:17.505 INFO 7660 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 547 ms
2020-04-23 11:59:17.617 INFO 7660 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-04-23 11:59:17.680 INFO 7660 --- [ restartedMain] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2020-04-23 11:59:17.691 INFO 7660 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-04-23 11:59:17.812 INFO 7660 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-04-23 11:59:17.814 INFO 7660 --- [ restartedMain] com.zsx.MyTestApplication : Started MyTestApplication in 1.059 seconds (JVM running for 1.514)
2020-04-23 11:59:18.002 INFO 7660 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA Start
2020-04-23 11:59:23.004 INFO 7660 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA End
2020-04-23 11:59:24.001 INFO 7660 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA Start
2020-04-23 11:59:29.002 INFO 7660 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA End
2020-04-23 11:59:30.001 INFO 7660 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA Start
2020-04-23 11:59:35.002 INFO 7660 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA End
2020-04-23 11:59:36.002 INFO 7660 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA Start
2020-04-23 11:59:41.003 INFO 7660 --- [ scheduling-1] com.zsx.action.ScheduledTask : scheduling-1AAA End
从结果看出系统只创建了一个线程执行调度任务