CN108710541B - Timed task execution method and device - Google Patents
Timed task execution method and device Download PDFInfo
- Publication number
- CN108710541B CN108710541B CN201810494485.2A CN201810494485A CN108710541B CN 108710541 B CN108710541 B CN 108710541B CN 201810494485 A CN201810494485 A CN 201810494485A CN 108710541 B CN108710541 B CN 108710541B
- Authority
- CN
- China
- Prior art keywords
- registration information
- timing task
- task
- timing
- locking
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/52—Program synchronisation; Mutual exclusion, e.g. by means of semaphores
- G06F9/526—Mutual exclusion algorithms
Abstract
The application discloses a method and a device for executing a timing task, which comprises the steps of inquiring registration information of the timing task according to the number of the timing task when the timing task reaches the execution time, judging whether the registration information of the timing task is in a locked state, if not, updating and locking the registration information so as to enable the registration information to be in an uneditable state for other nodes, and executing the timing task. According to the method and the device for executing the timing task, when the timing task reaches the execution time, the node firstly inquires whether the registration information of the timing task is locked, and when the registration information is locked, the other nodes begin to execute the timing task, and the timing task is not repeatedly executed; and when the timing task is not locked, the registration information is locked and the timing task is executed, so that other nodes cannot update the registration information and repeatedly execute the timing task, and the high availability of the execution of the timing task is ensured while the repeated execution of the timing task is avoided.
Description
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for executing a timing task.
Background
Timing tasks are currently widely used in many scenarios of software design. For example, account checking of a financial system requires a timing task, batch data cleaning is performed every other period requires a timing task, large-scale data archiving also requires a timing task, and the like. Ensuring a highly available and accurate execution of timed tasks is a hotspot of attention by those skilled in the art.
In order to ensure high availability of the timing task, a cluster environment is often adopted in practical situations to solve the problem of high availability of the timing task. In a cluster environment, in order to avoid a situation that multiple nodes execute a timing task at the same time, which results in multiple-side execution of the same task, it is a common practice to deploy a timing task on one server node. Thus, although the problem that a plurality of server nodes repeatedly execute a certain fixed timing task is avoided, the problem that the execution availability of the timing task is not high still exists, for example, once the server node for deploying the timing task fails, the timing task cannot be normally executed.
Disclosure of Invention
In view of this, the present invention provides a method and an apparatus for executing a timing task, so as to achieve high availability of the timing task in a cluster environment and avoid repeated execution of the timing task.
In order to achieve the purpose, the invention provides the following technical scheme:
a method for executing a timing task, which is applied to any one node in a cluster environment, comprises the following steps:
when the timing task reaches the execution time, inquiring the registration information of the timing task according to the number of the timing task;
judging whether the registration information of the timing task is in a locked state;
if not, updating and locking the registration information to enable the registration information to be in a non-editable state for other nodes;
and executing the timing task.
Optionally, before querying the registration information of the timing task according to the code of the timing task, the method further includes:
registration information for each timed task is determined and stored.
Optionally, the updating and locking the registration information to make it in an uneditable state for other nodes includes:
and updating the version number and the execution time information in the registration information, and locking the registration information to enable the registration information to be in a non-editable state for other nodes.
Optionally, after the executing the timing task is completed, the method further includes:
and updating the task execution result information in the registration information, and unlocking the updated registration information.
Optionally, the registration information is stored in a relational database or a non-relational database.
Optionally, before determining whether the registration information of the timing task is in the locked state, the method further includes:
judging whether the timing task exceeds a task execution window period or not according to the last execution time of the task in the registration information;
and if so, entering the step of updating and locking the registration information so as to enable the registration information to be in a non-editable state for other nodes.
Optionally, after the registration information of the timing task is in the locked state, the method further includes:
judging whether the timing task exceeds the clock error window period or not according to the last execution time of the task in the registration information;
and if so, entering the step of updating and locking the registration information so as to enable the registration information to be in a non-editable state for other nodes.
An apparatus for executing a timed task, applied to any one node in a cluster environment, includes:
the information query module is used for querying the registration information of the timing task according to the number of the timing task when the timing task reaches the execution time;
the locking judging module is used for judging whether the registration information of the timing task is in a locking state;
the locking updating module is used for updating and locking the registration information when the judgment result of the locking judging module is negative so as to enable the registration information to be in a non-editable state for other nodes;
and the task execution module is used for executing the timing task.
A computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements a method of performing any of the above-described timed tasks.
An electronic device, comprising:
a processor; and
a memory for storing executable instructions of the processor;
wherein the processor is configured to perform the method of performing the timed task of any of the above via execution of the executable instructions.
Compared with the prior art, the embodiment of the invention discloses a method and a device for executing a timing task, and the method and the device comprise the steps of inquiring the registration information of the timing task according to the number of the timing task when the timing task reaches the execution time, judging whether the registration information of the timing task is in a locked state, and if not, updating and locking the registration information to enable the registration information to be in an uneditable state for other nodes and executing the timing task. According to the method and the device for executing the timing task, when the timing task reaches the execution time, the node firstly inquires whether the registration information of the timing task is locked, and when the registration information is locked, the other nodes begin to execute the timing task, and the timing task is not repeatedly executed; and when the timing task is not locked, the registration information is locked and the timing task is executed, so that other nodes cannot update the registration information and repeatedly execute the timing task, and the high availability of the execution of the timing task is ensured while the repeated execution of the timing task is avoided.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
FIG. 1 is a flowchart illustrating a method for executing a timing task according to an embodiment of the present invention;
FIG. 2 is a flow chart of another method for executing a timing task according to an embodiment of the present invention;
FIG. 3 is a flowchart of another method for executing a timing task according to an embodiment of the present disclosure;
FIG. 4 is a schematic structural diagram of an apparatus for executing a timing task according to an embodiment of the present invention;
FIG. 5 is a schematic structural diagram of another apparatus for executing a timing task according to an embodiment of the present disclosure;
fig. 6 is a schematic structural diagram of another timing task execution device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a flowchart of a method for executing a timing task according to an embodiment of the present invention, and as shown in fig. 1, the method may include:
step 101: and when the timing task reaches the execution time, inquiring the registration information of the timing task according to the number of the timing task.
In this embodiment, the method for executing the timing task may be applied to any node in the cluster environment. When the system has registered the existing timing task to reach the execution time, the current node can inquire the registration information of the timing task according to the number of the timing task. The number of the timing task may be service module identification, timing task ID, and other identification information capable of uniquely determining a certain timing task.
The registration information may include, but is not limited to, a service module type, a lock flag, a version number, a task last execution time, an IP address of a server node that executes a task, a task execution condition, and the like. The registration information may be stored in a third party storage medium, such as a relational or non-relational database.
Step 102: and judging whether the registration information of the timing task is in a locked state, if not, entering the step 103.
After the registration information of the timing task is found, whether the registration information of the timing task is locked by other server nodes is judged firstly. If the current server node is in the locked state, the other server nodes already execute the timing task, and the current server node does not repeatedly execute the timing task and does not do any operation. If the registration information is not in the locked state, which indicates that other server nodes have not executed the timing task, the current server node may lock the registration information of the timing task and start to execute the timing task, as described in step 103 below.
Step 103: and updating and locking the registration information so as to enable the registration information to be in a non-editable state for other nodes.
Determining that a current server node can execute the timed task if the registration information of the timed task is not locked. Before executing the timing task, all server nodes in the cluster need to query and judge whether the registration information of the timing task is locked, so that before executing the timing task, the current server node needs to update the information which can be updated in the registration information, such as the last time of executing the task, the IP address of the server node executing the task, and the like, and meanwhile, the locking mark can be changed into a locking state, so that the phenomenon that other server nodes update the registration information and execute the timing task to cause repeated execution of the timing task on different server nodes is avoided.
Step 104: and executing the timing task.
After locking the registration information of the timing task, the current node may execute the timing task. The timing task may be executed quickly according to the work content of the timing task itself, or may be executed after a period of time. The execution time of the timing task is related to the work content contained in the task of the timing task, the self attribute of the node executing the timing task and the running condition.
In this embodiment, when the timed task reaches the execution time, the node first queries whether the registration information of the timed task is locked, and when the registration information is locked, it indicates that other nodes have already started executing the timed task, and the timed task is not repeatedly executed; and when the timing task is not locked, the registration information is locked and the timing task is executed, so that other nodes cannot update the registration information and repeatedly execute the timing task, and the high availability of the execution of the timing task is ensured while the repeated execution of the timing task is avoided.
On the basis of the above embodiment disclosed by the present invention, fig. 2 discloses a flowchart of another method for executing a timing task, and referring to fig. 2, the method may include:
step 201: registration information for each timed task is determined and stored.
The registration information of each timing task is predetermined and stored, so that the server node can search and lock the registration information of the timing task and then execute the timing task when the timing task needs to be executed subsequently. And avoiding other server nodes from repeatedly executing the timing task.
Step 202: and when the timing task reaches the execution time, inquiring the registration information of the timing task according to the number of the timing task.
Step 203: and judging whether the registration information of the timing task is in a locked state, if not, entering the step 204.
Step 204: and updating the version number and the execution time information in the registration information, and locking the registration information to enable the registration information to be in a non-editable state for other nodes.
In this implementation, the version number in the registration information may be used to implement an optimistic lock mechanism. When the locking state of the registration information of the timing task is inquired according to the code of the timing task, the version number in the registration information is checked out at the same time, and the registration information of the timing task needs to be used as a judgment condition according to the version number when being locked. If the version number is the same as the version number in the query, that is, if the version number is not changed, it indicates that no other server node updates the registration information, the registration information of the timing task may be locked, the other server node is not allowed to execute the corresponding timing task, and 1 is added to the version number, so as to prompt that the server node already executes the timing task when the other server node queries the registration information of the timing task. Specifically, information such as the last execution time and the locking state of the task is updated according to the version number, and the version number is added by 1, so that other server nodes are prevented from taking over the timing task at the same time. The last execution time of the task may be a start time of executing the timing task this time.
Step 205: and executing the timing task.
Step 206: and updating the task execution result information in the registration information, and unlocking the updated registration information.
After the timing task is executed, the execution result information may be updated to the registration information, and the execution result information may be selected as success or failure. Meanwhile, the updated registration information, that is, the new version of registration information needs to be unlocked, so that the server node can lock the new registration information and execute the timing task of the next period when the timing task needs to be executed next time.
In this embodiment, the method for executing the timing task determines and stores the registration information of each timing task, so that the server node can search the corresponding registration information according to the serial number of the timing task when the subsequent task reaches the execution time. After the timing task is executed, updating task execution result information in the registration information, and unlocking the updated registration information, so that the server node can lock new registration information and execute the timing task in the next period when the timing task needs to be executed in the next period.
Fig. 3 is a flowchart of a method for executing a timing task according to another embodiment of the present invention, and as shown in fig. 3, the method may include:
step 301: and when the timing task reaches the execution time, inquiring the registration information of the timing task according to the number of the timing task.
Step 302: judging whether the timed task exceeds the task execution window period or not according to the last execution time of the task in the registration information, if not, entering step 303; if so, step 305 is entered.
Wherein the task execution window period is typically set to be much larger than the execution time of the timed task. For example, if the execution time of the timing task is about 10 minutes, and the execution period of the timing task is once a day, the task execution window period may be set to 5 hours, 10 hours, or the like. The method and the device can avoid the situation that the registration information of the timing task is not unlocked all the time, other server nodes cannot update the registration information and cannot execute the timing task due to sudden failure or accident of a certain server node in the process of executing the timing task.
Step 303: and judging whether the registration information of the timing task is in a locked state, if not, entering a step 304.
Step 304: and judging whether the timing task exceeds the clock error window period or not according to the task last execution time in the registration information, and if so, entering the step 305.
In the cluster environment, the number of server nodes is large, and a clock difference exists between different server nodes, in this case, if the execution time of the timing task is short, only 30 seconds, a first server node has already executed the timing task and has already unlocked the registration information of the timing task, and a second server node is 1 minute later than the clock of the first server node, after the first server node has executed the timing task, the second server node may execute the timing task again according to its own time, which causes repeated execution of the timing task. In order to avoid this, in this implementation, a clock error window period is configured, and the duration of the clock error window period may be determined according to the clock error ranges of all server nodes in the cluster and the execution duration of the timing task. If the execution time of the timing task is about 15 seconds, and the clock error range of all the server nodes in the cluster is less than 1 minute, the clock error window period may be set to 1 minute.
And when the registration information of the timing task is not locked and the timing task is determined not to exceed the clock error window period according to the last execution time of the task in the registration information, the timing task is executed in the current period and is not repeatedly executed.
Step 305: and updating and locking the registration information so as to enable the registration information to be in a non-editable state for other nodes.
When the registration information of the timing task is not locked and the timing task is determined to exceed the clock error window period according to the last execution time of the task in the registration information, the timing task is not executed in the current period, the registration information can be updated and locked, and the timing task is executed.
Step 306: and executing the timing task.
Step 307: and updating the task execution result information in the registration information, and unlocking the updated registration information.
In the embodiment, the step of judging whether the timed task exceeds the task execution window period is added, so that the condition that the subsequent normal execution of the timed task is influenced because the node which executes the timed task last time fails in the execution process and the registration information of the timed task is not unlocked for a long time is avoided. The step of judging whether the timing task exceeds the clock error window period is added, so that the repeated execution of the timing task by different server nodes in one execution period of the timing task is avoided.
While, for purposes of simplicity of explanation, the foregoing method embodiments have been described as a series of acts or combination of acts, it will be appreciated by those skilled in the art that the present invention is not limited by the illustrated ordering of acts, as some steps may occur in other orders or concurrently with other steps in accordance with the invention. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required by the invention.
The method is described in detail in the embodiments disclosed above, and the method of the present invention can be implemented by various types of apparatuses, so that the present invention also discloses an apparatus, and the following detailed description will be given of specific embodiments.
Fig. 4 is a schematic structural diagram of an execution device of a timing task according to an embodiment of the present invention, and referring to fig. 4, the execution device 40 of the timing task may include:
and the information query module 401 is configured to query the registration information of the timing task according to the number of the timing task when the timing task reaches the execution time.
In this embodiment, the method for executing the timing task may be applied to any node in the cluster environment. When the system has registered the existing timing task to reach the execution time, the current node can inquire the registration information of the timing task according to the number of the timing task. The number of the timing task may be service module identification, timing task ID, and other identification information capable of uniquely determining a certain timing task.
The registration information may include, but is not limited to, a service module type, a lock flag, a version number, a task last execution time, an IP address of a server node that executes a task, a task execution condition, and the like. The registration information may be stored in a third party storage medium, such as a relational or non-relational database.
A locking determining module 402, configured to determine whether the registration information of the timing task is in a locked state.
After the registration information of the timing task is found, whether the registration information of the timing task is locked by other server nodes is judged firstly. If the current server node is in the locked state, the other server nodes already execute the timing task, and the current server node does not repeatedly execute the timing task and does not do any operation. And if the registration information is not in the locking state, indicating that other server nodes do not execute the timing task.
A locking updating module 403, configured to update and lock the registration information to make it in a non-editable state for another node when the determination result of the locking determining module 402 is negative.
Determining that a current server node can execute the timed task if the registration information of the timed task is not locked. Before executing the timing task, all server nodes in the cluster need to query and judge whether the registration information of the timing task is locked, so that before executing the timing task, the current server node needs to update the information which can be updated in the registration information, such as the last time of executing the task, the IP address of the server node executing the task, and the like, and meanwhile, the locking mark can be changed into a locking state, so that the phenomenon that other server nodes update the registration information and execute the timing task to cause repeated execution of the timing task on different server nodes is avoided.
A task executing module 404, configured to execute the timing task.
After locking the registration information of the timing task, the current node may execute the timing task. The timing task may be executed quickly according to the work content of the timing task itself, or may be executed after a period of time. The execution time of the timing task is related to the work content contained in the task of the timing task, the self attribute of the node executing the timing task and the running condition.
In this embodiment, when the timing task reaches the execution time, the node first queries whether the registration information of the timing task is locked, and when the registration information is locked, it indicates that other nodes have already started executing the timing task, and the timing task is not repeatedly executed; and when the timing task is not locked, the registration information is locked and the timing task is executed, so that other nodes cannot update the registration information and repeatedly execute the timing task, and the high availability of the execution of the timing task is ensured while the repeated execution of the timing task is avoided.
On the basis of the above embodiment disclosed by the present invention, fig. 5 discloses a schematic structural diagram of another timing task execution device, and referring to fig. 5, the timing task execution device 50 may include:
and a registration information storage module 501, configured to determine and store registration information of each timing task.
The registration information of each timing task is predetermined and stored, so that the server node can search and lock the registration information of the timing task and then execute the timing task when the timing task needs to be executed subsequently. And avoiding other server nodes from repeatedly executing the timing task.
And the information query module 401 is configured to query the registration information of the timing task according to the number of the timing task when the timing task reaches the execution time.
A locking determining module 402, configured to determine whether the registration information of the timing task is in a locked state.
A locking updating module 403, configured to update the version number and the execution time information in the registration information and lock the registration information so that the registration information is in an uneditable state with respect to other nodes when the determination result of the locking determining module 403 is negative.
In this implementation, the version number in the registration information may be used to implement an optimistic lock mechanism. When the locking state of the registration information of the timing task is inquired according to the code of the timing task, the version number in the registration information is checked out at the same time, and the registration information of the timing task needs to be used as a judgment condition according to the version number when being locked. If the version number is the same as the version number in the query, that is, if the version number is not changed, it indicates that no other server node updates the registration information, the registration information of the timing task may be locked, the other server node is not allowed to execute the corresponding timing task, and 1 is added to the version number, so as to prompt that the server node already executes the timing task when the other server node queries the registration information of the timing task. Specifically, information such as the last execution time and the locking state of the task is updated according to the version number, and the version number is added by 1, so that other server nodes are prevented from taking over the timing task at the same time.
A task executing module 404, configured to execute the timing task.
And an update unlocking module 502, configured to update task execution result information in the registration information, and unlock the updated registration information.
After the timing task is executed, the execution result information may be updated to the registration information, and the execution result information may be selected as success or failure. Meanwhile, the updated registration information, that is, the new version of registration information needs to be unlocked, so that the server node can lock the new registration information and execute the timing task of the next period when the timing task needs to be executed next time.
In this embodiment, the execution device of the timing task determines and stores the registration information of each timing task, so that the server node can search the corresponding registration information according to the serial number of the timing task when the subsequent task reaches the execution time. After the timing task is executed, updating task execution result information in the registration information, and unlocking the updated registration information, so that the server node can lock new registration information and execute the timing task in the next period when the timing task needs to be executed in the next period.
Fig. 6 is a schematic structural diagram of another timing task execution device according to an embodiment of the present invention, and as shown in fig. 6, the timing task execution device 60 may include:
and the information query module 401 is configured to query the registration information of the timing task according to the number of the timing task when the timing task reaches the execution time.
The first window period determining module 601 is configured to determine whether the timed task exceeds the task execution window period according to the last execution time of the task in the registration information.
Wherein the task execution window period is typically set to be much larger than the execution time of the timed task. For example, if the execution time of the timing task is about 10 minutes, and the execution period of the timing task is once a day, the task execution window period may be set to 5 hours, 10 hours, or the like. The method and the device can avoid the situation that the registration information of the timing task is not unlocked all the time, other server nodes cannot update the registration information and cannot execute the timing task due to sudden failure or accident of a certain server node in the process of executing the timing task.
A locking determining module 402, configured to determine whether the registration information of the timing task is in a locked state when the determination result of the first window period determining module 601 is negative.
A second window period determining module 602, configured to determine, when the determination result of the locking determining module 402 is negative, whether the timed task has exceeded the clock error window period according to the last execution time of the task in the registration information.
In the cluster environment, the number of server nodes is large, and a clock difference exists between different server nodes, in this case, if the execution time of the timing task is short, only 30 seconds, a first server node has already executed the timing task and has already unlocked the registration information of the timing task, and a second server node is 1 minute later than the clock of the first server node, after the first server node has executed the timing task, the second server node may execute the timing task again according to its own time, which causes repeated execution of the timing task. In order to avoid this, in this implementation, a clock error window period is configured, and the duration of the clock error window period may be determined according to the clock error ranges of all server nodes in the cluster and the execution duration of the timing task. If the execution time of the timing task is about 15 seconds, and the clock error range of all the server nodes in the cluster is less than 1 minute, the clock error window period may be set to 1 minute.
And when the registration information of the timing task is not locked and the timing task is determined not to exceed the clock error window period according to the last execution time of the task in the registration information, the timing task is executed in the current period and is not repeatedly executed.
A locking updating module 403, configured to update and lock the registration information to enable the registration information to be in an uneditable state for other nodes when the determination result of the first window period determining module 601 is yes or the determination result of the second window period determining module 602 is yes.
A task executing module 404, configured to execute the timing task.
And an update unlocking module 502, configured to update task execution result information in the registration information, and unlock the updated registration information.
In the embodiment, a function module for judging whether the timed task exceeds the task execution window period is added, so that the condition that the follow-up normal execution of the timed task is influenced because the node executing the timed task last time fails in the execution process and the registration information of the timed task is not unlocked for a long time is avoided. The function module for judging whether the timing task exceeds the clock error window period is added, so that the repeated execution of the timing task by different server nodes in one execution period of the timing task is avoided.
The execution device of any one of the timing tasks in the above embodiments includes a processor and a memory, where the information query module, the lock determination module, the lock update module, the task execution module, the registration information storage module, the update unlock module, the first window period determination module, the second window period determination module, and the like in the above embodiments are all stored in the memory as program modules, and the processor executes the program modules stored in the memory to implement corresponding functions.
The processor comprises a kernel, and the kernel calls the corresponding program module from the memory. The kernel can be provided with one or more, and the processing of the return visit data is realized by adjusting the kernel parameters.
The memory may include volatile memory in a computer readable medium, Random Access Memory (RAM) and/or nonvolatile memory such as Read Only Memory (ROM) or flash memory (flash RAM), and the memory includes at least one memory chip.
An embodiment of the present invention provides a storage medium on which a program is stored, which, when executed by a processor, implements the execution method of the timing task described in the above embodiments.
The embodiment of the invention provides a processor, which is used for running a program, wherein the program executes the execution method of the timing task in the embodiment when running.
Further, the present embodiment provides an electronic device, which includes a processor and a memory. Wherein the memory is used for storing executable instructions of the processor, and the processor is configured to execute the execution method of the timing task in the above embodiment by executing the executable instructions.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
It is further noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims (8)
1. A method for executing a timing task, applied to any one node in a cluster environment, is characterized by comprising:
when the timing task reaches the execution time, inquiring the registration information of the timing task according to the number of the timing task;
judging whether the registration information of the timing task is in a locked state;
if not, updating and locking the registration information to enable the registration information to be in a non-editable state for other nodes;
executing the timing task;
before querying the registration information of the timing task according to the code of the timing task, the method further comprises the following steps:
determining and storing the registration information of each timing task;
the updating and locking the registration information to enable the registration information to be in a non-editable state for other nodes comprises the following steps:
updating the version number and the execution time information in the registration information, and locking the registration information to enable the registration information to be in an uneditable state relative to other nodes;
when inquiring the registration information of the timing task according to the code of the timing task, checking out the version number in the registration information, when locking the registration information of the timing task, taking the version number as a judgment condition, if the version number is the same as the version number when inquiring, determining that no other server node updates the registration information, locking the registration information of the timing task, and adding 1 to the version number so as to prompt that the server node executes the timing task when the other server node inquires the registration information of the timing task.
2. The method for executing the timed task according to claim 1, after the execution of the timed task is completed, further comprising:
and updating the task execution result information in the registration information, and unlocking the updated registration information.
3. The method of claim 1, wherein the registration information is stored in a relational database or a non-relational database.
4. The method for executing the timed task according to any one of claims 1 to 2, before determining whether the registration information of the timed task is in the locked state, further comprising:
judging whether the timing task exceeds a task execution window period or not according to the last execution time of the task in the registration information;
and if so, entering the step of updating and locking the registration information so as to enable the registration information to be in a non-editable state for other nodes.
5. The method for executing the timed task according to any one of claims 1 to 2, wherein after the registration information of the timed task is in the locked state, the method further comprises:
judging whether the timing task exceeds the clock error window period or not according to the last execution time of the task in the registration information;
and if so, entering the step of updating and locking the registration information so as to enable the registration information to be in a non-editable state for other nodes.
6. An apparatus for executing a timed task, applied to any one node in a cluster environment, comprising:
the information query module is used for querying the registration information of the timing task according to the number of the timing task when the timing task reaches the execution time;
the locking judging module is used for judging whether the registration information of the timing task is in a locking state;
the locking updating module is used for updating and locking the registration information when the judgment result of the locking judging module is negative so as to enable the registration information to be in a non-editable state for other nodes;
the task execution module is used for executing the timing task;
further comprising:
determining and storing the registration information of each timing task;
the updating and locking the registration information to enable the registration information to be in a non-editable state for other nodes comprises the following steps:
updating the version number and the execution time information in the registration information, and locking the registration information to enable the registration information to be in an uneditable state relative to other nodes;
when inquiring the registration information of the timing task according to the code of the timing task, checking out the version number in the registration information, when locking the registration information of the timing task, taking the version number as a judgment condition, if the version number is the same as the version number when inquiring, determining that no other server node updates the registration information, locking the registration information of the timing task, and adding 1 to the version number so as to prompt that the server node executes the timing task when the other server node inquires the registration information of the timing task.
7. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out a method of performing a timed task according to any one of claims 1 to 5.
8. An electronic device, comprising:
a processor; and
a memory for storing executable instructions of the processor;
wherein the processor is configured to execute the execution method of the timed task according to any one of claims 1 to 5 via execution of the executable instructions.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810494485.2A CN108710541B (en) | 2018-05-22 | 2018-05-22 | Timed task execution method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810494485.2A CN108710541B (en) | 2018-05-22 | 2018-05-22 | Timed task execution method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108710541A CN108710541A (en) | 2018-10-26 |
CN108710541B true CN108710541B (en) | 2022-02-01 |
Family
ID=63869402
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810494485.2A Active CN108710541B (en) | 2018-05-22 | 2018-05-22 | Timed task execution method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108710541B (en) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109714411A (en) * | 2018-12-25 | 2019-05-03 | 浪潮电子信息产业股份有限公司 | The task timing of springboot micro services frame executes method, apparatus, equipment and medium |
CN110196765A (en) * | 2019-05-30 | 2019-09-03 | 苏州浪潮智能科技有限公司 | Timed task processing method, device, equipment and computer readable storage medium |
CN110515714A (en) * | 2019-08-15 | 2019-11-29 | 浙江万朋教育科技股份有限公司 | A kind of task balance dispatching method based on group system |
CN111459951A (en) * | 2020-02-25 | 2020-07-28 | 深圳联友科技有限公司 | Method and device for supporting cluster through timing task |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103744724A (en) * | 2014-02-19 | 2014-04-23 | 互联网域名系统北京市工程研究中心有限公司 | Timed task clustering method and device thereof |
CN103761148A (en) * | 2014-01-26 | 2014-04-30 | 北京京东尚科信息技术有限公司 | Control method for cluster timing scheduling tasks |
CN106095585A (en) * | 2016-06-22 | 2016-11-09 | 中国建设银行股份有限公司 | Task requests processing method, device and enterprise information system |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US10579413B2 (en) * | 2013-08-14 | 2020-03-03 | International Business Machines Corporation | Efficient task scheduling using a locking mechanism |
CN105700943A (en) * | 2015-12-31 | 2016-06-22 | 上海百事通信息技术股份有限公司 | Distributed task scheduling method and system |
CN106991002B (en) * | 2017-02-08 | 2021-01-29 | 阿里巴巴(中国)有限公司 | Method and equipment for realizing task scheduling management |
-
2018
- 2018-05-22 CN CN201810494485.2A patent/CN108710541B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103761148A (en) * | 2014-01-26 | 2014-04-30 | 北京京东尚科信息技术有限公司 | Control method for cluster timing scheduling tasks |
CN103744724A (en) * | 2014-02-19 | 2014-04-23 | 互联网域名系统北京市工程研究中心有限公司 | Timed task clustering method and device thereof |
CN106095585A (en) * | 2016-06-22 | 2016-11-09 | 中国建设银行股份有限公司 | Task requests processing method, device and enterprise information system |
Also Published As
Publication number | Publication date |
---|---|
CN108710541A (en) | 2018-10-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108710541B (en) | Timed task execution method and device | |
CN109032824B (en) | Database verification method, database verification device, computer equipment and storage medium | |
CN109828847B (en) | Block chain-based lock processing method, device, computer equipment and storage medium | |
CN106598992B (en) | Database operation method and device | |
CN108491252B (en) | Distributed transaction processing method and distributed system | |
CN110334126B (en) | Timing task processing method and device based on Spring MVC and computer equipment | |
CN112613993B (en) | Transaction data processing method and device, computer equipment and storage medium | |
CN111464487B (en) | Access control method, device and system | |
CN107819556B (en) | Service state switching method and device | |
CN110727724A (en) | Data extraction method and device, computer equipment and storage medium | |
US8347285B2 (en) | Embedded agent for self-healing software | |
CN112948504B (en) | Data acquisition method and device, computer equipment and storage medium | |
CN112069223B (en) | Data acquisition demand processing method and device, computer equipment and storage medium | |
CN111125721B (en) | Control method for starting process, computer equipment and readable storage medium | |
CN110543465B (en) | Directory operation method and device, computer equipment and storage medium | |
CN110955460A (en) | Service process starting method and device, electronic equipment and storage medium | |
CN110362554B (en) | Method, device, equipment and computer readable storage medium for setting timer | |
CN116010441A (en) | Data query method, device and storage medium | |
JP6658301B2 (en) | Application support program, application support device, and application support method | |
CN112583761B (en) | Management method and device of security entity, computer equipment and storage medium | |
CN113704277A (en) | Database-based breakpoint continuous transmission method and related device | |
CN111949363A (en) | Service access management method, computer equipment, storage medium and system | |
CN111158701B (en) | Library module issuing method, device, equipment and storage medium | |
CN109472681B (en) | Enterprise batch payment method and device | |
CN115277232B (en) | Security policy recycling method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |