Timed task execution method and device, computer equipment and readable storage medium

By managing the creation and execution of timing tasks between the task configuration thread and the task execution thread, the problem of excessive resource consumption caused by a large number of software timers is solved, and efficient resource utilization and accurate execution of timing tasks are achieved.

CN119597411APending Publication Date: 2025-03-11CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202411235043.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-04
Publication Date
2025-03-11

AI Technical Summary

Technical Problem

When there are a large number of software timers in the device, the creation, maintenance and destruction of each software timer requires a large amount of CPU and memory resources, resulting in excessive resource consumption.

Method used

The task configuration thread through the timer generates different timing tasks based on the task description information, and processes these timing tasks in turn through the task execution thread. This method avoids frequent creation and destruction of threads and reduces resource consumption.

Benefits of technology

It realizes that without setting multiple software timers, configuring diverse timing tasks according to needs, reducing resource consumption and ensuring the accuracy and efficiency of timing tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597411A_ABST
    Figure CN119597411A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of software, in particular to a timed task execution method and device, computer equipment and a readable storage medium. The method comprises the following steps: generating different timed tasks according to received different task description information through a task configuration thread of a timer; and processing the different timed tasks generated by the task configuration thread in sequence through the task execution thread of the timer.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software technology, and in particular to a method, device, computer equipment and readable storage medium for executing a scheduled task. Background Art

[0002] A software timer is a tool commonly used in computer programs to execute certain tasks or codes at predetermined time intervals or specific points in time. Unlike hardware timers, software timers are implemented and managed by software, usually based on the time management functions provided by the operating system or application.

[0003] In some specific scenarios, you need to set multiple software timers to meet the different needs of the application. For example, if the tasks in the application have specific requirements for resource usage, you may need to use software timers to manage the allocation and release of resources. That is, an application may need to execute some resource-intensive tasks during off-peak hours and reduce the execution frequency of these tasks during peak hours. By setting multiple software timers, you can dynamically adjust the execution of tasks based on resource usage.

[0004] However, when there are a large number of software timers in a device, the creation, maintenance, and destruction of each software timer consumes CPU and memory resources, and consumes a large amount of device resources, so improvement is urgently needed. Summary of the invention

[0005] Based on this, it is necessary to provide a scheduled task execution method, device, computer equipment and readable storage medium that can reduce resource consumption in response to the above technical problems.

[0006] In a first aspect, the present application provides a method for executing a scheduled task, comprising:

[0007] Through the task configuration thread of the timer, different scheduled tasks are generated according to the different task description information received;

[0008] Through the timer's task execution thread, different scheduled tasks generated by the task configuration thread are processed in turn.

[0009] In one embodiment, different scheduled tasks are generated according to different task description information received, including:

[0010] For each received task description information, a task object corresponding to the task description information is constructed in the task storage container through a task adding function;

[0011] According to the execution description information corresponding to different task objects, verify whether there is an execution conflict between different task objects;

[0012] If it does not exist, different scheduled tasks will be generated according to different task objects.

[0013] In one embodiment, the task execution thread of the timer sequentially processes different scheduled tasks generated by the task configuration thread, including:

[0014] Through the task configuration thread, according to the thread state of the task execution thread and the execution order between different scheduled tasks, the task execution instructions for different scheduled tasks are sent to the task execution thread in sequence;

[0015] Through the task execution thread, the corresponding scheduled tasks are processed according to the task execution instructions.

[0016] In one embodiment, processing the corresponding scheduled task according to the task execution instruction includes:

[0017] Extract the frequency division coefficient corresponding to the corresponding timed task from the task execution instruction;

[0018] Control the timer to start timing;

[0019] When the timing count value of the timer is greater than or equal to the frequency division coefficient, the corresponding timing task is executed.

[0020] In one of the embodiments, the timer is configured with a counting period; the frequency division coefficient is determined according to the timing duration and the counting period corresponding to the corresponding timing task.

[0021] In one embodiment, after executing the corresponding scheduled task, the method further includes:

[0022] According to the task execution instruction, when it is determined that the corresponding timed task is a periodic task, the timer count value is set to 0, and the operation of executing the control timer to start timing is returned.

[0023] In one embodiment, according to the thread state of the task execution thread and the execution order between different scheduled tasks, sending task execution instructions for different scheduled tasks to the task execution thread in sequence includes:

[0024] When the thread state of the task execution thread is in the ready state, task execution instructions for different scheduled tasks are sent to the task execution thread in sequence according to the execution order between different scheduled tasks.

[0025] In one embodiment, the method further comprises:

[0026] When the task configuration thread is in a congested state and the task execution thread is in a ready state, the thread state of the task execution thread is updated to a waiting indication state.

[0027] In a second aspect, the present application also provides a timed task execution device, comprising:

[0028] A task configuration module is used to generate different scheduled tasks according to different task description information received through the task configuration thread of the timer;

[0029] The task execution module is used to process different scheduled tasks generated by the task configuration thread in sequence through the task execution thread of the timer.

[0030] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:

[0031] Through the task configuration thread of the timer, different scheduled tasks are generated according to the different task description information received;

[0032] Through the timer's task execution thread, different scheduled tasks generated by the task configuration thread are processed in turn.

[0033] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the following steps are implemented:

[0034] Through the task configuration thread of the timer, different scheduled tasks are generated according to the different task description information received;

[0035] Through the timer's task execution thread, different scheduled tasks generated by the task configuration thread are processed in turn.

[0036] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:

[0037] Through the task configuration thread of the timer, different scheduled tasks are generated according to the different task description information received;

[0038] Through the timer's task execution thread, different scheduled tasks generated by the task configuration thread are processed in turn.

[0039] The above-mentioned scheduled task execution method, device, computer equipment and readable storage medium, the task configuration thread of the timer in the present application can generate different scheduled tasks according to different task description information, and can configure diversified scheduled tasks according to needs without setting multiple software timers, which reduces resource consumption compared with traditional technologies; in addition, the task execution thread of the timer is used to execute different scheduled tasks generated by the task configuration thread. By managing scheduled tasks through the task execution thread, frequent creation and destruction of threads can be avoided, further reducing resource consumption; and the task configuration thread is not affected by the task execution thread, and is only responsible for timing triggering, which can realize millisecond-level precision timing function, while ensuring the timing accuracy when managing scheduled tasks through multiple threads. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0041] Figure 1 An application environment diagram of a scheduled task execution method in an embodiment;

[0042] Figure 2 A schematic diagram of a flow chart of a method for executing a scheduled task in an embodiment;

[0043] Figure 3 A schematic diagram of a flow chart for generating different timing task steps in an embodiment;

[0044] Figure 4 A flowchart of the steps of sequentially processing different scheduled tasks generated by the task configuration thread in one embodiment;

[0045] Figure 5 A schematic diagram of the interaction between a task configuration thread and a task execution thread in one embodiment;

[0046] Figure 6 It is a flowchart of processing steps of corresponding scheduled tasks according to task execution instructions in another embodiment;

[0047] Figure 7 It is a structural block diagram of a timing task execution device in one embodiment;

[0048] Figure 8 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0050] The main function of a software timer is to create a timer in a program so that a specific operation can be triggered at a certain point in the future. This mechanism is very useful for applications that need to execute tasks periodically or with delay. For example, to execute certain repetitive operations at fixed time intervals, such as timed data collection, timed sending of heartbeat packets, etc.; or to execute certain operations after a period of time instead of immediately, the software timer can set a delay time to execute the task after the specified delay time, such as delaying the loading of resources, delaying the processing of user input, etc.

[0051] However, when there are a large number of software timers in the system, the creation, maintenance and destruction of special software timers require the consumption of CPU and memory resources, and consume a lot of device resources, so improvement is urgently needed.

[0052] like Figure 1 As shown, this embodiment provides an application environment diagram of a scheduled task execution method, including a computer device 104 and a terminal 102. The computer device 104 and the terminal 102 communicate through a network. The user sends task description information through the terminal 102, and the computer device 104 receives the scheduled description information and executes the scheduled task.

[0053] In an exemplary embodiment, Figure 2 As shown, a timed task execution method is provided, which is applied to Figure 1 The computer device 104 in the example is used as an example to illustrate, including the following S201 and S202. Among them:

[0054] S201, generating different scheduled tasks according to different task description information received through the task configuration thread of the timer.

[0055] Among them, the task configuration thread of the timer is used to manage the creation, deletion and update of the timed tasks in the timer. In this embodiment, the task execution thread of the timer is also created, and the task execution thread is used to execute different timed tasks. During the execution process, different timed tasks can correspond to execution time and priority.

[0056] Specifically, the task description information of the timer may include a task identifier, a task type, a timing duration, a task entity (ie, a task function), and a task execution order.

[0057] It can be understood that 1) the task ID is used to distinguish different scheduled tasks. It can be a number, a string, or any identifier that can ensure uniqueness. The task ID is assigned when the task is created and remains unchanged throughout the task life cycle. 2) The task type specifies the type of task, such as a periodically executed task or a task that is executed after a certain delay. It determines the behavior mode and execution logic of the task. 3) Scheduled duration: For delayed tasks, this field specifies how long the task is delayed to execute. For periodically executed tasks, it specifies the execution interval of the task. The scheduled duration can be fixed or dynamically calculated based on certain conditions. 4) The task entity (i.e., the task function) stores the actual task code or function to be executed. When the task reaches the execution time, the task entity will be called to execute the task. 5) Task execution order: If there are multiple scheduled tasks to be executed, this field specifies their execution order. The execution order can be based on priority or other custom logic.

[0058] Specifically, the task description information of the timer usually exists in the form of a data structure (such as a structure, class instance, etc.), and is managed and scheduled by the timer management module. Developers can define and use these fields according to the specific needs of the application to ensure that the scheduled task can be executed as expected.

[0059] Optionally, the computer device 104 obtains different task description information from the terminal 102 through an external interface, and calls the task configuration thread of the timer to generate different scheduled tasks according to the received different task description information.

[0060] The specific process of generating different scheduled tasks can be as follows: the task configuration thread creates a corresponding scheduled task object or data structure according to information such as the task type and the scheduled duration, and generates a corresponding scheduled task according to the corresponding scheduled task object or data structure. For periodically executed tasks, the thread sets the execution interval and number of repetitions of the task. For delayed execution tasks, the thread sets the delay time of the task and the condition for executing it once. The generated scheduled task is added to the task scheduling queue of the timer.

[0061] S202, processing different scheduled tasks generated by the task configuration thread in sequence through the task execution thread of the timer.

[0062] Specifically, the task configuration thread generates different scheduled tasks and sends the different scheduled tasks to the task execution thread, which manages the execution process of the different scheduled tasks. The different scheduled tasks can be executed in sequence according to the configuration order.

[0063] It is understandable that by managing the execution process of different scheduled tasks through task execution threads, frequent creation and destruction of threads can be avoided, because thread creation and destruction is a relatively time-consuming operation. Task execution threads can be reused, thereby reducing the resource overhead caused by creation and destruction.

[0064] In the above-mentioned scheduled task execution method, the task configuration thread of the timer in the present application can generate different scheduled tasks according to different task description information. Compared with the traditional technology setting of creating a timer for each scheduled task, the present application can configure a variety of scheduled tasks only through the task configuration thread, thereby reducing resource consumption; in addition, the task execution thread of the timer is used to execute different scheduled tasks generated by the task configuration thread. By managing the scheduled tasks through the task execution thread, frequent creation and destruction of threads can be avoided, further reducing resource consumption; and the task configuration thread is not affected by the task execution thread, and is only responsible for timing triggering, which can realize the timing function with millisecond-level precision, while ensuring the timing accuracy when managing scheduled tasks through multiple threads.

[0065] In an exemplary embodiment, Figure 3 As shown, different scheduled tasks are generated according to the different task description information received, including:

[0066] S301, for each received task description information, construct a task object corresponding to the task description information in a task storage container through a task adding function.

[0067] The task adding function refers to a function or method used to add a new task to a system or application in programming or system design. The input of the task adding function is the task description information, and the output is the task object. The task object is usually an abstract representation of the task, which provides all the details required to execute the task. In the timing scenario, the task object refers to a specific task instance that is scheduled to be executed at a specific time in the future.

[0068] It can be understood that the task object encapsulates all relevant information of the scheduled task (such as task description, execution logic, parameters, status, etc.) in a separate data structure, making the management and operation of scheduled tasks more centralized and orderly. Task objects can be used as elements in a task queue or task list, and can be uniformly managed and controlled by a task scheduler or task manager. Furthermore, the use of task objects can make it easier to expand the functionality of task execution. For example, new task properties or methods can be added to support more complex task execution logic without modifying the existing task management code.

[0069] S302: Verify whether there is an execution conflict between different task objects according to the execution description information corresponding to different task objects.

[0070] The execution description information of the task object refers to a detailed description directly related to the task execution process, which covers how the task is executed, the steps to be followed during execution, possible situations that may be encountered, and corresponding handling measures.

[0071] It is understandable that verifying whether there is an execution conflict between different task objects mainly depends on the detailed analysis and comparison of the execution description information of the task objects. Since the execution description information usually includes multiple aspects such as the execution steps, required resources, execution environment, input and output of the task, it is necessary to comprehensively evaluate the potential conflict between two task objects from these dimensions.

[0072] For example, when verifying whether there is an execution conflict between different task objects, verification can be performed from the following dimensions:

[0073] Dimension 1) Verify whether the steps of the two task objects overlap: Check whether the execution steps of the two tasks overlap or interfere with each other. If two tasks need to access or modify the same resource (such as files, database records, network ports, etc.) at the same time, there may be an execution conflict.

[0074] Dimension 2) Verify whether there is competition between the resources of the two task objects: Analyze the resource requirements of the two tasks, especially the use of shared resources. If two tasks need to monopolize certain resources at the same time, and the available resources are not enough to meet the needs of both tasks, resource competition will occur, resulting in execution conflict.

[0075] Dimension 3) Environmental compatibility: confirm whether two tasks can run simultaneously in the same execution environment. For example, some tasks may require specific operating system versions, software dependencies, or hardware configurations. If these requirements conflict with each other, the tasks cannot be executed in parallel.

[0076] Dimension 4) Time Window: Analyze whether the execution time windows of two tasks overlap. If two tasks need to be executed in the same time period and there is mutual dependence or interference during the execution process, an execution conflict may occur.

[0077] Dimension 5) Input conflict: Check whether two tasks may use the same input data, and whether the processing results of these data will affect the execution of each other. If two tasks have sequential or mutually exclusive requirements for processing the same input data, an input conflict may occur.

[0078] Dimension 6) Output Impact: Analyze whether the output results of two tasks may affect each other. For example, the output of one task may be the input of another task. If this input-output relationship is not managed correctly, it may lead to data inconsistency or execution errors.

[0079] Dimension 7) Priority conflict: If two tasks have different priorities and the execution of the high-priority task will block or delay the execution of the low-priority task, then execution conflict may occur under high load conditions.

[0080] Dimension 8) Dependency chain: Analyze the dependency chain between tasks. If two tasks are indirectly connected through a series of dependencies, and these dependencies conflict in execution order or resource allocation, the execution of the entire dependency chain may be blocked.

[0081] S303: If it does not exist, generate different scheduled tasks according to different task objects.

[0082] Specifically, if there is no execution conflict between any two task objects, different task objects are further processed according to the different task objects without conflict to obtain different scheduled tasks.

[0083] In this embodiment, conflict detection also helps to avoid data competition and state inconsistency between tasks, thereby maintaining the stability and reliability of task execution. Determining execution conflicts between tasks helps to more reasonably allocate and use device resources. By avoiding resource competition and conflicts, efficient use of resources can be ensured, and resource waste and bottlenecks can be reduced.

[0084] In an exemplary embodiment, Figure 4 As shown, the task execution thread of the timer processes the different scheduled tasks generated by the task configuration thread in turn, including:

[0085] S401, through the task configuration thread, according to the thread state of the task execution thread and the execution order between different scheduled tasks, send task execution instructions for different scheduled tasks to the task execution thread in sequence.

[0086] Optionally, the thread state of the task execution thread may include a ready state, a running state, and a blocked state. In this embodiment, a mutual exclusion lock (Mutex) is set between the task configuration thread and the task execution thread. The mutual exclusion lock is a synchronization mechanism used for multi-threaded programming. Its main purpose is to ensure mutual exclusion when multiple threads access shared resources, thereby avoiding data competition and inconsistency problems.

[0087] Specifically, the mutex lock ensures that only one thread can obtain the lock and access the shared resource at the same time. When a thread (such as the task execution thread in this embodiment) obtains the mutex lock, other threads (such as the task configuration thread in this embodiment) need to wait until the thread releases the lock. This mechanism effectively prevents multiple threads from performing read and write operations on the same resource at the same time, thereby ensuring the consistency and integrity of the data. In a multi-threaded environment, if there is no appropriate synchronization mechanism, multiple threads may modify shared data at the same time, resulting in inconsistent data. Mutex locks avoid this situation by limiting serial access to shared resources, ensuring the consistency and correctness of the data.

[0088] Based on the above-mentioned mutual exclusion lock mechanism, task execution instructions for different scheduled tasks are sent to the task execution thread in sequence according to the thread state of the task execution thread and the execution order between different scheduled tasks, including: when the thread state of the task execution thread is in the ready state, task execution instructions for different scheduled tasks are sent to the task execution thread in sequence according to the execution order between different scheduled tasks.

[0089] It can be understood that the ready state specifically means that the thread has all the resources required for operation. When the task execution thread completes a scheduled task, the state of the task execution thread switches to the ready state, waiting to execute the next scheduled task.

[0090] Optionally, when the task configuration thread is in a congested state and the task execution thread is in a ready state, the thread state of the task execution thread is updated to a waiting indication state.

[0091] In this embodiment, the thread state of the task execution thread is updated to the waiting indication state through the condition variable.

[0092] It is understandable that condition variables achieve synchronization between threads by allowing threads to enter a waiting state when a specific condition is not met until the condition is met and notified by another thread. This mechanism makes up for the shortcomings of mutex, because mutex can only ensure that only one thread can access shared resources at the same time, but cannot handle the waiting and notification relationship between threads.

[0093] Furthermore, condition variables are often used in conjunction with mutexes to avoid race conditions. Before calling a wait function for a condition variable (such as pthread_cond_wait), the thread must hold the mutex associated with the condition variable. When calling a wait function, such as Figure 5 As shown, the thread (task execution thread) releases the mutex and enters a waiting state until it is awakened and regains the mutex. The purpose of this is to ensure that shared resources are not accessed by other threads while waiting for the condition variable, thereby maintaining data consistency.

[0094] In addition, when the line Figure 5 When the task configuration thread in calls the waiting function of the condition variable, if the condition is not met (that is, the waiting condition variable is not set), the thread will be blocked and release the mutex it holds. At this time, the thread will not continue to execute until another thread (the task configuration thread) changes the condition and notifies the condition variable. The notification operation can be done by calling pthread_cond_signal (to wake up a waiting thread) or pthread_cond_broadcast (to wake up all waiting threads), that is Figure 5 When the blocked thread is awakened, it will retry to acquire the mutex lock that was released before, and recheck whether the condition is met after successfully acquiring the lock.

[0095] Condition variable blocking threads is an important synchronization mechanism in concurrent programming. It allows threads to enter a waiting state when a specific condition is not met and be awakened when the condition is met, thereby achieving orderly execution between threads and data consistency protection.

[0096] S402, processing the corresponding scheduled task according to the task execution instruction through the task execution thread.

[0097] Optionally, the task configuration thread generates different task execution instructions for different scheduled tasks; the task execution instruction generated for any scheduled task may include the scheduled task and the execution control instruction, or only include the scheduled task.

[0098] Specifically, the corresponding scheduled tasks are processed according to the task execution instructions, such as Figure 6 As shown, including:

[0099] S601, extracting a frequency division coefficient corresponding to a corresponding scheduled task from a task execution instruction.

[0100] Among them, the timer is configured with a counting cycle; the frequency division coefficient According to the timing duration corresponding to the corresponding timing task and the counting period baseTimeInternal, as shown in the following formula (1):

[0101] (1)

[0102] Accordingly, the task description information can be as follows: struct TaskInfo

[0103] {

[0104] TaskType taskType; / * Task type * /

[0105] uint16_t divFactor; / * Timer division factor* /

[0106] uint16_t divFactorCnt; / * Timer division count* /

[0107] std::function<void(void)> task; / * Task entity * / ;

[0108] }

[0109] S602, control the timer to start timing.

[0110] Specifically, after the task execution thread receives the task execution instruction, the task execution thread controls the timer to start timing, the timing interval is the counting period baseTimeInternal, and the count value of the timer is 0 when the timing starts.

[0111] S603: When the timing count value of the timer is greater than or equal to the frequency division coefficient, execute the corresponding timing task.

[0112] It can be understood that the timing count value is the current count value of the timer, which increases over time until it reaches a certain threshold, and then the timer will perform its preset operation, such as triggering an interrupt, sending a signal, etc. The frequency division coefficient is a coefficient used to adjust the counting speed of the timer. By changing the frequency division coefficient, you can control the speed of the timer counting, thereby affecting the frequency of the timer triggering operation.

[0113] When the timer count value is greater than or equal to the frequency division coefficient, it indicates that the timer has reached or exceeded its set timing period and may trigger certain preset operations or events, that is, start executing the task function in the timed task.

[0114] Furthermore, after executing the corresponding timed task, the method further includes: according to the task execution instruction, if it is determined that the corresponding timed task is a periodic task, setting the timing count value to 0, and returning to the operation of executing the control timer to start timing.

[0115] Furthermore, after executing the corresponding scheduled task, the method further includes: if it is determined according to the task execution instruction that the corresponding scheduled task is a delayed task, then only the timing count value is set to 0.

[0116] In this embodiment, after receiving the task execution instruction, the task execution thread will divide the frequency according to the timing configuration of the task and decide whether to execute the task, thereby realizing the isolation of the scheduled task configuration and execution.

[0117] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0118] Based on the same inventive concept, the embodiment of the present application also provides a timed task execution device for implementing the timed task execution method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more timed task execution device embodiments provided below can refer to the limitations on the timed task execution method above, and will not be repeated here.

[0119] In an exemplary embodiment, Figure 7 As shown, a timed task execution device is provided, including a task configuration module 11 and a task execution module 12, wherein:

[0120] The task configuration module 11 is used to generate different scheduled tasks according to different task description information received through the task configuration thread of the timer;

[0121] The task execution module 12 is used to process different scheduled tasks generated by the task configuration thread in sequence through the task execution thread of the timer.

[0122] In one embodiment, the task configuration module 11 is used to: for each received task description information, construct a task object corresponding to the task description information in the task storage container through a task adding function;

[0123] According to the execution description information corresponding to different task objects, verify whether there is an execution conflict between different task objects;

[0124] If it does not exist, different scheduled tasks will be generated according to different task objects.

[0125] In one embodiment, the task execution module 12 is used to: send task execution instructions for different scheduled tasks to the task execution thread in sequence according to the thread state of the task execution thread and the execution order between different scheduled tasks through the task configuration thread;

[0126] Through the task execution thread, the corresponding scheduled tasks are processed according to the task execution instructions.

[0127] In one embodiment, the task execution module 12 is used to: extract the frequency division coefficient corresponding to the corresponding timed task from the task execution instruction;

[0128] Control the timer to start timing;

[0129] When the timing count value of the timer is greater than or equal to the frequency division coefficient, the corresponding timing task is executed.

[0130] In one of the embodiments, the timer is configured with a counting period; the frequency division coefficient is determined according to the timing duration and the counting period corresponding to the corresponding timing task.

[0131] In one embodiment, the task execution module 12 is used to: when it is determined according to the task execution instruction that the corresponding timed task is a periodic task, set the timer count value to 0 and return to the operation of executing the control timer to start timing.

[0132] In one embodiment, the task configuration module 11 is used to: when the thread state of the task execution thread is in the ready state, send task execution instructions for different scheduled tasks to the task execution thread in sequence according to the execution order between different scheduled tasks.

[0133] In one embodiment, the task execution module 12 is used to: when the task configuration thread is in a congested state and the task execution thread is in a ready state, update the thread state of the task execution thread to a waiting indication state.

[0134] Each module in the above-mentioned timed task execution device can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.

[0135] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 8As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data of the timed task processing method. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a timed task execution method is implemented.

[0136] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0137] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:

[0138] Through the task configuration thread of the timer, different scheduled tasks are generated according to the different task description information received;

[0139] Through the timer's task execution thread, different scheduled tasks generated by the task configuration thread are processed in turn.

[0140] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0141] Through the task configuration thread of the timer, different scheduled tasks are generated according to the different task description information received;

[0142] Through the timer's task execution thread, different scheduled tasks generated by the task configuration thread are processed in turn.

[0143] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:

[0144] Through the task configuration thread of the timer, different scheduled tasks are generated according to the different task description information received;

[0145] Through the timer's task execution thread, different scheduled tasks generated by the task configuration thread are processed in turn.

[0146] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0147] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0148] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for processing a scheduled task, characterized in that: The method comprises: Through the task configuration thread of the timer, different scheduled tasks are generated according to the different task description information received; The different scheduled tasks generated by the task configuration thread are processed in sequence through the task execution thread of the timer.

2. The method according to claim 1, characterized in that The generating different scheduled tasks according to the received different task description information includes: For each received task description information, a task object corresponding to the task description information is constructed in a task storage container through a task adding function; According to the execution description information corresponding to different task objects, verify whether there is an execution conflict between different task objects; If it does not exist, different scheduled tasks will be generated according to different task objects.

3. The method according to claim 1 or 2, characterized in that: The task execution thread through the timer sequentially processes different scheduled tasks generated by the task configuration thread, including: By means of the task configuration thread, according to the thread state of the task execution thread and the execution order between different scheduled tasks, task execution instructions for different scheduled tasks are sent to the task execution thread in sequence; The corresponding scheduled task is processed according to the task execution instruction through the task execution thread.

4. The method according to claim 3, characterized in that The processing of the corresponding scheduled task according to the task execution instruction includes: Extracting the frequency division coefficient corresponding to the corresponding scheduled task from the task execution instruction; Controlling the timer to start timing; When the timing count value of the timer is greater than or equal to the frequency division coefficient, the corresponding timing task is executed.

5. The method according to claim 4, characterized in that The timer is configured with a counting cycle; the frequency division coefficient is determined according to the timing duration corresponding to the corresponding timing task and the counting cycle.

6. The method according to claim 4, characterized in that After executing the corresponding scheduled task, the method further includes: When it is determined according to the task execution instruction that the corresponding timed task is a periodic task, the timer count value is set to 0, and the operation of controlling the timer to start timing is returned.

7. The method according to claim 3, characterized in that The sending task execution instructions for different scheduled tasks to the task execution thread in sequence according to the thread state of the task execution thread and the execution order between different scheduled tasks includes: When the thread state of the task execution thread is in the ready state, task execution instructions for different scheduled tasks are sent to the task execution thread in sequence according to the execution order of different scheduled tasks.

8. The method according to claim 3, characterized in that The method further comprises: When the task configuration thread is in a congested state and the task execution thread is in a ready state, the thread state of the task execution thread is updated to a waiting indication state.

9. A timed task execution device, characterized in that: The device comprises: A task configuration module is used to generate different scheduled tasks according to different task description information received through the task configuration thread of the timer; The task execution module is used to process the different scheduled tasks generated by the task configuration thread in sequence through the task execution thread of the timer.

10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Cited By

  • Timed task execution method, electronic equipment, readable storage medium and program product

    CN120803667A

  • Timed task execution method, electronic device, readable storage medium and program product

    CN120803667B

  • Timer event processing method and device, medium, program and server system

    CN120849067A

  • Method, apparatus, medium, program and server system for handling timer events

    CN120849067B