Introduction to XXL-JOB

First of all, we need to know what XXL-JOB is, it is a distributed scheduling platform.

background

First, let me introduce the concept of timing tasks. Timing tasks mainly include performing a specific task at a certain point in time. There are several ways to implement timing tasks in Java:

  1. while(true)+Thread.sleep: Realize timing tasks by polling + thread sleep
  2. java.util.Timer+java.util.TimerTask: Timer is a timer tool provided by jdk, which can plan to execute a task or execute a task repeatedly; TimerTask is an abstract class of jdk, and its subclasses represent a task that can be Tasks scheduled by Timer
  3. ScheduleExecutorService: ScheduleExecutorService was introduced from jdk1.5 as a concurrent tool class, which is an ideal way to implement scheduled tasks
  4. Quartz: Quartz is an open source timing task scheduling framework written in Java and used for timing task scheduling in the Java ecosystem. It is a flexible, convenient, and easy-to-use timing task scheduling framework that can be integrated with Spring.
  5. Spring Task: A lightweight scheduled task scheduling tool provided by the Spring framework, easy to use
  6. Spring Boot Annotation @EnableScheduling+@Scheduled: The timing task scheduling tool provided by Spring Boot, the bottom layer is still Spring Task

Introduction to Distributed Task Scheduling

What is task scheduling?

We can first think about the solutions for the following business scenarios:

  • An e-commerce system needs to issue a batch of coupons at 10:00 am, 3:00 pm, and 8:00 pm every day.
  • A banking system needs to send SMS reminders three days before the due date of credit card repayment.
  • A financial system needs to settle the financial data of the previous day at 0:10 am every day, and collect statistics.
  • 12306 will set certain time points to release tickets in batches according to the number of trains.
  • In order to display the weather in real time, a website goes to the weather server to obtain the latest real-time weather information every 5 minutes.

Task scheduling refers to the process in which the system executes tasks at an agreed specific time in order to automatically complete specific tasks. With task scheduling, more manpower can be liberated and the system can automatically perform tasks.

The six timing task implementation methods introduced in the above chapters are mainly centralized timing tasks. Using centralized timing task scheduling will bring the following problems:

  1. How can the scheduled tasks deployed in multiple machine clusters ensure that the tasks are not executed repeatedly?
  2. How to dynamically adjust the execution time of scheduled tasks without restarting the application?
  3. How to implement failover when the machine fails when deploying tasks?
  4. How to monitor scheduled tasks?
  5. The business volume is relatively large, and the stand-alone performance bottleneck is encountered. How to expand the fragmentation?

Because of the above series of problems in centralized task scheduling, some specific solutions have been produced in the technological evolution:

  1. Use the unique constraint of the database to solve the duplicate execution problem
  2. Use configuration files, redis, mysql as a switch for scheduling
  3. Using distributed locks to implement task scheduling
  4. Use distributed task scheduling platforms, such as Elastic-Job, Saturn, TBSchedule, XXL-JOB, Google Cron, etc.

The use of distributed task scheduling platform is a good solution to solve the problems of centralized task scheduling comprehensively and systematically. Among them, XXL-JOB has many use cases in the domestic online production environment. Its core design goals are rapid development, easy learning, lightweight, and easy expansion. The address of the XXL-JOB official document is the distributed task scheduling platform XXL-JOB . The overall design architecture is as follows:

 

Guess you like

Origin blog.csdn.net/weixin_43918614/article/details/124421736