Spring scheduled task cron expression (@ scheduled)

, Tangcheng 2021-09-15 05:40:57
spring scheduled task cron expression


  • annotation @Scheduled Can be added to a method as a trigger source , for example , The following method will take a fixed delay time 5 Call once per second to execute , This cycle is the of the previous call task Completion time Benchmarking , After the last task ,5s Then execute again :
@Scheduled(fixedDelay = 5000)
public void doSomething() {
}
  • If necessary, perform at a fixed rate , Just change the attribute name specified in the annotation to fixedRate that will do , The following method will be at a fixed rate 5s To invoke an execution , This cycle is the above task Starting time Benchmarking , Since the last task 5s Call again :
@Scheduled(fixedRate = 5000)
public void doSomething() {
}

cron expression  @Scheduled(cron = "0 0 2 * * ?")

package com.imwoniu.task;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class TaskDemo {
@Scheduled(cron = "0 0 2 * * ?") // Every day at 2 a.m
void doSomethingWith(){
// Timed mission starts ......"
long begin = System.currentTimeMillis();
// The database operation has been performed ...
long end = System.currentTimeMillis();
logger.info(" The timed mission ends , Total time consuming :[" + (end-begin) / 1000 + "] second ");
//new Date() All you do is call System.currentTimeMillis(). If only necessary or
// Number of milliseconds , Then you can use System.currentTimeMillis() To replace new Date(), The efficiency will be higher
// spot
}
}

One cron The expression has at least 6 individual ( Or maybe 7 individual ) Time elements separated by spaces

 In order
second (0~59)
minute (0~59)
Hours (0~23)
God ( month )(0~31, But you need to think about the number of days in your month )
month (0~11)
God ( week )(1~7 1=SUN or SUN,MON,TUE,WED,THU,FRI,SAT)
7. year (1970-2099)
Each of these elements can be a value ( Such as 6), A continuous interval (9-12), One interval (8-18/4)(/ Said every 4 Hours ), A list of (1,3,5), wildcard . because " Date in month " and " Date of the week " These two elements are mutually exclusive , You have to set one of these ?.
Some subexpressions can contain ranges or lists
for example : subexpression ( God ( week )) It can be for “MON-FRI”,“MON,WED,FRI”,“MON-WED,SAT”
“*” The character represents all possible values
therefore ,“*” In subexpression ( month ) Li means every month ,“*” In subexpression ( God ( week )) Every day of the week
“/” Character to specify the increment of a value
for example : In subexpression ( minute ) Inside “0/15” Says from the first 0 minutes , Every time 15 minute
In subexpression ( minute ) Inside “3/20” Says from the first 3 minutes , Every time 20 minute ( It and “3,23,43”) It means the same thing
“?” The character is used only for days ( month ) And the day ( week ) Two subexpression , Indicates that no value is specified
When 2 After one of the subexpression has been specified , In order to avoid conflict , You need to set the value of the other subexpression to “?”
“L” The character is used only for days ( month ) And the day ( week ) Two subexpression , It is the word “last” Abbreviation
But its meaning is different in two subexpressions .
In heaven ( month ) In the subexpression ,“L” It means the last day of the month
In heaven ( week ) From the expression ,“L” The last day of the week , That is to say SAT
If in “L” There is a specific content before , It has other meanings
for example :“6L” Is the last but one of the month 6 God ,“FRIL” The last Friday of the month
Be careful : In the use of “L” When parameters are , Do not specify a list or scope , Because it can cause problems 

版权声明
本文为[, Tangcheng]所创,转载请带上原文链接,感谢
https://javamana.com/2021/09/20210909120408080j.html

  1. 互聯網Java工程師面試題,遇到的面試官都是架構師級別,
  2. 从入门到精通系列Java高级工程师路线介绍,拼多多三面惨败,
  3. 今年最新整理的《高频Java面试题集合》,2021Java通用流行框架大全,
  4. La dernière collection de questions d'entrevue Java haute fréquence organisée cette année, 2021 Java Universal Popular Framework
  5. De l'introduction à l'introduction de l'itinéraire de l'ingénieur principal Java de la série Mastering, il y a eu de nombreux échecs.
  6. JavaScript operator (1), Web Development Engineer
  7. Java simultané Programming Books recommended, half - Runner Java Program see me easy to Attack!
  8. Trier les questions d'entrevue Javascript, trier les points de connaissance des itinéraires d'apprentissage
  9. Xiaopeng P7, a high-value domestic electric car that can't be missed
  10. Song Mengjun's "sleepless night" triggered an upsurge of dance storm after 00
  11. Encapsulated PHP sends HTTP requests with curl. Get and post are very easy to use
  12. Recommend a lightweight and practical excellent Linux panel - wgcloud
  13. 从思维图到基础再到深入,记一次字节跳动Java研发岗的面试经历,
  14. 从底层开始带你了解并发编程,五步搞定Java开发环境部署,
  15. 从基础到源码统统帮你搞定,一招彻底帮你搞定HashMap源码,
  16. 從基礎到源碼統統幫你搞定,一招徹底幫你搞定HashMap源碼,
  17. De la base au code source pour vous aider à résoudre tout, un tour pour vous aider à résoudre complètement le code source hashtap,
  18. Commencez par le bas pour vous familiariser avec la programmation simultanée, et terminez le déploiement de l'environnement de développement Java en cinq étapes.
  19. De la carte de pensée à la base et à l'approfondissement, prenez note de l'expérience d'entrevue d'un octet sautant le poste de recherche et développement Java.
  20. Open source: Suzhou tourism strategy based on pyecharts visual analysis
  21. Good play | every character hates it. How does jade building spring do it?
  22. 從底層開始帶你了解並發編程,五步搞定Java開發環境部署,
  23. 以商品超卖为例讲解Redis分布式锁,一招彻底帮你搞定HashMap源码,
  24. 从青铜到王者的路线,2021Java者未来的出路在哪里?
  25. JavaScript Advanced Programming (3rd Edition) Reading note 6
  26. 從青銅到王者的路線,2021Java者未來的出路在哪裏?
  27. Quelle est la voie à suivre pour les 2021 Java du bronze au roi?
  28. Prenez l'exemple de la surproduction de marchandises pour expliquer redis Distributed Lock, un tour complet pour vous aider à résoudre le code source de hashtap,
  29. 以商品超賣為例講解Redis分布式鎖,一招徹底幫你搞定HashMap源碼,
  30. Win10系统 java环境配置
  31. Non-ASCII character ‘\xe5‘ in file kf1.py on line 4, but no encoding declared; see http://python.or
  32. 手把手教你搭建微信小程序服务器(HTTPS)
  33. JavaScript Review sketch - 1
  34. sqli-labs-less-18 http头user agent+报错注入
  35. Git下载、安装、配置、配合Intellij Idea实现代码版本控制
  36. NHibernate inheritance
  37. Summary of basic knowledge points of JavaScript language (mind map)
  38. GIT télécharge, installe, configure et implémente le contrôle de version de code avec intellij idea
  39. Sqli Labs - less - 18 http header user agent + Error Reporting Injection
  40. Vous apprendrez à construire un serveur d'applet Wechat (https) à la main
  41. Non - ASCII character 'xe5' in file kf1.py on Line 4, but no Encoding declared;Voirhttp://python.or
  42. 作为一名程序员我不忘初心,Java最新实习面试经验总结,
  43. 作为一名Java面试者你应该知道的,2021最新Java常用开源库总结,
  44. 作为一个程序员,你觉得最大的悲哀是什么,2021年大厂Java岗面试必问,
  45. Configuration de l'environnement Java du système win10
  46. 作為一個程序員,你覺得最大的悲哀是什麼,2021年大廠Java崗面試必問,
  47. En tant que programmeur, quelle est la plus grande tristesse que vous ressentez? L'entrevue d'emploi Java de 2021 dans une grande usine vous demandera:
  48. Comme vous devriez le savoir en tant qu'intervieweur Java, 2021 dernier résumé des bibliothèques open source couramment utilisées pour Java,
  49. En tant que programmeur, je n'oublie pas le dernier résumé de mon expérience d'entrevue de stage en Java.
  50. 作為一名Java面試者你應該知道的,2021最新Java常用開源庫總結,
  51. New feature of Java 8. Stream (). Map (general programming method: collect. Groupingby)
  52. Computer graduation project java + SSM hospital registration system
  53. 作為一名程序員我不忘初心,Java最新實習面試經驗總結,
  54. 使用Docker部署Spring-Boot项目,论程序员成长的正确姿势,
  55. Conseils pour améliorer l'efficacité du Code Java mille fois
  56. 全网首发,我在华为做Java外包的真实经历!
  57. 全套Java视频百度云,终于找到一个看得懂的JVM内存模型了,
  58. Docker tutorial series (I) introduction to docker tutorial spring cloud mybatis distributed microservice Cloud Architecture
  59. 全網首發,我在華為做Java外包的真實經曆!
  60. Run around with money? Li Weijia fell into the storm of endorsement! In the face of collective hot discussion, personal attitude has become the focus of attention