Countdown task execution method, device, computer equipment and storage medium
By storing countdown tasks in a persistent repository and dividing them into blocking queues, the method optimizes thread usage to reduce resource consumption and ensure timely task execution, addressing inefficiencies in current countdown task execution methods.
Patent Information
- Application Number
- CN202011594546.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-29
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2040-12-29
AI Technical Summary
Current methods for executing countdown tasks are resource-intensive and inefficient, leading to potential service shutdowns or delayed task completion due to high thread occupancy and thread pool limitations.
A method involving storing countdown tasks in a persistent repository, dividing them into blocking queues based on trigger time, and using a task thread pool with controlled resource allocation to execute tasks sequentially and dynamically adjust thread usage.
This approach reduces resource consumption and ensures timely execution of countdown tasks by optimizing thread usage, preventing simultaneous high resource demand and ensuring tasks are completed efficiently.
Smart Images

Figure CN112596888B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to a method, device, computer equipment and storage medium for executing a countdown task. Background Art
[0002] As the functions of application software continue to increase, specific tasks need to be processed regularly. The current solutions for executing countdown tasks are: one is to control a countdown task through a thread, and release the thread to execute the task after the countdown time is reached. This solution has too high thread occupancy rate and will cause a surge in resource usage in a short period of time. In severe cases, it may cause the service to shut down and restart; another solution is to control a group of countdown tasks through a thread pool. If the thread is used up, another group of countdown tasks can only be executed after the thread is idle. This solution will cause some countdown tasks to fail to execute on time after the thread waits, and thus the countdown task cannot be completed normally. In short, the current solution for executing countdown tasks occupies too many resources and cannot efficiently complete the countdown task. Summary of the invention
[0003] The main purpose of this application is to provide a countdown task execution method, device, computer equipment and storage medium, aiming to solve the problem that the resources required to execute the countdown task are too high and the countdown task cannot be completed efficiently.
[0004] In order to achieve the above-mentioned invention object, the present application proposes a method for executing a countdown task, comprising the following steps:
[0005] Obtain a countdown task, store the countdown task in a persistent repository, and add corresponding execution information for the countdown task, wherein the execution information includes a trigger time of the countdown task;
[0006] According to a preset time interval, the target countdown task whose trigger time is within a preset time range is obtained from the persistence library;
[0007] Divide the target countdown task into several parts and store them into corresponding blocking queues respectively;
[0008] Control the regular task thread to obtain the target countdown task from the corresponding blocking queue in sequence and then execute the target countdown task; and monitor the trigger time of the newly added target countdown task. If the difference between the trigger time of the newly added target countdown task and the current time is less than the preset value, control the additional task thread to execute the newly added countdown task.
[0009] Further, the controlling regular task thread sequentially obtains the target countdown tasks from the corresponding blocking queue and then executes the target countdown tasks, including:
[0010] Configure the number of regular task threads in the regular task thread pool equal to the number of blocking queues;
[0011] Within an execution time range, a regular task thread in the regular task thread pool is controlled to sequentially obtain target countdown tasks from the corresponding blocking queue and then execute the target countdown tasks.
[0012] Furthermore, within an execution time range, before controlling a regular task thread in a regular task thread pool to sequentially obtain a target countdown task from a corresponding blocking queue and then executing the target countdown task, it also includes:
[0013] Get the configuration resource information of each regular task thread in the regular task thread pool;
[0014] Different blocking queues are allocated to different regular task threads according to the configuration resource information.
[0015] Furthermore, dividing the target countdown task into several parts and storing them in corresponding blocking queues respectively includes:
[0016] Obtain the number of target countdown tasks;
[0017] According to the number of the target countdown tasks, a corresponding target number of blocking queues is configured;
[0018] The target countdown task is divided into target quantity parts and stored in corresponding blocking queues respectively.
[0019] Furthermore, after the control routine task thread sequentially obtains the target countdown tasks from the corresponding blocking queue and executes the target countdown tasks, it also includes:
[0020] Count the success rate of the conventional task thread in executing the target countdown task;
[0021] If the success rate is lower than a safety value, the conventional task thread is configured to be in a suspended enabled state.
[0022] Furthermore, before obtaining the target countdown task whose trigger time is within a preset time range from the persistent repository at a preset time interval, the process includes:
[0023] Get the distribution information of the number of countdown tasks in historical statistics;
[0024] A preset time interval is determined according to the distribution information, and the preset time interval is the same as a value of a preset time range.
[0025] Further, the control routine task thread sequentially obtains the target countdown task from the corresponding blocking queue and then executes the target countdown task; and monitors the trigger time of the newly added target countdown task. If the difference between the trigger time of the newly added target countdown task and the current time is less than a preset value, after controlling the additional task thread to execute the newly added countdown task, it also includes:
[0026] The execution information of the countdown task is updated, where the execution information includes the execution status of the countdown task.
[0027] The present application also provides a countdown task execution device, comprising:
[0028] Data persistence module: used to obtain countdown tasks, store the countdown tasks in a persistence library, and add corresponding execution information for the countdown tasks, wherein the execution information includes the triggering time of the countdown tasks;
[0029] Task acquisition module: used to acquire the target countdown task whose trigger time is within a preset time range from the persistent database at a preset time interval;
[0030] Task hierarchical module: used to divide the target countdown task into several parts and store them in corresponding blocking queues respectively;
[0031] Task execution module: used to control the regular task thread to obtain the target countdown task from the corresponding blocking queue in sequence and then execute the target countdown task; and monitor the trigger time of the newly added target countdown task. If the difference between the trigger time of the newly added target countdown task and the current time is less than the preset value, control the additional task thread to execute the newly added countdown task.
[0032] The present application also 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 steps of executing any one of the countdown task execution methods described above are implemented.
[0033] The present application also provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of executing any of the above-mentioned countdown task execution methods are implemented.
[0034] The present application provides a method for executing countdown tasks in layers, firstly, by acquiring the countdown tasks to be triggered, storing the countdown tasks in a persistent library, and adding corresponding execution information for the countdown tasks, wherein the execution information includes the triggering time of the countdown tasks, and in the persistent library, the countdown tasks are sequentially sorted according to the difference between the triggering time of the countdown tasks and the current time, and then, according to the preset time interval, the target countdown tasks whose triggering time is within the preset range are acquired from the persistent library, the countdown tasks are layered for the first time, and then the target countdown tasks are divided into several parts and respectively stored in the corresponding blocking queues, the countdown tasks are layered for the second time, and then the conventional task line is controlled. The program obtains the target countdown task from the corresponding blocking queue in turn and executes the target countdown task. When the target countdown task in a blocking queue is completed, the next regular task thread is controlled to execute the target countdown task in the next blocking queue, thereby ensuring that the countdown tasks can be executed in order after the countdown ends, improving the sequentiality of thread processing, and then opening up an additional task thread to process the newly added countdown tasks whose trigger time is close to the current time, thereby ensuring that the newly added countdown tasks can be executed normally according to the trigger time. By processing the countdown tasks in a hierarchical manner, the resources occupied by the threads are kept low, and it is avoided that too many threads are executed at the same time and require too much system resources, thereby reducing resource consumption. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 A flowchart of an embodiment of a method for executing a countdown task of the present application;
[0036] Figure 2 This is a flowchart of an embodiment of the present application in which the target countdown task is divided into several parts and the parts are respectively stored in corresponding blocking queues;
[0037] Figure 3 This is a schematic diagram of the structure of an embodiment of a device for executing a countdown task of the present application;
[0038] Figure 4 This is a schematic block diagram of the structure of an embodiment of a computer device of the present application.
[0039] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0040] 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.
[0041] Reference Figure 1 An embodiment of the present application provides a method for executing a countdown task, which includes at least steps S10-S40. The detailed description of each step of the method for executing the countdown task is as follows.
[0042] S10. Obtain a countdown task, store the countdown task in a persistent repository, and add corresponding execution information for the countdown task, where the execution information includes a trigger time of the countdown task.
[0043] The embodiment of the present application is applied to a task processing system. During the task processing process, there are tasks that are triggered only after the countdown time. The present embodiment defines these tasks as countdown tasks. For example, task A needs to be executed at 10:18:00, task B needs to be executed at 10:20:00, and task C needs to be executed at 10:20:30. The above tasks A, B, and C are countdown tasks. When the task processing system receives the countdown task, the countdown task is persistently stored in a persistent library, and corresponding execution information is added for each countdown task. The execution information includes the triggering time of the countdown task, that is, the time when the countdown task needs to be executed. In addition, the execution information may also include the execution class, method, and parameters of the countdown task. The execution class, method, and parameters of the countdown task record what operation the countdown task performs on what function, that is, reflects the specific operation of the countdown task. Furthermore, the execution information also includes the execution status identifier of the countdown task, which represents the execution status of the countdown task at the current time.
[0044] S20. Obtain, at a preset time interval, from the persistence repository the target countdown task whose trigger time is within a preset time range.
[0045] In this embodiment, after storing the countdown task in the persistence library, the countdown tasks are sorted in sequence in the persistence library according to the interval distance between the trigger time of the countdown task and the current time. After sorting, in order to realize hierarchical execution of the countdown task, the countdown task closer to the current time is processed more finely, and the countdown task farther from the current time is processed more coarsely. In this embodiment, according to the preset time interval, the countdown task with the trigger time within the preset time range is obtained from the persistence library, and the countdown task with the trigger time within the preset range is defined as the target countdown task. In one implementation, the preset time interval is 30 minutes, and the target countdown task is obtained from the persistence library in sequence every 30 minutes. The target countdown task is the countdown task with the trigger time within 30 minutes of the current time, that is, the scheduled task is executed once every 30 minutes to obtain the countdown task data to be executed within the next 30 minutes from the persistence library and sort it by the trigger time.
[0046] S30, dividing the target countdown task into several parts and storing them in corresponding blocking queues respectively.
[0047] In this embodiment, after obtaining the target countdown task, the countdown task is layered again, and the countdown task is sorted according to the distance between the trigger time and the current time. The trigger time is close to the current time and is sorted first, and the trigger time is far from the current time and is sorted later. Then the target countdown task is divided into several parts and stored in the corresponding blocking queues respectively, that is, the target countdown tasks are stored separately according to the order of trigger time. In one embodiment, six blocking queues are established, and then the target countdown task is layered every 5 minutes, and the countdown tasks to be triggered within 30 minutes are divided into 6 parts, and then stored in the corresponding blocking queues respectively. The blocking queues include A, B, C, D, E, and F, that is, the target countdown task whose trigger time is within 5 minutes (excluding 5 minutes) from the current time is stored in the blocking queue A, and the target countdown task whose trigger time is within 5 minutes-10 minutes (excluding 10 minutes) from the current time is stored in the blocking queue B, and so on, so that the target countdown task with a trigger time within a preset time range is divided into several parts and stored in the corresponding blocking queues respectively.
[0048] S40, control the regular task thread to obtain the target countdown tasks from the corresponding blocking queue in sequence and then execute the target countdown tasks; and monitor the trigger time of the newly added target countdown tasks. If the difference between the trigger time of the newly added target countdown task and the current time is less than a preset value, control the additional task thread to execute the newly added countdown task.
[0049] In this embodiment, after the target countdown task is divided into several parts and stored in the corresponding blocking queues respectively, the conventional task thread is controlled to sequentially obtain the target countdown tasks from the corresponding blocking queues. Specifically, the conventional task thread is configured in the conventional task thread pool, and the conventional task thread is activated when the project is started, and then the tasks that need countdown processing are cyclically obtained from the blocking queue, and the target countdown task is executed after the target countdown task is obtained. The conventional task thread obtains one target countdown task at a time in the order of triggering time and executes it. When the target countdown task in a blocking queue is executed, the next initialization thread is controlled to execute the target countdown task in the next blocking queue. At the same time, in the process of countdown tasks being executed in sequence, there will be new countdown tasks, and there is a phenomenon that the trigger time of the new countdown tasks is too close to the current time. In this embodiment, in the process of regular task threads executing countdown tasks, the trigger time of the new countdown tasks is monitored. If the difference between the trigger time of the new countdown task and the current time is less than a preset value, the new countdown task is configured to be processed by an additional task thread, and an additional task thread is opened to process the new countdown task whose trigger time is close to the current time, thereby ensuring that the new countdown task can be executed normally according to the trigger time, and the countdown tasks processed by the regular task thread are diverted to avoid opening too many threads to process countdown tasks, and also to avoid too many countdown tasks that need to be processed by the same thread at the same time, thereby improving the efficiency of multi-task execution.
[0050] The present embodiment provides a method for executing countdown tasks in layers, firstly, by acquiring the countdown tasks to be triggered, storing the countdown tasks in a persistent database, and adding corresponding execution information for the countdown tasks, wherein the execution information includes the triggering time of the countdown tasks, and in the persistent database, the countdown tasks are sequentially sorted according to the difference between the triggering time of the countdown tasks and the current time, and then, according to the preset time interval, the target countdown tasks whose triggering time is within the preset range are acquired from the persistent database, the countdown tasks are layered for the first time, and then the target countdown tasks are divided into several parts and respectively stored in the corresponding blocking queues, the countdown tasks are layered for the second time, and then the conventional task line is controlled. The program obtains the target countdown task from the corresponding blocking queue in turn and executes the target countdown task. When the target countdown task in a blocking queue is completed, the next regular task thread is controlled to execute the target countdown task in the next blocking queue, thereby ensuring that the countdown tasks can be executed in order after the countdown ends, improving the sequentiality of thread processing, and then opening up an additional task thread to process the newly added countdown tasks whose trigger time is close to the current time, thereby ensuring that the newly added countdown tasks can be executed normally according to the trigger time. By processing the countdown tasks in a hierarchical manner, the resources occupied by the threads are kept low, and it is avoided that too many threads are executed at the same time and require too much system resources, thereby reducing resource consumption.
[0051] In one embodiment, the controlling the regular task thread sequentially obtains the target countdown tasks from the corresponding blocking queue and then executes the target countdown tasks, including:
[0052] Configure the number of regular task threads in the regular task thread pool equal to the number of blocking queues;
[0053] Within an execution time range, a regular task thread in the regular task thread pool is controlled to sequentially obtain target countdown tasks from the corresponding blocking queue and then execute the target countdown tasks.
[0054] In this embodiment, when controlling the regular task thread to sequentially obtain the target countdown task from the corresponding blocking queue and then execute the target countdown task, the regular task thread is controlled by a regular task thread pool, and regular task threads equal to the number of blocking queues are configured in the regular task thread pool. When the target countdown task is divided into 6 parts and stored in 6 blocking queues, 6 regular task threads are configured in the regular task thread pool, and each regular task thread is used to execute a target countdown task in a blocking queue, and within an execution time range, a regular task thread in the regular task thread pool is controlled to sequentially obtain the target countdown task from the corresponding blocking queue. The target countdown task is executed after the target countdown task is completed. The execution time range is the ratio of the above-mentioned preset time range to the number of blocking queues. For example, the preset time range is 30 minutes. The target countdown task with the trigger time within 30 minutes is obtained from the persistent library, and then the target countdown task is layered into 6 parts every 5 minutes and stored in 6 blocking queues. At this time, an execution time range is 5 minutes. Within the execution time range, only one regular task thread is controlled to obtain the target countdown task from the corresponding blocking queue in sequence and then execute the target countdown task, so as to avoid too many threads executing at the same time and occupying too many system resources.
[0055] In one embodiment, within an execution time range, controlling a regular task thread in a regular task thread pool to sequentially obtain a target countdown task from a corresponding blocking queue and before executing the target countdown task further includes:
[0056] Get the configuration resource information of each regular task thread in the regular task thread pool;
[0057] Different blocking queues are allocated to different regular task threads according to the configuration resource information.
[0058] In this embodiment, before controlling the regular task threads in the regular task thread pool to obtain the target countdown tasks from the corresponding blocking queues in sequence, different regular task threads are configured with different resources, including distributed configuration of regular task threads, and the configuration resources of regular task threads at different nodes are different, and the number of target countdown tasks contained in each blocking queue is also different. In order to better allocate regular task threads to execute the target countdown tasks in the blocking queues, the configuration resource information of each regular task thread in the regular task thread pool is obtained to determine the maximum number of target countdown tasks that each regular task thread can process, and then different blocking queues are allocated to different regular task threads according to the configuration resource information, and regular task threads with high configuration resources are allocated to blocking queues containing a high number of target countdown tasks, thereby ensuring that the target countdown tasks in the blocking queues containing a high number of target countdown tasks can be executed on time, thereby ensuring the efficiency of countdown task execution.
[0059] In one embodiment, Figure 2 As shown, the target countdown task is divided into several parts and stored in corresponding blocking queues respectively, including:
[0060] S31: Obtain the number of the target countdown tasks;
[0061] S32: configuring a corresponding target number of blocking queues according to the number of the target countdown tasks;
[0062] S33: Divide the target countdown task into target quantity parts and store them in corresponding blocking queues respectively.
[0063] In this embodiment, the total amount of countdown tasks in different time periods is different. For example, the number of countdown tasks in the 10:00-12:00 time period of each day is greater than the number of countdown tasks in the 12:00-14:00 time period of each day. When the number of countdown tasks is greater, in order to process the countdown tasks in a refined manner, the countdown tasks are more finely allocated. Specifically, after the target countdown tasks are divided into several parts, they are respectively stored in the corresponding blocking queues to obtain the number of target countdown tasks. Then, according to the number of the target countdown tasks, the corresponding target number of blocking queues are configured, and then the target countdown tasks are divided into target number parts and respectively stored in the corresponding blocking queues. When the number of target countdown tasks is large, more blocking queues are configured, and when the number of target countdown tasks is small, fewer blocking queues are configured, thereby dynamically adjusting the number of blocking queues to dynamically allocate the number of conventional task threads, better allocate the number of countdown tasks in the blocking queues, and ensure that the conventional task threads can complete the execution of the countdown tasks in the blocking queues.
[0064] In one embodiment, after the controlling regular task thread sequentially obtains the target countdown tasks from the corresponding blocking queue and executes the target countdown tasks, it also includes:
[0065] Count the success rate of the conventional task thread in executing the target countdown task;
[0066] If the success rate is lower than a safety value, the conventional task thread is configured to be in a suspended enabled state.
[0067] In this embodiment, after controlling the regular task thread to obtain the target countdown task from the corresponding blocking queue in sequence and then execute the target countdown task, it is necessary to monitor in real time the success rate of the regular task thread in executing the countdown task. When the success rate of the regular task thread is too low, the regular task thread may have certain errors and cannot normally complete a certain type of countdown task. At this time, if the success rate of the regular task thread is lower than the safety value, the regular task thread is configured to be suspended and enabled, temporarily reducing the number of regular task threads, and controlling the regular task thread with low success rate to temporarily not execute the task, thereby ensuring the success rate of the regular task thread in executing the countdown task.
[0068] In one embodiment, obtaining the target countdown task whose trigger time is within a preset time range from the persistent repository at a preset time interval includes:
[0069] Get the distribution information of the number of countdown tasks in historical statistics;
[0070] The preset time interval is determined according to the distribution information, and the preset time interval is the same as the value of the preset time range.
[0071] In this embodiment, the countdown tasks can be counted on a daily basis, and the number of countdown tasks in each time period of each day can be counted, so as to obtain the distribution information of the number of countdown tasks per day, and then before obtaining the target countdown task whose trigger time is within the preset time range from the persistent library, the distribution information of the number of countdown tasks from historical statistics is obtained, so as to determine which time period has a larger number of countdown tasks and which time period has a smaller number of countdown tasks, and then determine the preset time interval based on the distribution information, and the preset time interval is the same as the value of the preset time range, for example, the countdown task data is obtained once every 30 minutes, and then the countdown task whose trigger time is within 30 minutes of the current time is obtained from the persistent library as the target countdown task, so as to more accurately control the precision of the countdown task execution and improve the efficiency of the countdown task execution.
[0072] In one embodiment, the control routine task thread sequentially obtains the target countdown tasks from the corresponding blocking queue and then executes the target countdown tasks; and monitors the trigger time of the newly added target countdown tasks. If the difference between the trigger time of the newly added target countdown task and the current time is less than a preset value, after controlling the additional task thread to execute the newly added countdown task, the method further includes:
[0073] The execution information of the countdown task is updated, where the execution information includes the execution status of the countdown task.
[0074] In this embodiment, after the countdown task is executed, the execution information of the countdown task is updated, and the execution information includes the execution status of the countdown task. The execution status of the countdown task is changed to an executed status, wherein the executed status also includes marking information of successful execution and failed execution. By changing the execution status in the execution information, it is convenient to count the execution status of each countdown task. According to the execution status information, it can be ensured that each unexecuted countdown task can be executed, and it can be ensured that the countdown task is not executed repeatedly, thereby improving resource utilization.
[0075] Reference Figure 3 The present application also provides a countdown task execution device, including:
[0076] Data persistence module 10: used to obtain a countdown task, store the countdown task in a persistence database, and add corresponding execution information for the countdown task, wherein the execution information includes a trigger time of the countdown task;
[0077] Task acquisition module 20: used to acquire the target countdown task whose trigger time is within a preset time range from the persistent database at a preset time interval;
[0078] Task hierarchical module 30: used to divide the target countdown task into several parts and store them into corresponding blocking queues respectively;
[0079] Task execution module 40: used to control the regular task thread to obtain the target countdown task from the corresponding blocking queue in sequence and then execute the target countdown task; and monitor the trigger time of the newly added target countdown task. If the difference between the trigger time of the newly added target countdown task and the current time is less than a preset value, control the additional task thread to execute the newly added countdown task.
[0080] As described above, it can be understood that the various components of the countdown task execution device proposed in the present application can implement the step functions of any one of the countdown task execution methods described above.
[0081] In one embodiment, the task execution module 40 further includes executing:
[0082] Configure the number of regular task threads in the regular task thread pool equal to the number of blocking queues;
[0083] Within an execution time range, a regular task thread in the regular task thread pool is controlled to sequentially obtain target countdown tasks from the corresponding blocking queue and then execute the target countdown tasks.
[0084] In one embodiment, the task execution module 40 further includes executing:
[0085] Get the configuration resource information of each regular task thread in the regular task thread pool;
[0086] Different blocking queues are allocated to different regular task threads according to the configuration resource information.
[0087] In one embodiment, the task hierarchy module 30 further includes executing:
[0088] Obtain the number of target countdown tasks;
[0089] According to the number of the target countdown tasks, a corresponding target number of blocking queues is configured;
[0090] The target countdown task is divided into target quantity parts and stored in corresponding blocking queues respectively.
[0091] In one embodiment, the device further comprises: a statistical module, configured to count the success rate of the conventional task thread in executing the target countdown task;
[0092] If the success rate is lower than a safety value, the conventional task thread is configured to be in a suspended enabled state.
[0093] In one embodiment, the task acquisition module 20 further includes executing:
[0094] Get the distribution information of the number of countdown tasks in historical statistics;
[0095] A preset time interval is determined according to the distribution information, and the preset time interval is the same as a value of a preset time range.
[0096] In one embodiment, the apparatus further comprises:
[0097] The updating module is used to update the execution information of the countdown task, wherein the execution information includes the execution status of the countdown task.
[0098] Reference Figure 4In the embodiment of the present application, a computer device is also provided. The computer device may be a mobile terminal, and its internal structure may be as follows: Figure 4 As shown. The computer device includes a processor, a memory, a network interface, a display device and an input device connected through a system bus. Among them, the network interface of the computer device is used to communicate with an external terminal through a network connection. The display device of the computer device is used to display an interactive interface. The input device of the computer device is used to receive user input. The processor designed by the computer is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium. The non-volatile storage medium stores an operating system, a computer program and a database. When the computer program is executed by the processor, a method for executing a countdown task is implemented.
[0099] The execution method of the above-mentioned processor for executing the above-mentioned countdown task includes: obtaining the countdown task, storing the countdown task in a persistent library, and adding corresponding execution information for the countdown task, the execution information including the trigger time of the countdown task; obtaining the target countdown task whose trigger time is within a preset time range from the persistent library at a preset time interval; dividing the target countdown task into several parts and storing them in corresponding blocking queues respectively; controlling the regular task thread to obtain the target countdown task from the corresponding blocking queue in sequence and then execute the target countdown task; and monitoring the trigger time of the newly added target countdown task. If the difference between the trigger time of the newly added target countdown task and the current time is less than a preset value, controlling the additional task thread to execute the newly added countdown task. The computer device provides a method for executing countdown tasks in layers, firstly, by acquiring a countdown task to be triggered, storing the countdown task in a persistent library, and adding corresponding execution information for the countdown task, the execution information including the triggering time of the countdown task, sorting the countdown tasks in the persistent library in sequence according to the difference between the triggering time of the countdown task and the current time, and then acquiring the target countdown task whose triggering time is within a preset range from the persistent library at a preset time interval, layering the countdown task for the first time, dividing the target countdown task into several parts and storing them in corresponding blocking queues respectively, layering the countdown task for the second time, and then controlling the conventional task. The service thread obtains the target countdown task from the corresponding blocking queue in turn and executes the target countdown task. When the target countdown task in a blocking queue is completed, the next regular task thread is controlled to execute the target countdown task in the next blocking queue, thereby ensuring that the countdown tasks can be executed in order after the countdown ends, improving the sequentiality of thread processing, and then opening up an additional task thread to process the newly added countdown tasks whose trigger time is close to the current time, thereby ensuring that the newly added countdown tasks can be executed normally according to the trigger time. By processing the countdown tasks in a hierarchical manner, the resources occupied by the threads are kept low, and it is avoided that too many threads are executed at the same time and require too much system resources, thereby reducing resource consumption.
[0100] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by the processor, a method for executing a countdown task is implemented, comprising the steps of: obtaining a countdown task, storing the countdown task in a persistent library, and adding corresponding execution information for the countdown task, wherein the execution information includes a trigger time of the countdown task; obtaining a target countdown task whose trigger time is within a preset time range from the persistent library at a preset time interval; dividing the target countdown task into several parts and storing them in corresponding blocking queues respectively; controlling a regular task thread to sequentially obtain the target countdown tasks from the corresponding blocking queue and then execute the target countdown tasks; and monitoring the trigger time of a newly added target countdown task. If the difference between the trigger time of the newly added target countdown task and the current time is less than a preset value, controlling an additional task thread to execute the newly added countdown task. The computer-readable storage medium provides a method for executing countdown tasks in layers, firstly, by acquiring a countdown task to be triggered, storing the countdown task in a persistent library, and adding corresponding execution information for the countdown task, wherein the execution information includes the triggering time of the countdown task, and in the persistent library, the countdown tasks are sequentially sorted according to the difference between the triggering time of the countdown task and the current time, and then, according to a preset time interval, the target countdown task with the triggering time within a preset range is acquired from the persistent library, the countdown task is layered for the first time, and then the target countdown task is divided into several parts and respectively stored in corresponding blocking queues, the countdown task is layered for the second time, and then the constant is controlled to be The regular task thread obtains the target countdown task from the corresponding blocking queue in turn and executes the target countdown task. When the target countdown task in a blocking queue is completed, the next regular task thread is controlled to execute the target countdown task in the next blocking queue, thereby ensuring that the countdown tasks can be executed in order after the countdown ends, improving the sequentiality of thread processing, and then opening up an additional task thread to process the newly added countdown tasks whose trigger time is close to the current time, thereby ensuring that the newly added countdown tasks can be executed normally according to the trigger time. By processing the countdown tasks in a hierarchical manner, the resources occupied by the threads are kept low, and it is avoided that too many threads are executed at the same time and require too much system resources, thereby reducing resource consumption.
[0101] It will be appreciated by those skilled in the art that all or part of the processes in the above-mentioned embodiment methods can be implemented 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 memory, storage, database or other media provided in the present application and used in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0102] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, device, article or method including the element.
[0103] The above description is only a preferred embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for executing a countdown task, characterized in that: include: Obtain a countdown task, store the countdown task in a persistent repository, and add corresponding execution information for the countdown task, the execution information including the trigger time of the countdown task; At preset time intervals, the target countdown task whose trigger time is within a preset time range is obtained from the persistence library; Divide the target countdown task into several parts and store them in corresponding blocking queues respectively; Control the regular task thread to sequentially obtain the target countdown tasks from the corresponding blocking queue and then execute the target countdown tasks; and monitor the trigger time of the newly added target countdown tasks. If the difference between the trigger time of the newly added target countdown tasks and the current time is less than a preset value, control the additional task thread to execute the newly added countdown tasks; The step of obtaining the target countdown task whose trigger time is within a preset time range from the persistent repository at a preset time interval includes: In the persistence database, the countdown tasks are sequentially sorted according to the distance between the trigger time of the countdown tasks and the current time, and the countdown tasks are first layered, wherein, with the current time as the boundary, the countdown tasks closer to the current time are processed more finely; the countdown tasks farther from the current time are processed more coarsely; After obtaining the target countdown task whose trigger time is within the preset time range from the persistent database, the method includes: The countdown tasks are layered for the second time, and the countdown tasks are sorted according to the distance between the trigger time and the current time, wherein the countdown tasks with a trigger time closer to the current time are sorted first, and the countdown tasks with a trigger time farther from the current time are sorted last; The controlling routine task thread sequentially obtains target countdown tasks from the corresponding blocking queue and then executes the target countdown tasks, including: Configure regular task threads in the regular task thread pool that are equal to the number of blocking queues; Within an execution time range, a regular task thread in the regular task thread pool is controlled to sequentially obtain the target countdown task from the corresponding blocking queue and then execute the target countdown task. The execution time range is the ratio of the preset time range to the number of blocking queues.
2. The method for executing a countdown task according to claim 1, wherein: The method further includes: controlling a regular task thread in the regular task thread pool to sequentially obtain target countdown tasks from the corresponding blocking queue within an execution time range, and before executing the target countdown tasks; Get the configuration resource information of each regular task thread in the regular task thread pool; Different blocking queues are allocated to different regular task threads according to the configuration resource information.
3. The method for executing a countdown task according to claim 1, wherein: The target countdown task is divided into several parts and stored in corresponding blocking queues respectively, including: Obtain the number of target countdown tasks; Configure a corresponding target number of blocking queues according to the number of target countdown tasks; The target countdown task is divided into target quantity parts and stored in corresponding blocking queues respectively.
4. The method for executing a countdown task according to claim 1, wherein: After the conventional task thread is controlled to sequentially obtain target countdown tasks from the corresponding blocking queue and execute the target countdown tasks, the process further includes: Count the success rate of the conventional task thread in executing the target countdown task; If the success rate is lower than a safety value, the conventional task thread is configured to be in a suspended enabled state.
5. The method for executing a countdown task according to claim 1, wherein: Before obtaining the target countdown task whose trigger time is within the preset time range from the persistent repository at the preset time interval, the method includes: Get the distribution information of the number of countdown tasks in historical statistics; A preset time interval is determined according to the distribution information, and the preset time interval is the same as a value of a preset time range.
6. The method for executing a countdown task according to claim 1, wherein: The control method further includes: controlling the regular task thread to sequentially obtain target countdown tasks from the corresponding blocking queue and then execute the target countdown tasks; and monitoring the trigger time of the newly added target countdown tasks. If the difference between the trigger time of the newly added target countdown tasks and the current time is less than a preset value, controlling the additional task thread to execute the newly added countdown tasks. Update execution information of the countdown task, where the execution information includes the execution status of the countdown task.
7. A countdown task execution device, characterized in that: include: Data persistence module: used to obtain countdown tasks, store the countdown tasks in a persistence library, and add corresponding execution information for the countdown tasks, the execution information including the trigger time of the countdown tasks; Task acquisition module: used to acquire the target countdown task whose trigger time is within a preset time range from the persistent database according to a preset time interval; Task layering module: used to divide the target countdown task into several parts and store them in corresponding blocking queues respectively; Task execution module: used to control the regular task thread to sequentially obtain the target countdown task from the corresponding blocking queue and then execute the target countdown task; and monitor the trigger time of the newly added target countdown task. If the difference between the trigger time of the newly added target countdown task and the current time is less than a preset value, control the additional task thread to execute the newly added countdown task; The task acquisition module includes: a sorting module, configured to sort the countdown tasks in the persistence library according to the interval between the trigger time of the countdown tasks and the current time, and perform a first stratification on the countdown tasks, wherein, with the current time as the boundary, the countdown tasks closer to the current time are processed more finely, and the countdown tasks farther from the current time are processed more coarsely; The task acquisition module also includes: a second stratification module, configured to stratify the countdown tasks for the second time, and sort the countdown tasks according to the distance between the trigger time and the current time, wherein the countdown tasks with a trigger time closer to the current time are sorted at the front, and the countdown tasks with a trigger time farther from the current time are sorted at the back; The task execution module includes: A configuration module is used to configure a number of regular task threads in the regular task thread pool that is equal to the number of blocking queues; The control module is used to control a regular task thread in the regular task thread pool to obtain the target countdown task from the corresponding blocking queue in sequence within an execution time range and then execute the target countdown task. The execution time range is the ratio of the preset time range to the number of blocking queues.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method for executing the countdown task according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for executing the countdown task according to any one of claims 1 to 6 are implemented.
