zoukankan      html  css  js  c++  java
  • 框架 Spring Boot 技术入门到整合 10-2 定时任务表达式的简单讲解与应用

    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:javajdkjdk8jdkinjava.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:8543,suspend=y,server=n -javaagent:C:Usersweijingli.IdeaIC2018.1systemcaptureAgentdebugger-agent.jar=file:/C:/Users/weijingli/AppData/Local/Temp/capture.props -Dfile.encoding=UTF-8 -classpath "D:javajdkjdk8jdkjrelibcharsets.jar;D:javajdkjdk8jdkjrelibdeploy.jar;D:javajdkjdk8jdkjrelibextaccess-bridge-64.jar;D:javajdkjdk8jdkjrelibextcldrdata.jar;D:javajdkjdk8jdkjrelibextdnsns.jar;D:javajdkjdk8jdkjrelibextjaccess.jar;D:javajdkjdk8jdkjrelibextjfxrt.jar;D:javajdkjdk8jdkjrelibextlocaledata.jar;D:javajdkjdk8jdkjrelibext
    ashorn.jar;D:javajdkjdk8jdkjrelibextsunec.jar;D:javajdkjdk8jdkjrelibextsunjce_provider.jar;D:javajdkjdk8jdkjrelibextsunmscapi.jar;D:javajdkjdk8jdkjrelibextsunpkcs11.jar;D:javajdkjdk8jdkjrelibextzipfs.jar;D:javajdkjdk8jdkjrelibjavaws.jar;D:javajdkjdk8jdkjrelibjce.jar;D:javajdkjdk8jdkjrelibjfr.jar;D:javajdkjdk8jdkjrelibjfxswt.jar;D:javajdkjdk8jdkjrelibjsse.jar;D:javajdkjdk8jdkjrelibmanagement-agent.jar;D:javajdkjdk8jdkjrelibplugin.jar;D:javajdkjdk8jdkjrelib
    esources.jar;D:javajdkjdk8jdkjrelib
    t.jar;F:xiangmu3XinFuQiangSpringboot_1download_resourceSpringbootDemodemodemo	argetclasses;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-starter-web2.4.0spring-boot-starter-web-2.4.0.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-starter2.4.0spring-boot-starter-2.4.0.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-starter-logging2.4.0spring-boot-starter-logging-2.4.0.jar;C:Usersweijingli.m2
    epositorychqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;C:Usersweijingli.m2
    epositorychqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;C:Usersweijingli.m2
    epositoryorgapachelogginglog4jlog4j-to-slf4j2.13.3log4j-to-slf4j-2.13.3.jar;C:Usersweijingli.m2
    epositoryorgapachelogginglog4jlog4j-api2.13.3log4j-api-2.13.3.jar;C:Usersweijingli.m2
    epositoryorgslf4jjul-to-slf4j1.7.30jul-to-slf4j-1.7.30.jar;C:Usersweijingli.m2
    epositoryjakartaannotationjakarta.annotation-api1.3.5jakarta.annotation-api-1.3.5.jar;C:Usersweijingli.m2
    epositoryorgyamlsnakeyaml1.27snakeyaml-1.27.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-starter-json2.4.0spring-boot-starter-json-2.4.0.jar;C:Usersweijingli.m2
    epositorycomfasterxmljacksoncorejackson-databind2.11.3jackson-databind-2.11.3.jar;C:Usersweijingli.m2
    epositorycomfasterxmljacksoncorejackson-annotations2.11.3jackson-annotations-2.11.3.jar;C:Usersweijingli.m2
    epositorycomfasterxmljacksoncorejackson-core2.11.3jackson-core-2.11.3.jar;C:Usersweijingli.m2
    epositorycomfasterxmljacksondatatypejackson-datatype-jdk82.11.3jackson-datatype-jdk8-2.11.3.jar;C:Usersweijingli.m2
    epositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.11.3jackson-datatype-jsr310-2.11.3.jar;C:Usersweijingli.m2
    epositorycomfasterxmljacksonmodulejackson-module-parameter-names2.11.3jackson-module-parameter-names-2.11.3.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-starter-tomcat2.4.0spring-boot-starter-tomcat-2.4.0.jar;C:Usersweijingli.m2
    epositoryorgapache	omcatembed	omcat-embed-core9.0.39	omcat-embed-core-9.0.39.jar;C:Usersweijingli.m2
    epositoryorgglassfishjakarta.el3.0.3jakarta.el-3.0.3.jar;C:Usersweijingli.m2
    epositoryorgapache	omcatembed	omcat-embed-websocket9.0.39	omcat-embed-websocket-9.0.39.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-web5.3.1spring-web-5.3.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-beans5.3.1spring-beans-5.3.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-webmvc5.3.1spring-webmvc-5.3.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-aop5.3.1spring-aop-5.3.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-context5.3.1spring-context-5.3.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-expression5.3.1spring-expression-5.3.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-core5.3.1spring-core-5.3.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-jcl5.3.1spring-jcl-5.3.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-devtools2.4.0spring-boot-devtools-2.4.0.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot2.4.0spring-boot-2.4.0.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-autoconfigure2.4.0spring-boot-autoconfigure-2.4.0.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-configuration-processor2.4.0spring-boot-configuration-processor-2.4.0.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-starter-freemarker2.4.0spring-boot-starter-freemarker-2.4.0.jar;C:Usersweijingli.m2
    epositoryorgfreemarkerfreemarker2.3.30freemarker-2.3.30.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-context-support5.3.1spring-context-support-5.3.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-starter-thymeleaf2.4.0spring-boot-starter-thymeleaf-2.4.0.jar;C:Usersweijingli.m2
    epositoryorg	hymeleaf	hymeleaf-spring53.0.11.RELEASE	hymeleaf-spring5-3.0.11.RELEASE.jar;C:Usersweijingli.m2
    epositoryorg	hymeleaf	hymeleaf3.0.11.RELEASE	hymeleaf-3.0.11.RELEASE.jar;C:Usersweijingli.m2
    epositoryorgattoparserattoparser2.0.5.RELEASEattoparser-2.0.5.RELEASE.jar;C:Usersweijingli.m2
    epositoryorgunbescapeunbescape1.1.6.RELEASEunbescape-1.1.6.RELEASE.jar;C:Usersweijingli.m2
    epositoryorg	hymeleafextras	hymeleaf-extras-java8time3.0.4.RELEASE	hymeleaf-extras-java8time-3.0.4.RELEASE.jar;C:Usersweijingli.m2
    epositorycomalibabadruid1.1.0druid-1.1.0.jar;D:javajdkjdk8jdklibjconsole.jar;D:javajdkjdk8jdklib	ools.jar;C:Usersweijingli.m2
    epositorymysqlmysql-connector-java5.1.41mysql-connector-java-5.1.41.jar;C:Usersweijingli.m2
    epositoryorgmybatisspringootmybatis-spring-boot-starter1.3.1mybatis-spring-boot-starter-1.3.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-starter-jdbc2.4.0spring-boot-starter-jdbc-2.4.0.jar;C:Usersweijingli.m2
    epositorycomzaxxerHikariCP3.4.5HikariCP-3.4.5.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-jdbc5.3.1spring-jdbc-5.3.1.jar;C:Usersweijingli.m2
    epositoryorgmybatisspringootmybatis-spring-boot-autoconfigure1.3.1mybatis-spring-boot-autoconfigure-1.3.1.jar;C:Usersweijingli.m2
    epositoryorgmybatismybatis3.4.5mybatis-3.4.5.jar;C:Usersweijingli.m2
    epositoryorgmybatismybatis-spring1.3.1mybatis-spring-1.3.1.jar;C:Usersweijingli.m2
    epository	kmybatismapper-spring-boot-starter1.2.4mapper-spring-boot-starter-1.2.4.jar;C:Usersweijingli.m2
    epository	kmybatismapper-spring-boot-autoconfigure1.2.4mapper-spring-boot-autoconfigure-1.2.4.jar;C:Usersweijingli.m2
    epository	kmybatismapper3.5.3mapper-3.5.3.jar;C:Usersweijingli.m2
    epositoryjavaxpersistencepersistence-api1.0persistence-api-1.0.jar;C:Usersweijingli.m2
    epositorycomgithubpagehelperpagehelper-spring-boot-starter1.2.3pagehelper-spring-boot-starter-1.2.3.jar;C:Usersweijingli.m2
    epositorycomgithubpagehelperpagehelper-spring-boot-autoconfigure1.2.3pagehelper-spring-boot-autoconfigure-1.2.3.jar;C:Usersweijingli.m2
    epositorycomgithubpagehelperpagehelper5.1.2pagehelper-5.1.2.jar;C:Usersweijingli.m2
    epositorycomgithubjsqlparserjsqlparser1.0jsqlparser-1.0.jar;C:Usersweijingli.m2
    epositorycomalibabadruid-spring-boot-starter1.1.9druid-spring-boot-starter-1.1.9.jar;C:Usersweijingli.m2
    epositoryorgslf4jslf4j-api1.7.30slf4j-api-1.7.30.jar;C:Usersweijingli.m2
    epositoryorgmybatisgeneratormybatis-generator-core1.3.2mybatis-generator-core-1.3.2.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkootspring-boot-starter-data-redis2.4.0spring-boot-starter-data-redis-2.4.0.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkdataspring-data-redis2.4.1spring-data-redis-2.4.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkdataspring-data-keyvalue2.4.1spring-data-keyvalue-2.4.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkdataspring-data-commons2.4.1spring-data-commons-2.4.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-tx5.3.1spring-tx-5.3.1.jar;C:Usersweijingli.m2
    epositoryorgspringframeworkspring-oxm5.3.1spring-oxm-5.3.1.jar;C:Usersweijingli.m2
    epositoryiolettucelettuce-core6.0.1.RELEASElettuce-core-6.0.1.RELEASE.jar;C:Usersweijingli.m2
    epositoryio
    etty
    etty-common4.1.54.Final
    etty-common-4.1.54.Final.jar;C:Usersweijingli.m2
    epositoryio
    etty
    etty-handler4.1.54.Final
    etty-handler-4.1.54.Final.jar;C:Usersweijingli.m2
    epositoryio
    etty
    etty-resolver4.1.54.Final
    etty-resolver-4.1.54.Final.jar;C:Usersweijingli.m2
    epositoryio
    etty
    etty-buffer4.1.54.Final
    etty-buffer-4.1.54.Final.jar;C:Usersweijingli.m2
    epositoryio
    etty
    etty-codec4.1.54.Final
    etty-codec-4.1.54.Final.jar;C:Usersweijingli.m2
    epositoryio
    etty
    etty-transport4.1.54.Final
    etty-transport-4.1.54.Final.jar;C:Usersweijingli.m2
    epositoryioprojectreactor
    eactor-core3.4.0
    eactor-core-3.4.0.jar;C:Usersweijingli.m2
    epositoryorg
    eactivestreams
    eactive-streams1.0.3
    eactive-streams-1.0.3.jar;D:javadevolopKitideaanZhIntelliJ IDEA Community Edition 2018.1.4libidea_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:xiangmu3XinFuQiangSpringboot_1download_resourceSpringbootDemodemodemo	argetclasses started by weijingli in F:xiangmu3XinFuQiangSpringboot_1download_resourceSpringbootDemodemodemo)
    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
  • 相关阅读:
    ActiveMQ (二):JMS
    Java消息队列--ActiveMq 初体验
    利用 UltraEdit 重新排版 XML 结构数据
    Java中的Arrays工具类
    数组的下标与长度
    数组的一维与多维
    MySQL数据库的下载与安装
    MySQL数据库的发展历程
    Java中的数组(Array)
    break与continue关键字
  • 原文地址:https://www.cnblogs.com/1446358788-qq/p/14195386.html
Copyright © 2011-2022 走看看