Cluster timed task execution method and device, equipment, medium and product
By storing timing tasks in the database and loading them into memory when the server is started, combined with the distributed lock mechanism, the problem of repeated scheduling and low storage efficiency of timing tasks in the cluster environment is solved, and efficient and real-time timing task execution is achieved.
Patent Information
- Application Number
- CN202411722132.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-03-18
AI Technical Summary
In a cluster environment, it is difficult for the prior art to effectively avoid the problem of repeated scheduling of timing tasks, and there is also the problem of low efficiency in storing task information.
By storing timing tasks in the target database, when the server cluster starts, these tasks are read from the database and stored in server memory. At the same time, a distributed lock mechanism is used to ensure that only one server performs timing tasks.
It solves the problem of repeated scheduling of timed tasks in the cluster environment, reduces the frequency of obtaining timed task status from the database, and improves the real-time and efficiency of tasks.
Smart Images

Figure CN119645600A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a cluster scheduled task execution method, device, equipment, medium and product. Background Art
[0002] Scheduled tasks are widely used in the computer field. Among them, the Quartz framework, as a task scheduling system, has the advantages of rich functions, flexible configuration, and easy to use, and is very popular in this field.
[0003] The server needs to store tasks during operation. Quartz has two storage modes for tasks: RAMJobStore and JobStoreSupport.
[0004] RAMJobStore stores task information in the server's memory. The task storage speed is very fast and has strong real-time performance during scheduling. However, once the server is restarted or shut down, the task information will be lost. In addition, since Quartz has no communication measures with the machines in the cluster environment in this mode, the cluster machines will repeatedly schedule tasks at the same time. JobStoreSupport stores task information in the database based on database connection. Its advantage is that it can persist Quartz's task running information. Even if the cluster server is restarted or shut down, its task information still exists. It also supports cluster mode and relies on the database to control task information, which can solve the problem of repeated scheduling in the cluster environment. However, the disadvantage is that the configuration is more complicated, and since the machine obtains the status of the task in the database at a certain frequency, it has a low efficiency problem. Summary of the invention
[0005] The embodiment of the present invention provides a cluster scheduled task execution method, device, equipment, medium and product, so as to solve the problem of repeated scheduling of cluster tasks.
[0006] According to one aspect of the present invention, a cluster scheduled task execution method is provided, comprising:
[0007] Create a scheduled task and store the scheduled task in a target database;
[0008] When the server cluster is started, controlling the server cluster to read the scheduled task from the target database, and storing the scheduled task in the memory of the target server in the server cluster;
[0009] Control the target server to execute the scheduled task.
[0010] In some embodiments of the present invention, when a server cluster is started, controlling the server cluster to read the scheduled task from the target database and storing the scheduled task in the memory of the target server in the server cluster includes:
[0011] When the server cluster is started, each server in the server cluster is controlled to read the scheduled task from the target database, and store the scheduled task in the memory of each server.
[0012] In some embodiments of the present invention, controlling the target server to execute the scheduled task includes:
[0013] Control each server in the server cluster to obtain a distributed lock;
[0014] Determine the server that obtains the distributed lock as the target server;
[0015] Control the target server to execute the scheduled task.
[0016] In some embodiments of the present invention, when a server cluster is started, controlling the server cluster to read the scheduled task from the target database and storing the scheduled task in the memory of the target server in the server cluster includes:
[0017] When the server cluster is started, each server in the server cluster is controlled to write the task information of the scheduled task into the target database;
[0018] Determine the server that successfully writes the task information as the target server;
[0019] The target server is controlled to read the scheduled task from the target database and store the scheduled task in the target server memory.
[0020] In some embodiments of the present invention, after controlling the target server to execute the scheduled task, the method further includes:
[0021] Delete the task information.
[0022] In some embodiments of the present invention, creating a scheduled task and storing the scheduled task in a target database includes:
[0023] Create a scheduled task, create a scheduler, configure a trigger, associate the scheduled task with the trigger through the scheduler, and store the scheduled task in a target database.
[0024] According to another aspect of the present invention, a cluster scheduled task execution device is provided, the device comprising:
[0025] A creation and storage module, used to create a scheduled task and store the scheduled task in a target database;
[0026] A control and storage module, used for controlling the server cluster to read the scheduled task from the target database and store the scheduled task in the memory of the target server in the server cluster when the server cluster is started;
[0027] The execution control module is used to control the target server to execute the scheduled task.
[0028] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0029] at least one processor; and
[0030] a memory communicatively connected to the at least one processor; wherein,
[0031] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the cluster scheduled task execution method described in any embodiment of the present invention.
[0032] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the cluster scheduled task execution method described in any embodiment of the present invention when executed.
[0033] According to another aspect of the present invention, an embodiment of the present invention further provides a computer program product, the computer program product includes a computer program, and when the computer program is executed by a processor, the cluster scheduled task execution method described in any embodiment of the present invention is implemented.
[0034] The embodiment of the present invention creates a scheduled task and stores the scheduled task in a target database. When the server cluster is started, the server cluster is controlled to read the scheduled task from the target database and store the scheduled task in the memory of the target server in the server cluster, thereby controlling the target server to execute the scheduled task. The technical solution of the present invention can solve the problem of repeated scheduling, reduce the frequency of obtaining the status of scheduled tasks from the database, and improve real-time performance.
[0035] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0037] Figure 1 is a flow chart of a cluster scheduled task execution method in an embodiment of the present invention;
[0038] Figure 2 It is a structural diagram of a cluster scheduled task execution device in an embodiment of the present invention;
[0039] Figure 3 It is a structural diagram of an electronic device for implementing the cluster scheduled task execution method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0040] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0041] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and their meanings are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0042] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.
[0043] Embodiment 1
[0044] Figure 1is a flow chart of a cluster scheduled task execution method in an embodiment of the present invention. This embodiment is applicable to the case of cluster scheduled task execution. The method can be executed by the cluster scheduled task execution device in an embodiment of the present invention. The device can be implemented in software and / or hardware. Figure 1 As shown, the method specifically comprises the following steps:
[0045] S101, creating a scheduled task, and storing the scheduled task in a target database.
[0046] It is known that a scheduled task is a task that performs an action at a predetermined time or at a fixed frequency.
[0047] In this embodiment, the target database may be a relational database, that is, a database that uses a relational model to organize data. For the convenience of subsequent introduction, the target database may be referred to as a database.
[0048] The cluster scheduled task execution method of the embodiment of the present invention adopts the Quartz framework. First, define the task content: create a custom task (Job) class, and write the execute method of the BaseJob class in the Quartz package, and write the functions to be implemented in the execute method. Then, create a scheduler Scheduler, configure the trigger Trigger, set the specific trigger time and trigger number, etc., and associate the running tasks and Trigger through the Scheduler. Quartz uses the RAMJobStore mode by default. Afterwards, when creating a new scheduled task, after defining and adding the trigger to the Scheduler, the task information is stored in the database at the same time to avoid information loss after the server is shut down.
[0049] S102: When the server cluster is started, the server cluster is controlled to read the scheduled tasks from the target database and store the scheduled tasks in the memory of the target server in the server cluster.
[0050] It can be known that a server cluster can be a group (several) independent computers that form a larger computer service system using a communication network.
[0051] In this embodiment, the target server may be a server in a server cluster that executes scheduled tasks.
[0052] Specifically, each time the application is started, all scheduled tasks are obtained from the database, and the task information is added to the memory of the target server for execution. In a server cluster, only one server (the target server) executes scheduled tasks at the same time.
[0053] In actual operation, since the scheduled task will put the information into the memory for initialization, its scheduling is also executed by directly querying the memory through the server thread, which reduces the frequency of obtaining the scheduled task status from the database, and therefore has higher real-time performance.
[0054] S103: Control the target server to execute the scheduled task.
[0055] Specifically, the target server executes the scheduled task after obtaining the scheduled task.
[0056] The embodiment of the present invention creates a scheduled task and stores the scheduled task in a target database. When the server cluster is started, the server cluster is controlled to read the scheduled task from the target database and store the scheduled task in the memory of the target server in the server cluster, thereby controlling the target server to execute the scheduled task. The technical solution of the present invention can solve the problem of repeated scheduling, reduce the frequency of obtaining the status of scheduled tasks from the database, and improve real-time performance.
[0057] Optionally, when the server cluster is started, the control server cluster reads the scheduled tasks from the target database and stores the scheduled tasks in the memory of the target server in the server cluster, including:
[0058] When the server cluster is started, each server in the control server cluster reads the scheduled tasks from the target database and stores the scheduled tasks in the memory of each server.
[0059] In actual operation, all servers in the server cluster store scheduled tasks in memory. All servers start executing scheduled tasks at the same time, but since only one server can obtain the distributed lock, only one server can successfully execute the scheduled task.
[0060] Optionally, control the target server to execute scheduled tasks, including:
[0061] Controls each server in the server cluster to obtain a distributed lock.
[0062] What we know is that a distributed lock is a cross-machine mutual exclusion mechanism that can control machine access to shared resources and ensure that only one machine owns the resources at the same time.
[0063] Specifically, when a scheduled task is executed, each server in the server cluster first obtains a distributed lock from the Redis or Zookeeper server, and then releases the lock when the task is completed. In a server cluster, only one server can obtain the lock at the same time, so it can be ensured that the task is not called up repeatedly.
[0064] The server that obtains the distributed lock is determined as the target server.
[0065] This embodiment uses the Quartz framework and stores the scheduled tasks in the memory of the server cluster machine based on the RAMJobStore mode to ensure the real-time performance of the scheduled tasks. At the same time, each server in the server cluster competes for the task execution right through the distributed lock, thereby solving the problem of repeated scheduling of cluster tasks. Specifically, the server that successfully obtains the distributed lock in the server cluster is determined as the target server.
[0066] Control the target server to execute scheduled tasks.
[0067] Specifically, an embodiment of the present invention proposes to store scheduled tasks in a database. Each time the server is started, the scheduled tasks will be read from the database and stored in the server memory based on the RAMJobStore mode. At the same time, each time the task is executed, the task execution right will be competed for by acquiring a distributed lock, so as to achieve the purpose of scheduling the task only once, and it has strong real-time performance.
[0068] Optionally, after controlling the target server to execute the scheduled task, the following is further included:
[0069] Release the distributed lock.
[0070] Specifically, the distributed lock is released after the scheduled task is completed.
[0071] Optionally, when the server cluster is started, the control server cluster reads the scheduled tasks from the target database and stores the scheduled tasks in the memory of the target server in the server cluster, including:
[0072] When the server cluster is started, each server in the control server cluster writes the task information of the scheduled task into the target database.
[0073] In this embodiment, the task information may be relevant information of a scheduled task, and this embodiment does not limit the detailed content of the task information.
[0074] In actual operations, the use of distributed locks can solve the problem of repeated task scheduling. In addition, you can create a unique index or use a primary key in the database, and use its uniqueness to achieve the same goal while using fewer resources.
[0075] Specifically, when a task is called, each server in the server cluster inserts a piece of data into the database table. This data is unique. The task information needs to be stored in the database, so a unique ID can be used to store the task information. At the same time, only one server in the server cluster can successfully add data. If the other servers fail to add data, the task scheduling will not be executed.
[0076] The server on which the task information is successfully written is determined as the target server.
[0077] This embodiment uses the Quartz framework and stores the scheduled tasks in the memory of the server cluster machine based on the RAMJobStore mode to ensure the real-time performance of the scheduled tasks. At the same time, each server in the server cluster uses the unique primary key feature of the relational database to compete for the right to execute the task, thereby solving the problem of repeated scheduling of cluster tasks. Specifically, the server that successfully writes the task information of the scheduled task into the database is regarded as the target server.
[0078] Control the target server to read the scheduled tasks from the target database and store the scheduled tasks in the target server memory.
[0079] Specifically, an embodiment of the present invention proposes to store scheduled tasks in a database. Each time the server is started, the scheduled tasks will be read from the database and stored in the server memory based on the RAMJobStore mode. At the same time, each time the task is executed, the unique characteristic of the primary key in the database is used to compete for the task execution right, so as to achieve the purpose of scheduling the task only once, and it has strong real-time performance.
[0080] Optionally, after controlling the target server to execute the scheduled task, the following is further included:
[0081] Delete task information.
[0082] Specifically, when the scheduled task is completed, the unique data is deleted to avoid affecting the next scheduling of the scheduled task.
[0083] Optionally, create a scheduled task and store it in the target database, including:
[0084] Create a scheduled task, create a scheduler, configure a trigger, associate the scheduled task with the trigger through the scheduler, and store the scheduled task in the target database.
[0085] Specifically, create a scheduler, configure the trigger, set the specific trigger time and trigger frequency, and associate the running task with the trigger through the Scheduler. Quartz uses the RAMJobStore mode by default. When creating a new scheduled task, define and add the trigger to the Scheduler, and store the task information in the database to avoid information loss after the server is shut down.
[0086] The technical solution of the embodiment of the present invention uses the RAMJobStore mode to put the task information of the scheduled task into the memory for initialization, and store the task data in the database, which solves the problem of task information loss after the application is closed in the RAMJobStore mode; at the same time, by using a distributed lock or a database unique index to determine the task execution right, the problem of repeated scheduling is solved. The embodiment of the present invention has both a task persistence mechanism and the characteristics of high scheduling efficiency, and solves the problem of repeated scheduling, combining the advantages of both Quartz modes.
[0087] Embodiment 2
[0088] Figure 2 Schematic diagram of the structure of a cluster scheduled task execution device in an embodiment of the present invention. This embodiment is applicable to the case of cluster scheduled task execution. The device can be implemented in software and / or hardware. The device can be integrated in any device that provides the function of cluster scheduled task execution, such as Figure 2 As shown, the cluster scheduled task execution device specifically includes: a creation and storage module 201, a control and storage module 202 and an execution control module 203.
[0089] The creation and storage module 201 is used to create a scheduled task and store the scheduled task in a target database;
[0090] The control and storage module 202 is used to control the server cluster to read the scheduled task from the target database and store the scheduled task in the memory of the target server in the server cluster when the server cluster is started;
[0091] The execution control module 203 is used to control the target server to execute the scheduled task.
[0092] Optionally, the control and storage module 202 is specifically used for:
[0093] When the server cluster is started, each server in the server cluster is controlled to read the scheduled task from the target database, and store the scheduled task in the memory of each server.
[0094] Optionally, the execution control module 203 is specifically used to:
[0095] Control each server in the server cluster to obtain a distributed lock;
[0096] Determine the server that obtains the distributed lock as the target server;
[0097] Control the target server to execute the scheduled task.
[0098] Optionally, the control and storage module 202 is specifically used for:
[0099] When the server cluster is started, each server in the server cluster is controlled to write the task information of the scheduled task into the target database;
[0100] Determine the server that successfully writes the task information as the target server;
[0101] The target server is controlled to read the scheduled task from the target database and store the scheduled task in the target server memory.
[0102] Optionally, the device is further specifically used for:
[0103] Delete the task information.
[0104] Optionally, the creation and storage module 201 is specifically used for:
[0105] Create a scheduled task, create a scheduler, configure a trigger, associate the scheduled task with the trigger through the scheduler, and store the scheduled task in a target database.
[0106] The above-mentioned product can execute the cluster scheduled task execution method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0107] Embodiment 3
[0108] Figure 3 A schematic diagram of the structure of an electronic device 30 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0109] like Figure 3As shown, the electronic device 30 includes at least one processor 31, and a memory connected to the at least one processor 31, such as a read-only memory (ROM) 32, a random access memory (RAM) 33, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 31 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 32 or the computer program loaded from the storage unit 38 to the random access memory (RAM) 33. In the RAM 33, various programs and data required for the operation of the electronic device 30 can also be stored. The processor 31, the ROM 32, and the RAM 33 are connected to each other through a bus 34. An input / output (I / O) interface 35 is also connected to the bus 34.
[0110] A number of components in the electronic device 30 are connected to the I / O interface 35, including: an input unit 36, such as a keyboard, a mouse, etc.; an output unit 37, such as various types of displays, speakers, etc.; a storage unit 38, such as a disk, an optical disk, etc.; and a communication unit 39, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 39 allows the electronic device 30 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0111] The processor 31 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 31 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 31 executes the various methods and processes described above, such as the cluster scheduled task execution method:
[0112] Create a scheduled task and store the scheduled task in a target database;
[0113] When the server cluster is started, controlling the server cluster to read the scheduled task from the target database, and storing the scheduled task in the memory of the target server in the server cluster;
[0114] Control the target server to execute the scheduled task.
[0115] In some embodiments, the cluster timing task execution method can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 38. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 30 via the ROM 32 and / or the communication unit 39. When the computer program is loaded into the RAM 33 and executed by the processor 31, one or more steps of the cluster timing task execution method described above can be performed. Alternatively, in other embodiments, the processor 31 can be configured to execute the cluster timing task execution method in any other appropriate manner (for example, by means of firmware).
[0116] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0117] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0118] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0119] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0120] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0121] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0122] In one embodiment, the embodiment of the present invention further includes a computer program product, the computer program product includes a computer program, and when the computer program is executed by a processor, the cluster scheduled task execution method of any embodiment of the present invention is implemented.
[0123] In the process of implementation, the computer program product can be written in one or more programming languages or a combination thereof to perform the computer program code of the present invention, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0124] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0125] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A cluster scheduled task execution method, characterized in that: include: Create a scheduled task and store the scheduled task in a target database; When the server cluster is started, controlling the server cluster to read the scheduled task from the target database, and storing the scheduled task in the memory of the target server in the server cluster; Control the target server to execute the scheduled task.
2. The method according to claim 1, characterized in that When the server cluster is started, controlling the server cluster to read the scheduled task from the target database and storing the scheduled task in the memory of the target server in the server cluster includes: When the server cluster is started, each server in the server cluster is controlled to read the scheduled task from the target database, and store the scheduled task in the memory of each server.
3. The method according to claim 2, characterized in that Controlling the target server to execute the scheduled task includes: Control each server in the server cluster to obtain a distributed lock; Determine the server that obtains the distributed lock as the target server; Control the target server to execute the scheduled task.
4. The method according to claim 1, characterized in that: When the server cluster is started, controlling the server cluster to read the scheduled task from the target database and storing the scheduled task in the memory of the target server in the server cluster includes: When the server cluster is started, each server in the server cluster is controlled to write the task information of the scheduled task into the target database; Determine the server that successfully writes the task information as the target server; The target server is controlled to read the scheduled task from the target database and store the scheduled task in the target server memory.
5. The method according to claim 4, characterized in that After controlling the target server to execute the scheduled task, the method further includes: Delete the task information.
6. The method according to claim 1, characterized in that Creating a scheduled task and storing the scheduled task in a target database includes: Create a scheduled task, create a scheduler, configure a trigger, associate the scheduled task with the trigger through the scheduler, and store the scheduled task in a target database.
7. A cluster scheduled task execution device, characterized in that: include: A creation and storage module, used to create a scheduled task and store the scheduled task in a target database; A control and storage module, used for controlling the server cluster to read the scheduled task from the target database and store the scheduled task in the memory of the target server in the server cluster when the server cluster is started; The execution control module is used to control the target server to execute the scheduled task.
8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the cluster scheduled task execution method described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the cluster scheduled task execution method according to any one of claims 1 to 6 when executed.
10. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the cluster scheduled task execution method according to any one of claims 1 to 6.