麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發(fā) > Java > 正文

SpringBoot任務調度器的實現(xiàn)代碼

2024-07-14 08:43:12
字體:
來源:轉載
供稿:網(wǎng)友

SpringBoot自帶了任務調度器,通過注解的方式使用。

啟用方式: 在配置類上注解 org.springframework.scheduling.annotation.EnableScheduling

Java示例

package bj.scheduler;import lombok.extern.slf4j.Slf4j;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;import org.springframework.scheduling.annotation.EnableScheduling;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.scheduling.annotation.Schedules;import java.time.LocalDateTime;/** * Created by [email protected] at 2018/12/12 下午2:51 */@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)@EnableScheduling@Slf4jpublic class SchedulerApp {  public static void main(String[] args) throws InterruptedException {    SpringApplication.run(SchedulerApp.class, args);    Thread.currentThread().join();  }  @Schedules({      @Scheduled(fixedRate = 1000),      @Scheduled(fixedDelay = 1001),      @Scheduled(cron = "* * * * * *")  })  public void sayHello() {    log.info("{} Hello", LocalDateTime.now());  }}

要點

  • @EnableScheduling 啟用任務調度器
  • @Schedules 組合多個調度器。多個調度器全部啟用。
  • @Scheduled 單個調度器的配置
  • fixedRate 固定執(zhí)行頻率(毫秒),不計執(zhí)行耗時
  • fixedDelay 固定執(zhí)行延遲(毫秒),表示距離上次執(zhí)行完畢的時長
  • cron CronTab調度格式,第一位表示秒

控制臺輸出

 .  ____     _      __ _ _ /// / ___'_ __ _ _(_)_ __ __ _ / / / /( ( )/___ | '_ | '_| | '_ // _` | / / / / /// ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_/__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::    (v2.1.0.RELEASE)2018-12-12 15:01:00.332 INFO 34660 --- [      main] bj.scheduler.SchedulerApp        : Starting SchedulerApp on MacBook-Air-2.local with PID 34660 (/Users/yuchao/temp/java/hellomaven/target/classes started by yuchao in /Users/yuchao/temp/java/hellomaven)2018-12-12 15:01:00.339 INFO 34660 --- [      main] bj.scheduler.SchedulerApp        : No active profile set, falling back to default profiles: default2018-12-12 15:01:02.395 INFO 34660 --- [      main] o.s.s.c.ThreadPoolTaskScheduler     : Initializing ExecutorService 'taskScheduler'2018-12-12 15:01:02.496 WARN 34660 --- [      main] reactor.netty.tcp.TcpResources      : [http] resources will use the default LoopResources: DefaultLoopResources {prefix=reactor-http, daemon=true, selectCount=4, workerCount=4}2018-12-12 15:01:02.498 WARN 34660 --- [      main] reactor.netty.tcp.TcpResources      : [http] resources will use the default ConnectionProvider: PooledConnectionProvider {name=http, poolFactory=reactor.netty.resources.ConnectionProvider$$Lambda$278/687399269@6594402a}2018-12-12 15:01:02.707 INFO 34660 --- [  scheduling-1] bj.scheduler.SchedulerApp        : 2018-12-12T15:01:02.707 Hello2018-12-12 15:01:02.707 INFO 34660 --- [  scheduling-1] bj.scheduler.SchedulerApp        : 2018-12-12T15:01:02.707 Hello2018-12-12 15:01:02.708 INFO 34660 --- [      main] bj.scheduler.SchedulerApp        : Started SchedulerApp in 3.257 seconds (JVM running for 4.997)2018-12-12 15:01:03.004 INFO 34660 --- [  scheduling-1] bj.scheduler.SchedulerApp        : 2018-12-12T15:01:03.004 Hello2018-12-12 15:01:03.704 INFO 34660 --- [  scheduling-1] bj.scheduler.SchedulerApp        : 2018-12-12T15:01:03.704 Hello2018-12-12 15:01:03.710 INFO 34660 --- [  scheduling-1] bj.scheduler.SchedulerApp        : 2018-12-12T15:01:03.710 Hello2018-12-12 15:01:04.002 INFO 34660 --- [  scheduling-1] bj.scheduler.SchedulerApp        : 2018-12-12T15:01:04.002 Hello2018-12-12 15:01:04.702 INFO 34660 --- [  scheduling-1] bj.scheduler.SchedulerApp        : 2018-12-12T15:01:04.702 Hello2018-12-12 15:01:04.712 INFO 34660 --- [  scheduling-1] bj.scheduler.SchedulerApp        : 2018-12-12T15:01:04.712 Hello2018-12-12 15:01:05.000 INFO 34660 --- [  scheduling-1] bj.scheduler.SchedulerApp        : 2018-12-12T15:01:05 Hello2018-12-12 15:01:05.700 INFO 34660 --- [  scheduling-1] bj.scheduler.SchedulerApp        : 2018-12-12T15:01:05.700 Hello2018-12-12 15:01:05.716 INFO 34660 --- [  scheduling-1] bj.scheduler.SchedulerApp        : 2018-12-12T15:01:05.716 Hello

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網(wǎng)。


注:相關教程知識閱讀請移步到JAVA教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 精品无吗乱吗av国产爱色 | 亚洲精品无码不卡在线播放he | 欧美三日本三级少妇三级99观看视频 | 污污短视频 | 亚洲无线看 | 2019中文字幕在线播放 | 12av毛片| 日本在线播放一区二区三区 | 一级在线免费 | 日韩精品无码一区二区三区 | 日韩黄色片在线观看 | 欧美成人一级 | 亚洲综合91 | 免费a级黄色片 | 黄色a级片免费观看 | 中文日韩字幕 | 日产精品久久久一区二区开放时间 | 欧美色视频免费 | 日韩理论电影网 | 暖暖免费观看高清完整版电影 | 失禁高潮抽搐喷水h | 噜噜噜在线 | 91成人免费在线视频 | 久久亚洲春色中文字幕久久 | 视频在线中文字幕 | 日韩美女电影 | 天天草天天操 | 午夜a狂野欧美一区二区 | 久久久麻豆 | 日本视频免费观看 | 免费观看一区二区三区 | 久久一本日日摸夜夜添 | 一本视频在线观看 | 精品一区二区三区免费 | 狠狠久久| 密室逃脱第一季免费观看完整在线 | 国产高潮失禁喷水爽到抽搐视频 | 国产一区二区三区精品在线观看 | 国产精品www | 久久久www视频 | 欧美成人国产va精品日本一级 |