Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement timed tasks in Springboot

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how Springboot implements scheduled tasks. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Scheduled task

The timing here is marked in the method + comments, if you want to modify the time of the generation environment, it is not very flexible, later add Quartz+boot, using the principle of database configuration and reflection.

Note: the cron expression of java is not quite the same as that of Linux. Note that java is 6 bits and linux is 5 bits.

Startup class

@ SpringBootApplication@EnableSchedulingpublic class Oss6Application {public static void main (String [] args) {SpringApplication.run (Oss6Application.class, args);}}

Service class

@ Servicepublic class ScheduledService {/ * second (seconds), minute (minutes), hour (hours), day of month (day), month (month), day of week (day of the week). * 0 * MON-FRI * [00 MON-FRI *] 5 14 minutes 18 * *?] every day at 14:00 sharp, and 18:00 sharp Every 5 minutes * [0 15 10? * 1-6] every month from Monday to Saturday at 10:15 * [0 02? * 6L] at 2 am on the last Saturday of every month * [0 02 LW *?] at 2 am on the last working day of each month * [0 02-4? * " 1] between 2: 00 a.m. and 4: 00 a.m. on the first Monday of every month Execute every hour on the hour. * / / @ Scheduled (cron = "0 * MON-SAT") / / @ Scheduled (cron = "0meme 1meme 2jue 3" 4 * MON-SAT ") / / @ Scheduled (cron =" 0-4 * MON-SAT ") @ Scheduled (cron =" 0amp 4 * MON-SAT ") / / execute public void hello () {System.out.println (" hello... ") every 4 seconds. Thank you for your reading! This is the end of this article on "how to achieve scheduled tasks in Springboot". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report