0    课程地址

https://www.imooc.com/video/16792/0

 

1    课程重点
1.1  cron表达式在线生成地址(非年)

https://qqe2.com/cron 

 

1.2  重点

cron表达式 注解相关@Scheduled(cron =)

 

2    课程demo
2.1  课程demo

顶类:(同上节)

定时任务类:

package com.example.demo.task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * TestTask
 *
 * @author 魏豆豆
 * @date 2020/12/27
 */
//标注Spring管理的Bean,使用@Component注解在一个类上,表示将此类标记为Spring容器中的一个Bean。
@Component
public class TestTask {

    private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");

    //定义每3秒执行任务
    //@Scheduled(fixedRate = 3000)
    @Scheduled(cron = "10-40 * * * * ? ")
    public void printCurrentTime(){
        System.out.println("当前时间为:"+simpleDateFormat.format(new Date()));
    }
}

 

打印日志:

D:\java\jdk\jdk8\jdk\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:8543,suspend=y,server=n -javaagent:C:\Users\weijingli\.IdeaIC2018.1\system\captureAgent\debugger-agent.jar=file:/C:/Users/weijingli/AppData/Local/Temp/capture.props -Dfile.encoding=UTF-8 -classpath "D:\java\jdk\jdk8\jdk\jre\lib\charsets.jar;D:\java\jdk\jdk8\jdk\jre\lib\deploy.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\access-bridge-64.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\cldrdata.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\dnsns.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\jaccess.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\jfxrt.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\localedata.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\nashorn.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\sunec.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\sunjce_provider.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\sunmscapi.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\sunpkcs11.jar;D:\java\jdk\jdk8\jdk\jre\lib\ext\zipfs.jar;D:\java\jdk\jdk8\jdk\jre\lib\javaws.jar;D:\java\jdk\jdk8\jdk\jre\lib\jce.jar;D:\java\jdk\jdk8\jdk\jre\lib\jfr.jar;D:\java\jdk\jdk8\jdk\jre\lib\jfxswt.jar;D:\java\jdk\jdk8\jdk\jre\lib\jsse.jar;D:\java\jdk\jdk8\jdk\jre\lib\management-agent.jar;D:\java\jdk\jdk8\jdk\jre\lib\plugin.jar;D:\java\jdk\jdk8\jdk\jre\lib\resources.jar;D:\java\jdk\jdk8\jdk\jre\lib\rt.jar;F:\xiangmu3\Xin\FuQiang\Springboot_1\download_resource\SpringbootDemo\demo\demo\target\classes;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.4.0\spring-boot-starter-web-2.4.0.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-starter\2.4.0\spring-boot-starter-2.4.0.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.4.0\spring-boot-starter-logging-2.4.0.jar;C:\Users\weijingli\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\weijingli\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\weijingli\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.13.3\log4j-to-slf4j-2.13.3.jar;C:\Users\weijingli\.m2\repository\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;C:\Users\weijingli\.m2\repository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;C:\Users\weijingli\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\weijingli\.m2\repository\org\yaml\snakeyaml\1.27\snakeyaml-1.27.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.4.0\spring-boot-starter-json-2.4.0.jar;C:\Users\weijingli\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.11.3\jackson-databind-2.11.3.jar;C:\Users\weijingli\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.11.3\jackson-annotations-2.11.3.jar;C:\Users\weijingli\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.11.3\jackson-core-2.11.3.jar;C:\Users\weijingli\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.11.3\jackson-datatype-jdk8-2.11.3.jar;C:\Users\weijingli\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.11.3\jackson-datatype-jsr310-2.11.3.jar;C:\Users\weijingli\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.11.3\jackson-module-parameter-names-2.11.3.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.4.0\spring-boot-starter-tomcat-2.4.0.jar;C:\Users\weijingli\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.39\tomcat-embed-core-9.0.39.jar;C:\Users\weijingli\.m2\repository\org\glassfish\jakarta.el\3.0.3\jakarta.el-3.0.3.jar;C:\Users\weijingli\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.39\tomcat-embed-websocket-9.0.39.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-web\5.3.1\spring-web-5.3.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-beans\5.3.1\spring-beans-5.3.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-webmvc\5.3.1\spring-webmvc-5.3.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-aop\5.3.1\spring-aop-5.3.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-context\5.3.1\spring-context-5.3.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-expression\5.3.1\spring-expression-5.3.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-core\5.3.1\spring-core-5.3.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-jcl\5.3.1\spring-jcl-5.3.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-devtools\2.4.0\spring-boot-devtools-2.4.0.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot\2.4.0\spring-boot-2.4.0.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.4.0\spring-boot-autoconfigure-2.4.0.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-configuration-processor\2.4.0\spring-boot-configuration-processor-2.4.0.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-starter-freemarker\2.4.0\spring-boot-starter-freemarker-2.4.0.jar;C:\Users\weijingli\.m2\repository\org\freemarker\freemarker\2.3.30\freemarker-2.3.30.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-context-support\5.3.1\spring-context-support-5.3.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-starter-thymeleaf\2.4.0\spring-boot-starter-thymeleaf-2.4.0.jar;C:\Users\weijingli\.m2\repository\org\thymeleaf\thymeleaf-spring5\3.0.11.RELEASE\thymeleaf-spring5-3.0.11.RELEASE.jar;C:\Users\weijingli\.m2\repository\org\thymeleaf\thymeleaf\3.0.11.RELEASE\thymeleaf-3.0.11.RELEASE.jar;C:\Users\weijingli\.m2\repository\org\attoparser\attoparser\2.0.5.RELEASE\attoparser-2.0.5.RELEASE.jar;C:\Users\weijingli\.m2\repository\org\unbescape\unbescape\1.1.6.RELEASE\unbescape-1.1.6.RELEASE.jar;C:\Users\weijingli\.m2\repository\org\thymeleaf\extras\thymeleaf-extras-java8time\3.0.4.RELEASE\thymeleaf-extras-java8time-3.0.4.RELEASE.jar;C:\Users\weijingli\.m2\repository\com\alibaba\druid\1.1.0\druid-1.1.0.jar;D:\java\jdk\jdk8\jdk\lib\jconsole.jar;D:\java\jdk\jdk8\jdk\lib\tools.jar;C:\Users\weijingli\.m2\repository\mysql\mysql-connector-java\5.1.41\mysql-connector-java-5.1.41.jar;C:\Users\weijingli\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-starter\1.3.1\mybatis-spring-boot-starter-1.3.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.4.0\spring-boot-starter-jdbc-2.4.0.jar;C:\Users\weijingli\.m2\repository\com\zaxxer\HikariCP\3.4.5\HikariCP-3.4.5.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-jdbc\5.3.1\spring-jdbc-5.3.1.jar;C:\Users\weijingli\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\1.3.1\mybatis-spring-boot-autoconfigure-1.3.1.jar;C:\Users\weijingli\.m2\repository\org\mybatis\mybatis\3.4.5\mybatis-3.4.5.jar;C:\Users\weijingli\.m2\repository\org\mybatis\mybatis-spring\1.3.1\mybatis-spring-1.3.1.jar;C:\Users\weijingli\.m2\repository\tk\mybatis\mapper-spring-boot-starter\1.2.4\mapper-spring-boot-starter-1.2.4.jar;C:\Users\weijingli\.m2\repository\tk\mybatis\mapper-spring-boot-autoconfigure\1.2.4\mapper-spring-boot-autoconfigure-1.2.4.jar;C:\Users\weijingli\.m2\repository\tk\mybatis\mapper\3.5.3\mapper-3.5.3.jar;C:\Users\weijingli\.m2\repository\javax\persistence\persistence-api\1.0\persistence-api-1.0.jar;C:\Users\weijingli\.m2\repository\com\github\pagehelper\pagehelper-spring-boot-starter\1.2.3\pagehelper-spring-boot-starter-1.2.3.jar;C:\Users\weijingli\.m2\repository\com\github\pagehelper\pagehelper-spring-boot-autoconfigure\1.2.3\pagehelper-spring-boot-autoconfigure-1.2.3.jar;C:\Users\weijingli\.m2\repository\com\github\pagehelper\pagehelper\5.1.2\pagehelper-5.1.2.jar;C:\Users\weijingli\.m2\repository\com\github\jsqlparser\jsqlparser\1.0\jsqlparser-1.0.jar;C:\Users\weijingli\.m2\repository\com\alibaba\druid-spring-boot-starter\1.1.9\druid-spring-boot-starter-1.1.9.jar;C:\Users\weijingli\.m2\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;C:\Users\weijingli\.m2\repository\org\mybatis\generator\mybatis-generator-core\1.3.2\mybatis-generator-core-1.3.2.jar;C:\Users\weijingli\.m2\repository\org\springframework\boot\spring-boot-starter-data-redis\2.4.0\spring-boot-starter-data-redis-2.4.0.jar;C:\Users\weijingli\.m2\repository\org\springframework\data\spring-data-redis\2.4.1\spring-data-redis-2.4.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\data\spring-data-keyvalue\2.4.1\spring-data-keyvalue-2.4.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\data\spring-data-commons\2.4.1\spring-data-commons-2.4.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-tx\5.3.1\spring-tx-5.3.1.jar;C:\Users\weijingli\.m2\repository\org\springframework\spring-oxm\5.3.1\spring-oxm-5.3.1.jar;C:\Users\weijingli\.m2\repository\io\lettuce\lettuce-core\6.0.1.RELEASE\lettuce-core-6.0.1.RELEASE.jar;C:\Users\weijingli\.m2\repository\io\netty\netty-common\4.1.54.Final\netty-common-4.1.54.Final.jar;C:\Users\weijingli\.m2\repository\io\netty\netty-handler\4.1.54.Final\netty-handler-4.1.54.Final.jar;C:\Users\weijingli\.m2\repository\io\netty\netty-resolver\4.1.54.Final\netty-resolver-4.1.54.Final.jar;C:\Users\weijingli\.m2\repository\io\netty\netty-buffer\4.1.54.Final\netty-buffer-4.1.54.Final.jar;C:\Users\weijingli\.m2\repository\io\netty\netty-codec\4.1.54.Final\netty-codec-4.1.54.Final.jar;C:\Users\weijingli\.m2\repository\io\netty\netty-transport\4.1.54.Final\netty-transport-4.1.54.Final.jar;C:\Users\weijingli\.m2\repository\io\projectreactor\reactor-core\3.4.0\reactor-core-3.4.0.jar;C:\Users\weijingli\.m2\repository\org\reactivestreams\reactive-streams\1.0.3\reactive-streams-1.0.3.jar;D:\java\devolopKit\idea\anZh\IntelliJ IDEA Community Edition 2018.1.4\lib\idea_rt.jar" com.example.demo.DemoApplication
Connected to the target VM, address: '127.0.0.1:8543', transport: 'socket'
{spring.web.resources.chain.cache=false, spring.web.resources.cache.period=0}

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.0)

2020-12-27 08:17:56.888  INFO 17128 --- [  restartedMain] com.example.demo.DemoApplication         : Starting DemoApplication using Java 1.8.0_77 on DESKTOP-A08HONB with PID 17128 (F:\xiangmu3\Xin\FuQiang\Springboot_1\download_resource\SpringbootDemo\demo\demo\target\classes started by weijingli in F:\xiangmu3\Xin\FuQiang\Springboot_1\download_resource\SpringbootDemo\demo\demo)
2020-12-27 08:17:56.898  INFO 17128 --- [  restartedMain] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2020-12-27 08:17:57.320  INFO 17128 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-12-27 08:17:57.320  INFO 17128 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-12-27 08:18:01.211  INFO 17128 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-12-27 08:18:01.237  INFO 17128 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2020-12-27 08:18:01.506  INFO 17128 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 152 ms. Found 0 Redis repository interfaces.
2020-12-27 08:18:04.004 ERROR 17128 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : An incompatible version [1.1.32] of the Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]
2020-12-27 08:18:07.448  INFO 17128 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8088 (http)
2020-12-27 08:18:07.514  INFO 17128 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-12-27 08:18:07.514  INFO 17128 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.39]
2020-12-27 08:18:07.969  INFO 17128 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/IMooc]  : Initializing Spring embedded WebApplicationContext
2020-12-27 08:18:07.969  INFO 17128 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 10644 ms
2020-12-27 08:18:08.873  INFO 17128 --- [  restartedMain] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource
2020-12-27 08:18:11.104  INFO 17128 --- [  restartedMain] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited
2020-12-27 08:18:17.017  INFO 17128 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-12-27 08:18:18.256  WARN 17128 --- [  restartedMain] org.thymeleaf.templatemode.TemplateMode  : [THYMELEAF][restartedMain] Template Mode 'HTML5' is deprecated. Using Template Mode 'HTML' instead.
2020-12-27 08:18:19.961  INFO 17128 --- [  restartedMain] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
2020-12-27 08:18:20.214  INFO 17128 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2020-12-27 08:18:20.390  INFO 17128 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8088 (http) with context path '/IMooc'
2020-12-27 08:18:20.522  INFO 17128 --- [  restartedMain] com.example.demo.DemoApplication         : Started DemoApplication in 26.702 seconds (JVM running for 30.672)
当前时间为:08:18:21
当前时间为:08:18:22
当前时间为:08:18:23
当前时间为:08:18:24
当前时间为:08:18:25
当前时间为:08:18:26
当前时间为:08:18:27
当前时间为:08:18:28
当前时间为:08:18:29
当前时间为:08:18:30
当前时间为:08:18:31
当前时间为:08:18:32
当前时间为:08:18:33
当前时间为:08:18:34
当前时间为:08:18:35
当前时间为:08:18:36
当前时间为:08:18:37
当前时间为:08:18:38
当前时间为:08:18:39
当前时间为:08:18:40
当前时间为:08:19:10
当前时间为:08:19:11
当前时间为:08:19:12
当前时间为:08:19:13
当前时间为:08:19:14

 

posted on 2020-12-27 08:10  菜鸟乙  阅读(122)  评论(0编辑  收藏  举报