In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how spring boot integrates quartz to manage timing tasks through page operation". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to integrate spring boot quartz to achieve timing tasks through page operation management" can help you solve the problem.
Know a few key words before using it:
Job
By implementing the Job class, we write down what we want the timed task to do in the implementation method, and then give it to quartz to manage.
JobDetail
Job is only responsible for implementing specific tasks, so you also need to use JobDetail to store some basic information that describes Job.
Quartz JobBuilder
The builder-style API provided for constructing JobDetail entities. You can use it to build a JobDetail like this:
@ Bean
Public JobDetail jobDetail () {
Return JobBuilder.newJob (). OfType (SampleJob.class)
. StoreDurably ()
. WithIdentity ("Qrtz_Job_Detail")
. WithDescription ("Invoke Sample Job service..." )
. Build ()
}
Spring JobDetailFactoryBean
How to configure JobDetail in Spring:
@ Bean
Public JobDetailFactoryBean jobDetail () {
JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean ()
JobDetailFactory.setJobClass (SampleJob.class)
JobDetailFactory.setDescription ("Invoke Sample Job service..." )
JobDetailFactory.setDurability (true)
Return jobDetailFactory
}
Trigger
Trigger, which represents the configuration of a scheduling parameter, when to schedule:
@ Bean
Public Trigger trigger (JobDetail job) {
Return TriggerBuilder.newTrigger (). ForJob (job)
. WithIdentity ("Qrtz_Trigger")
. WithDescription ("Sample trigger")
. WithSchedule (simpleSchedule (). RepeatForever (). WithIntervalInHours (1))
. Build ()
}
Scheduler
A scheduler, which registers a scheduler through Job and Trigger:
@ Bean
Public Scheduler scheduler (Trigger trigger, JobDetail job) {
StdSchedulerFactory factory = new StdSchedulerFactory ()
Factory.initialize (new ClassPathResource ("quartz.properties"). GetInputStream ()
Scheduler scheduler = factory.getScheduler ()
Scheduler.setJobFactory (springBeanJobFactory ())
Scheduler.scheduleJob (job, trigger)
Scheduler.start ()
Return scheduler
}
These are some of the concepts you need to know to use quartz, but to sum up there are only three things: job | jobDetail, trigger, and schedule. That is, tasks, triggers and schedulers. So we just have to instantiate them in code. And the task can be persisted to the database, which is convenient for us to operate all kinds of tasks.
Quartz automatically starts executing scheduled tasks in the executable state when the project starts, and can also support clustering.
This is the end of the content on "how spring boot integrates quartz to manage scheduled tasks through page operations". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.