Xxl-job [Study Notes · I]

preface
  • The topic is also the first time to contact XXL-job, so I will record my learning process, thoughts and skills
  • Learning notes will briefly introduce what I think of XXL-job, and will follow the document to run the demo
  • The following study notes will analyze and read the source code from the perspective of the executor, and will continue to update the source code of the dispatch center if time permits
XXL – what is the job
  1. Before learning xxL-job, let’s review what we know about task scheduling in the past
  • Linux crontab
  • Task scheduling under Spring
@Slf4j
@Component
public class MyTask {
    @Scheduled(fixedRate = 1000L)
    public void run(a) {
        log.info("On a mission every second."); }}Copy the code
  • Why do we need xxl-job with @scheduled? Because spring provides the scheduling annotation is simpler, if we have a spring application deployment N nodes, each node would run tasks, if a task does not have “power”, then can produce the unexpected errors, of course, we can write their own rules, let the task to run only on one node, such as a distributed lock, etc. Of course, the real environment is far more simple than that. The emergence of XXL-Job is to help us solve these possible problems
  1. Xxl-job is a distributed task scheduling framework. Keywords [distributed, task scheduling]
  • What is distributed? My understanding is rather vulgar, distribution is scattered, to describe a system is a distributed system, that is, to describe the current system is composed of a number of different applications scattered in different nodes combined to serve the upstream
  • What is task scheduling? Having tasks trigger at a specified time, or at a specified frequency, is what I understand as task scheduling
  • Xxl-job is an application that collaborates with N identical or different tasks and executes them at a specified time point or a specified frequency
  1. How to learn XXL-job
  • The best way to learn a new tool/framework is to get a general idea of what it is/what I want to do with it/guess how it works/read about it/run demos/follow the main link DEBUG
  • Click to jump to the document of xxl-job
Run the DEMO again
  1. Environment to prepare
  • git/maven/mysql/jdk8+
  1. Gitee address, first clone down
  2. Perform XXL – job \ doc \ db \ tables_xxl_job SQL
  3. Change xxl-job-admin’s application.properties, change database address, account password, etc
  4. Maven to perform the clean compile, run XXL – job – admin, and then go to http://localhost:8080/xxl-job-admin, the initial password is admin / 123456
  5. xxl-job-executor-samples\xxl-job-executor-sample-springboot
  • Modify the application. The properties, XXL. Job. Executor. Logpath = D: \ logs
  • Run com. XXL. Job. Executor. XxlJobExecutorApplication
  1. Create a task in admin and observe the log after execution (D:\logs\2021-12-14)
2021-12-14 22:54:34 [com.xxl.job.core.thread.JobThread#run]-[130]-[Thread-19] <br>----------- xxl-job job execute start -----------<br>----------- Param:
2021-12-14 22:54:34 [com.xxl.job.executor.service.jobhandler.SampleXxlJob#demoJobHandler]-[39]-[Thread-19] XXL-JOB, Hello World.
2021-12-14 22:54:34 [com.xxl.job.executor.service.jobhandler.SampleXxlJob#demoJobHandler]-[42]-[Thread-19] beat at:0
2021-12-14 22:54:36 [com.xxl.job.executor.service.jobhandler.SampleXxlJob#demoJobHandler]-[42]-[Thread-19] beat at:1
2021-12-14 22:54:38 [com.xxl.job.executor.service.jobhandler.SampleXxlJob#demoJobHandler]-[42]-[Thread-19] beat at:2
2021-12-14 22:54:40 [com.xxl.job.executor.service.jobhandler.SampleXxlJob#demoJobHandler]-[42]-[Thread-19] beat at:3
2021-12-14 22:54:42 [com.xxl.job.executor.service.jobhandler.SampleXxlJob#demoJobHandler]-[42]-[Thread-19] beat at:4
2021-12-14 22:54:44 [com.xxl.job.core.thread.JobThread#run]-[176]-[Thread-19] <br>----------- xxl-job job execute end(finish) -----------<br>----------- Result: handleCode=200, handleMsg = null
2021-12-14 22:54:44 [com.xxl.job.core.thread.TriggerCallbackThread#callbackLog]-[197]-[xxl-job, executor TriggerCallbackThread] <br>----------- xxl-job job callback finish.
Copy the code
tip
  1. Scheduling center (nodes that strip task logic and simply perform task scheduling)
  2. Executor (node where the task runs)
  3. Both scheduling centers and actuators can be deployed in a cluster. When creating a task, you can specify broadcast execution or single execution, and have the function of fast failover
At the end
  1. The whole article only has some personal opinions, other practices are basically completed according to the introduction of the document, very simple
  2. The second note will interpret the source code from an executor’s point of view and understand the overall framework logic