Method and device for managing a time triggered task, computer device and storage medium
By building a task library and using a thread pool to execute tasks, the problem of excessive triggers in computer devices is solved, and efficient task management and maintenance are achieved.
Patent Information
- Application Number
- CN202210363476.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-07
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2042-04-07
AI Technical Summary
When computer equipment processes multiple tasks, the different timing of each task's trigger can lead to an excessive number of triggers, making management and maintenance difficult and affecting execution efficiency.
By constructing multiple task libraries, tasks are assigned to different task libraries based on their scheduled trigger times. When the current time matches the scheduled trigger time of the target task library, the task is assigned to a preset thread pool and executed using the thread pool.
The number of triggers has been reduced, simplifying task management and maintenance, and improving the efficiency of task execution and ease of management.
Smart Images

Figure CN114816698B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computers, and more particularly, to a management method and device for tasks triggered at a timing, a computer device, and a storage medium. BACKGROUND
[0002] With the application range of computers becoming wider, the number of tasks that a processor needs to execute simultaneously is increasing, and the trigger time corresponding to each task is more complex. In this case, a trigger is usually configured for each task to trigger and process the task when the trigger time corresponding to the task is met, but this can result in too many triggers and make it inconvenient to manage and maintain all tasks. SUMMARY
[0003] In view of the above problems, the present application provides a management method and device for tasks triggered at a timing, a computer device, and a storage medium.
[0004] In a first aspect, the present application provides a management method for tasks triggered at a timing, which includes: when a current time matches a timing trigger time corresponding to a target task library in a plurality of task libraries, assigning all execution tasks in the target task library to a preset thread pool, wherein the timing trigger times of all execution tasks in each task library are the same; and executing all execution tasks in the target task library by using threads in the preset thread pool.
[0005] In a second aspect, the present application provides a management device for tasks triggered at a timing, which includes a task trigger module and a task execution module. The task trigger module is configured to, when a current time matches a timing trigger time corresponding to a target task library in a plurality of task libraries, assign all execution tasks in the target task library to a preset thread pool, wherein the timing trigger times of all execution tasks in each task library are the same. The task execution module is configured to execute all execution tasks in the target task library by using threads in the preset thread pool.
[0006] In a third aspect, the present application provides a computer device, which includes one or more processors, a memory, and one or more application programs stored in the memory and configured to be executed by the one or more processors. The one or more programs are configured to execute the management method for tasks triggered at a timing provided in the first aspect.
[0007] In a fourth aspect, the present application provides a computer-readable storage medium, which stores program codes that can be invoked by a processor to execute the management method for tasks triggered at a timing provided in the first aspect.
[0008] The scheme provided in the application can assign all execution tasks to the task library with different timing trigger times based on the different timing trigger times corresponding to the execution tasks, and then assign all execution tasks in the target task library to the preset thread pool when the current time matches the timing trigger time corresponding to the target task library, so as to execute all execution tasks in the target task library by using threads in the preset thread pool. Therefore, the triggering of all execution tasks can be managed based on the timing trigger time corresponding to the task library, and the trigger corresponding to the task library with the same timing trigger time can be configured, so that the corresponding task is executed by the timing trigger, thereby reducing the number of triggers and making the management and maintenance of the execution tasks more convenient. BRIEF DESCRIPTION OF DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the application, and other drawings can be obtained by those skilled in the art without creative effort on the basis of these drawings.
[0010] Figure 1 A flowchart of a management method of a timing trigger task provided by an embodiment of the application is shown.
[0011] Figure 2 A flowchart of a management method of a timing trigger task provided by another embodiment of the application is shown.
[0012] Figure 3 A specific flowchart of step S210 in another embodiment of the application is shown.
[0013] Figure 4 A specific flowchart of step S212 in another embodiment of the application is shown.
[0014] Figure 5 A flowchart of a management method of a timing trigger task provided by another embodiment of the application is shown.
[0015] Figure 6 A specific flowchart of step S310 in another embodiment of the application is shown.
[0016] Figure 7 A structural block diagram of a management device of a timing trigger task provided by an embodiment of the application is shown.
[0017] Figure 8 A structural block diagram of a computer device provided by an embodiment of the application is shown.
[0018] Figure 9A structural block diagram of the computer readable storage medium provided by the embodiment of the present application is shown. DETAILED DESCRIPTION
[0019] In order to enable those skilled in the art to better understand the scheme of the present application, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0020] At present, with the development of computer technology, a computer device can complete more execution tasks at the same time. Generally, a trigger is configured for each execution task to manage all the timing trigger times in the execution task, that is, if the current time matches the timing trigger time of any execution task, the processor can start executing the content of the task. However, with the continuous expansion of the application range of the computer device, the processor needs to process more and more tasks at the same time, and more tasks correspondingly exist more triggers. The timing trigger times in each trigger are different, which easily leads to the confusion of the management and maintenance of the computer device for multiple tasks; the computer device needs more space and time to maintain all the triggers, which may also reduce the execution efficiency of the tasks.
[0021] In view of the above problems, the inventors propose the timing trigger task management method, device, storage device and storage medium provided by the embodiments of the present application, which constructs multiple task libraries according to the timing trigger times of all tasks and configures a trigger for each task library, thereby realizing the ordered management of the timing trigger times of multiple execution tasks. The specific timing trigger task management method is described in detail in subsequent embodiments.
[0022] The timing trigger task management method provided by the embodiments of the present application will be described in detail below in conjunction with the drawings.
[0023] Please refer to Figure 1 , Figure 1 A flowchart of the timing trigger task management method provided by one embodiment of the present application is shown, and the timing trigger task management method will be described in detail below in conjunction with the flowchart shown in Figure 1 The timing trigger task management method can specifically include the following steps:
[0024] Step S110: When the current time matches the timing trigger time corresponding to a target task library in multiple task libraries, all execution tasks in the target task library are assigned to a preset thread pool, wherein the timing trigger times of all execution tasks in each task library are the same.
[0025] In the embodiment of the present application, the computer device can set a plurality of task libraries according to a plurality of different timing trigger times respectively corresponding to the execution tasks, each task library corresponds to a different timing trigger time, and each task library can include any number of execution tasks, which are tasks that need to be triggered and executed at the timing trigger time corresponding to the task library, so that the computer device triggers all execution tasks in the task library based on the different timing trigger times corresponding to different task libraries. If the current time matches the timing trigger time corresponding to the target task library, it means that all execution tasks in the target task library need to be triggered and executed at the current time, therefore, the computer device can assign all execution tasks in the target task library to the preset thread pool, so as to execute all tasks in the target task library using threads in the preset thread pool. The target task library is any one of the plurality of task libraries. Therefore, since the timing trigger times of all execution tasks in each task library are the same, only a trigger needs to be configured for each task library to ensure that all execution tasks in the task library can be triggered and executed.
[0026] It can be understood that each execution task can have a plurality of different timing trigger times, and if the current time matches any timing trigger time corresponding to the execution task, the execution task needs to be triggered and executed. The task content of the execution task triggered and executed at different timing trigger times can be different. In the embodiment of the present application, the execution tasks in the task library are triggered based on the timing trigger time corresponding to each task library, and each task library corresponds to only one timing trigger time, therefore, a same execution task can exist in two or more task libraries, indicating that the execution task has a plurality of different timing trigger times.
[0027] Step S120: executing all execution tasks in the target task library using threads in the preset thread pool.
[0028] In the embodiment of the present application, the computer device can execute all execution tasks in the target task library through threads in the preset thread pool. Since the target task library is any one of the plurality of task libraries, and the number of execution tasks in each task library is not consistent, the computer device can pre-acquire the length of time required for each execution task to complete, and the total length of time required for all execution tasks in each task library to complete, and then determine the size of the preset thread pool, so that all execution tasks in any task library can complete at the fastest speed after entering the thread pool.
[0029] In some embodiments, the computer device can determine the number of threads in the thread pool based on the number of execution tasks respectively corresponding to all the task libraries. For example, if the maximum number of execution tasks respectively contained in all the task libraries is 50, that is, the number of execution tasks in each of all the task libraries is less than or equal to 50. At this time, the computer device can determine the number of threads in the thread pool as 50 to ensure that all the execution tasks in all the task libraries can be executed at the first time and completed as soon as possible.
[0030] The management method of the timing triggered task provided by the embodiments of the present application can construct multiple task libraries and respectively configure different timing trigger times according to different timing trigger times of multiple execution tasks, distribute all the execution tasks in a target task library to a preset thread pool when the current time matches the timing trigger time corresponding to the target task library, and execute all the execution tasks in the target task library by using threads in the preset thread pool. The multiple execution tasks are managed and maintained based on the timing trigger time corresponding to the task library, and the efficiency of managing and maintaining the timing trigger time of the multiple execution tasks is improved.
[0031] Please refer to Figure 2 , Figure 2 The flowchart of the management method of the timing triggered task provided by another embodiment of the present application is shown, and the following will be described in detail with respect to the flowchart shown in Figure 2 The management method of the timing triggered task can specifically include the following steps:
[0032] Step S210: Pre-create multiple task libraries.
[0033] In the embodiments of the present application, in order to reduce the number of triggers corresponding to all the execution tasks, the computer device can pre-create multiple task libraries to distribute all the execution tasks to different task libraries according to different timing trigger times respectively corresponding to each execution task, and then manage the timing trigger time of the multiple execution tasks based on the task library.
[0034] In some embodiments, the size of the pre-created multiple task libraries can be consistent, that is, the number of execution tasks that can be accommodated in each task library can be the same, wherein the size of each task library can be the total amount of all execution tasks to cope with the case that all execution tasks need to be triggered at the same time; the size of the task library can also be the average value of the number of all execution tasks, etc. to accommodate more execution tasks while reducing the memory unit occupied by the task library.
[0035] In some embodiments, the size of the pre-created task library can not be fixed, wherein each execution task in the task library can be connected in the form of a linked list, and the size of each task library can vary according to the number of execution tasks included therein. In this case, each task library is a non-continuous and non-sequential storage structure on the physical storage unit. Each task library can also be implemented in the form of a dynamic array to accommodate multiple execution tasks.
[0036] In some embodiments, as shown in FIG. 2, the step S210 of pre-creating multiple task libraries can specifically include the following steps: Figure 3
[0037] Step S211: Obtain the trigger interval time corresponding to each execution task in all execution tasks to be executed.
[0038] In the embodiments of the present application, the computer device can obtain the timing trigger time corresponding to each execution task in all execution tasks to be executed, and then determine the trigger interval time corresponding to each execution task to determine the number of task libraries and the timing trigger time corresponding to each task library. It can be understood that in all execution tasks to be executed, each execution task can be triggered to execute the same or different content at one or more different times. The computer device can obtain all trigger times, i.e. timing trigger time, in each execution task while obtaining the task data corresponding to the execution task, and obtain the trigger interval time corresponding to each task, thereby determining the number of task libraries.
[0039] For example, an execution task needs to be triggered to execute different content at each hour (e.g. 8 o'clock, 9 o'clock, 10 o'clock, etc.). The computer device can obtain the trigger interval time corresponding to the execution task as one hour. For another example, another execution task needs to be triggered to execute the task at 10:30 am every day. The computer device can obtain the trigger interval time corresponding to the execution task as 24 hours.
[0040] Step S212: Based on the trigger interval time corresponding to each execution task, construct multiple task libraries, the number of the multiple task libraries is determined according to the trigger interval time, and each task library corresponds to different timing trigger time.
[0041] In the embodiments of the present application, after determining the trigger interval time corresponding to all the execution tasks to be executed, the computer device can determine the number of task libraries and the timing trigger time corresponding to each task library based on all the trigger interval times. For example, if a part of the execution tasks need to be triggered once every hour, i.e., the trigger interval time is 1 hour, and the remaining execution tasks are triggered at 0 o'clock and 12 o'clock every day, i.e., the trigger interval time is 12 hours, then in general, the computer device can set the number of task libraries to 24 and set the timing trigger time corresponding to each task library to different hour time points (i.e., 0 o'clock, 1 o'clock, 2 o'clock, etc.), so that these task libraries can not only accommodate all the execution tasks, but also the number of task libraries is not redundant, and multiple empty triggers do not burden the execution efficiency of the computer.
[0042] It can be understood that the method of the computer device for determining the number of task libraries can be performed by obtaining the timing trigger time corresponding to each execution task, then determining the trigger interval time between the timing trigger times, thereby determining the minimum interval time among different trigger interval times, and finally determining the interval time between the timing trigger times of adjacent task libraries. At this time, the number of task libraries determined according to the minimum interval time can be optimal.
[0043] In some embodiments, as shown in Figure 4 The process of constructing multiple task libraries based on the trigger interval time corresponding to each execution task in step S212 can include the following steps:
[0044] Step S2121: determining the minimum interval time among the trigger interval times of all the execution tasks to be executed based on the trigger interval time corresponding to each execution task.
[0045] In the embodiments of the present application, as can be known from the above analysis, the computer device can obtain all the timing trigger times of each execution task when obtaining the task data of the execution task, and then determine the trigger interval time corresponding to each execution task. The computer device can obtain the minimum interval time among the trigger interval times to determine the number of task libraries that can accommodate all the execution tasks. For example, the timing trigger time corresponding to some execution tasks is every hour, and the trigger interval time is 1 hour. The timing trigger time corresponding to some other execution tasks is every even hour (2 o'clock, 4 o'clock, 6 o'clock, etc.), and the trigger interval time is 2 hours. In the absence of other execution tasks, the computer device can determine that the minimum interval time among all the execution tasks is 1 hour, thereby further determining the number of task libraries. For another example, in some execution tasks, the trigger interval time between 0 o'clock and 12 o'clock is 1 hour, and the trigger interval time between 12 o'clock and 24 o'clock is 2 hours. At this time, the computer device can determine that the minimum interval time is 1 hour.
[0046] Step S2122: determining a target number of task libraries to be constructed based on the minimum interval time.
[0047] In the embodiments of the present application, after determining the minimum interval time, the computer device can determine the target number of task libraries to be constructed based on the minimum interval time and the timing trigger time corresponding to each task. It is worth noting that the minimum interval time is not equal to the interval time between the timing trigger times corresponding to adjacent task libraries. For example, some execution tasks need to be triggered at every whole point of time (7 o'clock, 8 o'clock, 9 o'clock, etc.), and the trigger interval time corresponding to these execution tasks is 1 hour, but some other execution tasks need to be triggered at every half point of time (7:30, 8:30, 9:30, etc.), and the trigger interval time corresponding to these execution tasks is also 1 hour. Obviously, at this time, the computer device constructs the task library, and the interval time between the timing trigger times corresponding to adjacent task libraries cannot also be 1 hour, otherwise some tasks will not be able to be placed in the corresponding task library. Similarly, at this time, the computer device constructs the task library, and the interval time between the timing trigger times corresponding to adjacent task libraries does not have to be set to 1 minute or 2 minutes, etc., otherwise it will cause a large number of task libraries to be idle, and it is easy to cause the execution efficiency of the computer device to be reduced.
[0048] In general, the computer device can determine the target number of task libraries to be constructed based on the minimum interval time corresponding to all execution tasks, but it cannot simply set the interval time between the timing trigger times of the task library to the minimum interval time.
[0049] In some embodiments, after determining the minimum interval time corresponding to each execution task, the computer device can also obtain the maximum interval time among all minimum interval times, and determine the target number of task libraries to be constructed based on the minimum interval time and the maximum interval time. For example, the timing trigger time of a part of the execution tasks is every whole point of time (7 o'clock, 8 o'clock, 9 o'clock, etc.), that is, the minimum interval time is 1 hour, and the timing trigger time of another part of the execution tasks is 10 o'clock in the morning every day, that is, the minimum interval time is 24 hours, then after determining the minimum interval time corresponding to each task, the computer device can also determine that the maximum interval time among all execution tasks is 24 hours, and the computer device can determine that the target number of task libraries to be constructed is 24, and the interval time between the timing trigger times corresponding to each task library is 1 hour.
[0050] Step S2123: creating a plurality of task libraries with the target number, and associating each task library with different timing trigger times according to the timing trigger time of each execution task.
[0051] In the embodiments of the present application, after determining the target number of task libraries, the computer device can create a plurality of task libraries with the target number, and then determine the timing trigger time corresponding to each task library based on the timing trigger time corresponding to each execution task, so as to put the execution tasks triggered at the same time into the same task library. At this time, the target number of task libraries can accommodate all execution tasks, and can make all execution tasks in the same task library triggered at the same time.
[0052] Step S220: According to the timing trigger time corresponding to each execution task in all execution tasks to be executed, the computer device stores the execution task in the corresponding task library.
[0053] In the embodiments of the present application, after creating the task library, the computer device can store each execution task in different task libraries based on the timing trigger time corresponding to the execution task. Each task library has a corresponding timing trigger time when it is created, which indicates that all tasks in the task library will be triggered at the timing trigger time. That is, if there is a target timing trigger time in the target execution task that is the same as the timing trigger time corresponding to any task library, the computer device can store the target execution task in the task library, so as to trigger the target execution task when the current time matches the target timing trigger time. It can be understood that if the execution task has a plurality of different timing trigger times, the execution task will be stored in a plurality of different task libraries.
[0054] It should be understood that not every task library has a corresponding execution task. In order to facilitate the management and maintenance of execution tasks based on task libraries, the interval time between the timing trigger times corresponding to each task library is the same, but obviously, not every timing trigger time corresponding to each task library has an execution task triggered, that is, some task libraries are empty. For example, some execution tasks only need to trigger tasks at 7:00, 8:00 and 9:00 in the morning, and the remaining execution tasks need to trigger tasks at 0:00 and 12:00 every day. At this time, the computer device can determine that the minimum interval time is 1 hour, but the target number of task libraries can be 12 or 24, and the timing trigger time corresponding to each task library is every whole point of time (0:00, 1:00, 2:00, etc.). At this time, some task libraries do not contain execution tasks.
[0055] In some embodiments, the computer device stores the execution tasks in different task libraries, which can be a task identifier corresponding to the execution task, and when the current time matches the timing trigger time corresponding to the task library, the computer device can find the relevant storage location of the task based on all the task identifiers in the task library, and then obtain the relevant task content for execution. Thereby, the storage capacity in the task library can be reduced, and the content of the execution task can be managed or modified.
[0056] Step S230: configuring a trigger for each task library according to the timing trigger time of the execution task in the task library, the trigger being used to trigger all execution tasks in the task library corresponding to the trigger when the current time matches the timing trigger time of the execution task in the task library corresponding to the trigger.
[0057] In the embodiments of the present application, in order to accurately trigger the corresponding execution task at different times, the computer device can configure a trigger for each task library according to the timing trigger time of the execution task in the task library, and use the trigger to trigger all execution tasks in the task library when the current time matches the timing trigger time corresponding to the task library. It can be understood that the trigger is associated with the task library, and if the computer device wants to cancel or add a task library, the corresponding trigger also needs to be canceled or added, so that the execution tasks in the task library can be triggered accurately and timely. Therefore, the number of triggers is the same as the number of task libraries, and is irrelevant to the number of execution tasks in the task library. Usually, the number of task libraries is less than the number of execution tasks, that is, associating the trigger with the task library can effectively reduce the number of triggers, and managing the execution tasks triggered at the same time based on the task library can more conveniently and effectively maintain and manage the execution tasks.
[0058] Step S240: constructing a thread pool corresponding to the number of threads for each task library based on the number of execution tasks in the task library and the processing time.
[0059] In the embodiments of the present application, the computer device triggers all execution tasks in the task library based on the timing trigger time corresponding to the task library, which means that all execution tasks in the task library need to be triggered at the same time, that is, the computer device needs to construct a thread pool that can accommodate all execution tasks in advance, so as to ensure that all execution tasks can be triggered for execution at the timing trigger time corresponding to the task library. Therefore, the computer device can construct a thread pool corresponding to the number of threads based on the number of execution tasks in each task library and the processing time.
[0060] The size of the thread pool does not necessarily need to be equal to the number of all execution tasks in the task library. To achieve optimal processing efficiency of the execution tasks, the computer device can optimize the size of the thread pool based on the processing duration of the execution tasks. Specifically, if some execution tasks in the task library correspond to a short processing duration, the threads in the thread pool can preferentially process these execution tasks, and after a short time, all threads are used to process the remaining execution tasks with a long processing duration. At this time, the number of threads in the thread pool can be less than the number of execution tasks, and it will not have a great impact on the completion time of all execution tasks in the task library.
[0061] Step S250: When the current time matches the timing trigger time corresponding to the target task library in the plurality of task libraries, all execution tasks in the target task library are assigned to the thread pool corresponding to the target task library, wherein the timing trigger time of all execution tasks in each task library is the same.
[0062] In the embodiments of the present application, after the computer device constructs the thread pool corresponding to each task library, it can wait for the execution tasks to be triggered based on the current time. If the current time matches the timing trigger time corresponding to the target task library, all execution tasks in the target task library are assigned to the corresponding thread pool to execute all execution tasks based on the threads in the thread pool. It can be understood that all execution tasks in the same task library will be triggered to execute different contents at the same time, and the timing trigger time of all execution tasks in each task library is the same as the timing trigger time corresponding to the task library.
[0063] Step S260: All execution tasks in the target task library are executed by using the threads in the preset thread pool.
[0064] In the embodiments of the present application, step S260 can refer to the content of other embodiments, which will not be repeated here.
[0065] The management method of the timing triggered task provided in the embodiments of the present application comprises the following steps: constructing a plurality of task libraries of a target quantity based on the timing trigger time corresponding to each execution task and the minimum interval time; storing all execution tasks into the corresponding task library according to the timing trigger time corresponding to each execution task; configuring a trigger for each task library according to the timing trigger time of the execution task in the task library; and constructing a thread pool of a corresponding thread quantity for each task library based on the quantity of the execution task in each task library and the processing time length, and distributing all execution tasks in the task library into the corresponding thread pool when the current time matches the timing trigger time corresponding to the task library, and executing all execution tasks by using the threads in the thread pool. By configuring the trigger to be associated with the task library, the quantity of the trigger is reduced, and all execution tasks triggered at the same time are placed in the same task library, thereby facilitating the management and maintenance of the execution task.
[0066] Referring to Figure 5 , Figure 5 A flowchart of a management method of a timing triggered task provided in another embodiment of the present application is shown, and the management method of the timing triggered task will be described in detail below with reference to the flowchart shown in Figure 5 The management method of the timing triggered task can specifically comprise the following steps:
[0067] Step S310: determining the thread quantity required by each task library based on the quantity of the execution task in each task library and the processing time length.
[0068] In the embodiments of the present application, the computer device can process all execution tasks in all task libraries based on the same thread pool. Since there is a certain time interval between different timing trigger times corresponding to each task library, the computer device can set the thread quantity in the thread pool, so that all execution tasks in the task library triggered at the current time can be completed within the time interval, so that the thread pool can be empty before the next timing trigger time arrives, and can accommodate all execution tasks in the adjacent task library. Therefore, the computer device can determine the thread quantity required by each task library based on the quantity of the execution task in each task library and the processing time length. Since the quantity of the execution task included in each task library can be different, the thread quantity required to complete all execution tasks within the same time interval can also be different, and therefore the computer device can obtain different thread quantities required by each task library in advance, to determine the thread quantity in the final thread pool.
[0069] In some embodiments, as shown in Figure 6 Step S310 of determining the thread quantity required by each task library can comprise the following steps:
[0070] Step S311: According to the timing trigger time of executing tasks in each task library, the plurality of task libraries are sorted in the order of timing trigger time from early to late, and a sorting result is obtained.
[0071] In the embodiments of the present application, the computer device needs to determine the timing trigger time corresponding to each task library and the interval time between the timing trigger times corresponding to adjacent task libraries in order to determine the number of threads in the thread pool. When the computer device constructs the plurality of task libraries, it can determine the timing trigger time corresponding to each task library. At this time, the plurality of task libraries can be sorted in the order of timing trigger time from early to late, so as to determine the interval time based on the sorting result.
[0072] It can be understood that the computer device sorts the timing trigger times corresponding to the task libraries in order because the interval time between the timing trigger times corresponding to each task library can not be fixed. In some cases, the computer device can set the timing trigger times of the task libraries according to the same interval time, or set the timing trigger times of the task libraries according to the actual timing trigger times corresponding to the executing tasks. Therefore, in order to ensure the accuracy of the number of threads in the thread pool, the computer device can first sort the task libraries according to the timing trigger times corresponding to the task libraries.
[0073] Step S312: Determine the interval duration between the timing trigger time of executing tasks in each task library and the timing trigger time of executing tasks in the next task library in the sorting result, and obtain the interval duration corresponding to each task library.
[0074] In the embodiments of the present application, after the computer device sorts the task libraries based on the timing trigger times corresponding to the task libraries, it can obtain the interval duration between the timing trigger times corresponding to adjacent task libraries, which is used as the interval duration corresponding to the previous task library of the adjacent task libraries. The computer device determines the number of threads required to complete all executing tasks in each task library based on the number of executing tasks and the processing duration in each task library, and the interval duration corresponding to the task library. It can be understood that, in the case of the same number of executing tasks, the longer the interval duration corresponding to the task library, the fewer the number of threads required to complete all executing tasks; in the case of the same processing duration of executing tasks, the more the number of executing tasks, the more the number of threads required. In general, the number of threads is positively correlated with the number of executing tasks and the processing duration of executing tasks in the task library.
[0075] Step S313: For each task library, based on the number of executing tasks and the processing duration in each task library, determine the number of threads required to execute all executing tasks in each task library within the interval duration corresponding to each task library as the number of threads required by each task library.
[0076] In the embodiment of the present application, after the computer device determines the interval duration corresponding to each task library, the computer device can further determine the number of threads required to complete all execution tasks in the task library within the interval duration, and associate the required number of threads with the task library, so as to determine the number of threads in the thread pool. Since the interval duration corresponding to each task library, the number of execution tasks in the task library, and the processing duration of each execution task are different, the number of threads corresponding to each task library can be different, wherein the number of threads is positively correlated with the number of execution tasks in the task library and the processing duration of the execution tasks. The number of threads corresponding to each task library needs to ensure that all execution tasks in the task library can be completed within the interval duration corresponding to the task library, so that the threads in the thread pool can process all execution tasks in the current task library before the arrival of the timing trigger time corresponding to the adjacent task library, and prepare for the execution tasks in the adjacent task library. The situation that the execution tasks in the adjacent task library are triggered while the execution tasks in the current task library are not completed is avoided.
[0077] Step S320: determining the maximum number of threads based on the number of threads required by each task library.
[0078] In the embodiment of the present application, after the computer device determines the number of threads corresponding to each task library, the computer device can take the maximum number of threads in all the numbers of threads as the size of the thread pool, so that the thread pool can complete all execution tasks in the task library within the interval duration corresponding to the task library. By means of the same thread pool corresponding to all task libraries, that is, by means of one thread pool processing all execution tasks in all task libraries, the number of preset thread pools can be effectively reduced, the occupied space can be reduced, and the computing efficiency can be improved.
[0079] Step S330: creating the preset thread pool based on the maximum number of threads.
[0080] In the embodiment of the present application, after the computer device determines the maximum number of threads, the computer device can create a preset thread pool, which includes threads with the maximum number of threads. The preset thread pool can simultaneously process all execution tasks included in any one of all task libraries, and can complete the processing within the interval duration corresponding to the task library, so as to ensure that the thread pool is empty before the next timing trigger time, so as to continue to simultaneously process all execution tasks in the next task library.
[0081] Step S340: when the current time matches the timing trigger time corresponding to the target task library in the plurality of task libraries, all execution tasks in the target task library are assigned to the preset thread pool, wherein the timing trigger times of all execution tasks in each task library are the same.
[0082] Step S350: executing all execution tasks in the target task library by using threads in the preset thread pool.
[0083] In the embodiments of the present application, steps S340 and S350 can refer to the content of other embodiments, which will not be described here.
[0084] The management method of the timing triggered task provided in the embodiments of the present application determines the number of threads required by each task library based on the number and processing time length of the execution tasks in each task library, determines the maximum number of threads based on the number of threads required by each task library, and creates a preset thread pool based on the maximum number of threads. Thus, when the current time matches the timing trigger time corresponding to the target task library, all execution tasks in the target task library are executed by using threads in the preset thread pool. The number of threads in the preset thread pool is determined based on the number of threads required by each task library, so that the preset thread pool can complete all execution tasks in any task library within an interval time length, which realizes processing of the execution tasks in all task libraries based on one thread pool, reduces the storage space required by the thread pool, and improves the processing efficiency of the execution tasks.
[0085] Please refer to Figure 7 which shows a structural block diagram of a management device 100 of a timing triggered task provided in the embodiments of the present application. The device includes a task trigger module 110 and a task execution module 120. The task trigger module is configured to assign all execution tasks in a target task library to a preset thread pool when the current time matches the timing trigger time corresponding to the target task library in a plurality of task libraries, and the timing trigger time of all execution tasks in each task library is the same. The task execution module is configured to execute all execution tasks in the target task library by using threads in the preset thread pool.
[0086] As a possible implementation, the management device 100 of the timing triggered task includes a task library creation module, a task assignment module, and a trigger configuration module. The task library creation module is configured to create a plurality of task libraries in advance. The task assignment module is configured to store each execution task in the plurality of task libraries according to the timing trigger time corresponding to the execution task, and the timing trigger time of all execution tasks in each task library is the same. The trigger configuration module is configured to configure a trigger for each task library according to the timing trigger time of the execution tasks in the task library, and the trigger is configured to trigger execution of all execution tasks in the task library corresponding to the trigger when the current time matches the timing trigger time of the execution tasks in the task library.
[0087] As a possible implementation, the task library creation module comprises an interval time acquisition unit and a task library construction unit. The interval time acquisition unit is configured to acquire a trigger interval time corresponding to each execution task in all execution tasks to be executed. The task library construction unit is configured to construct a plurality of task libraries based on the trigger interval time corresponding to each execution task, and the number of the plurality of task libraries is determined according to the trigger interval time, and each task library corresponds to a different timing trigger time.
[0088] As a possible implementation, the task library construction unit is configured to determine a minimum interval time in the trigger interval times of all execution tasks to be executed based on the trigger interval time corresponding to each execution task. The target number of task libraries to be constructed is determined based on the minimum interval time. A plurality of task libraries with the target number are created, and each task library is associated with a different timing trigger time according to the timing trigger time of each execution task.
[0089] As a possible implementation, the management device 100 of the timing trigger task further comprises a thread pool construction module. The thread pool construction module is configured to construct a thread pool with a corresponding number of threads for each task library based on the number of execution tasks in each task library and the processing duration. The task trigger module is further configured to assign all execution tasks in a target task library in the plurality of task libraries to a thread pool corresponding to the target task library when the current time matches the timing trigger time corresponding to the target task library.
[0090] As a possible implementation, the management device 100 of the timing trigger task further comprises a thread number determination module, a maximum number determination module, and a thread pool creation module. The thread number determination module is configured to determine the number of threads required for each task library based on the number of execution tasks in each task library and the processing duration. The maximum number determination module is configured to determine a maximum number of threads based on the number of threads required for each task library. The thread pool creation module is configured to create the preset thread pool based on the maximum number of threads.
[0091] As a possible implementation, the thread quantity determination module comprises: a task library ordering unit, an interval duration determination unit, and a thread quantity determination unit. The task library ordering unit is configured to order the plurality of task libraries according to the timing trigger time of executing tasks in each task library, in the order from the earliest to the latest, to obtain an ordering result; the interval duration determination unit is configured to determine the interval duration between the timing trigger time of executing tasks in each task library and the timing trigger time of executing tasks in a task library after the task library in the ordering result, to obtain the interval duration corresponding to each task library; and the thread quantity determination unit is configured to, for each task library, determine the thread quantity required for executing all executing tasks in each task library within the interval duration corresponding to each task library, as the thread quantity required by each task library, based on the number of executing tasks in each task library and the processing duration.
[0092] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described devices and modules can refer to the corresponding process in the foregoing method embodiments, which will not be described here.
[0093] In several embodiments provided in the present application, the coupling between the modules can be electrical, mechanical or other forms of coupling.
[0094] In addition, each functional module in each embodiment of the present application can be integrated in one processing module, or each module can exist physically independently, or two or more modules can be integrated in one module. The integrated module can be realized in the form of hardware or in the form of a software functional module.
[0095] In summary, in the management method of the timing trigger task provided in the present application, all executing tasks are allocated to task libraries with different timing trigger times based on the different timing trigger times corresponding to the executing tasks, and then all executing tasks in the target task library are allocated to the preset thread pool when the current time matches the timing trigger time corresponding to the target task library, so that all executing tasks in the target task library are executed by the threads in the preset thread pool. By managing the triggering of all executing tasks based on the timing trigger time corresponding to the task library, the number of triggers is reduced, and the management and maintenance of the executing tasks are more convenient.
[0096] Please refer to Figure 8FIG. 2 shows a structural block diagram of a computer device 200 according to an embodiment of the present application. The computer device 200 can be a server, a computer, a mobile terminal, or the like. The computer device 200 can include one or more of the following components: a processor 210, a memory 220, and one or more application programs stored in the memory 220 and configured to be executed by the processor 210. The one or more application programs are configured to perform the methods described in the foregoing method embodiments.
[0097] The processor 210 can include one or more processing cores. The processor 210 connects various parts within the computer device through various interfaces and lines, performs various functions of the computer device and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 220, and calling data stored in the memory 220. Alternatively, the processor 210 can be implemented in at least one of a hardware form of a digital signal processing (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor 210 can be integrated with a combination of one or more of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU is mainly used to process an operating system, a user interface, and an application program; the GPU is used to render and draw display content; and the modem is used to process wireless communication. It can be understood that the above-mentioned modem can also not be integrated into the processor 210, but can be implemented by a separate communication chip.
[0098] The memory 220 can include a random access memory (RAM) and a read-only memory (ROM). The memory 220 can be used to store instructions, programs, codes, code sets, or instruction sets. The memory 220 can include a program storage area and a data storage area. The program storage area can store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing various method embodiments described below, etc. The data storage area can also store data created by the computer device in use (such as a phone book, audio and video data, chat record data), etc.
[0099] Reference is made to Figure 9FIG. 8 shows a structural block diagram of a computer readable storage medium according to an embodiment of the present application. The computer readable medium 800 stores program codes, which can be invoked by a processor to execute the methods described in the above method embodiments.
[0100] The computer readable storage medium 800 can be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Alternatively, the computer readable storage medium 800 comprises a non-transitory computer readable medium. The computer readable storage medium 800 has a storage space for program codes 810 to execute any of the above methods. These program codes can be read from or written to one or more computer program products. The program codes 810 can be compressed in a suitable form, for example.
[0101] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than limit the same. Even though the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalent replacements. Such modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A management method of a timing trigger task, characterized by, The method comprises: pre-creating a plurality of task libraries; storing each execution task in a corresponding task library according to the timing trigger time corresponding to each execution task in all execution tasks to be executed, wherein the timing trigger times of all execution tasks in the same task library are the same; configuring a trigger for each task library according to the timing trigger time of the execution task in the task library, wherein the trigger is used to trigger all execution tasks in the corresponding task library when the current time matches the timing trigger time of the execution task in the corresponding task library; allocating all execution tasks in a target task library to a preset thread pool when the current time matches the timing trigger time corresponding to the target task library in the plurality of task libraries, wherein the timing trigger times of all execution tasks in each task library are the same; executing all execution tasks in the target task library by using threads in the preset thread pool; wherein, before the step of allocating all execution tasks in the target task library to the preset thread pool when the current time matches the timing trigger time corresponding to the target task library in the plurality of task libraries, the method further comprises: sorting the plurality of task libraries according to the timing trigger time of the execution task in each task library in the order from early to late to obtain a sorting result; determining the interval duration between the timing trigger time of the execution task in each task library and the timing trigger time of the execution task in the task library after the sorting result to obtain the interval duration corresponding to each task library; determining the number of threads required for executing all execution tasks in each task library within the interval duration corresponding to each task library as the number of threads required by each task library based on the number of execution tasks and the processing duration in each task library; determining the maximum number of threads based on the number of threads required by each task library; creating the preset thread pool based on the maximum number of threads, wherein the number of threads in the preset thread pool is equal to the maximum number of threads.
2. The method of claim 1, wherein, The pre-creating a plurality of task libraries comprises: obtaining the trigger interval time corresponding to each execution task in all execution tasks to be executed; constructing a plurality of task libraries based on the trigger interval time corresponding to each execution task, wherein the number of the plurality of task libraries is determined according to the trigger interval time, and each task library corresponds to different timing trigger times.
3. The method of claim 2, wherein, The constructing a plurality of task libraries based on the trigger interval time corresponding to each execution task comprises: determining the minimum interval time in the trigger interval time of all execution tasks to be executed based on the trigger interval time corresponding to each execution task; determining the target number of task libraries to be constructed based on the minimum interval time; creating a plurality of task libraries with the target number, and associating each task library with different timing trigger times according to the timing trigger time of each execution task.
4. The method according to any one of claims 1 to 3, characterized in that, Before the all execution tasks in the target task library are assigned to the preset thread pool when the current time matches the timing trigger time corresponding to the target task library in the plurality of task libraries, the method further comprises: A thread pool of a corresponding thread quantity is constructed for each task library based on the quantity of execution tasks in the each task library and the processing duration; The all execution tasks in the target task library are assigned to the thread pool corresponding to the target task library when the current time matches the timing trigger time corresponding to the target task library in the plurality of task libraries. The all execution tasks in the target task library are assigned to the thread pool corresponding to the target task library when the current time matches the timing trigger time corresponding to the target task library in the plurality of task libraries.
5. A management apparatus of a timing trigger task, characterized by, The device comprises a task trigger module, a task execution module, a task library creation module, a task assignment module, a trigger configuration module, a thread quantity determination module, a maximum quantity determination module and a thread pool creation module, wherein, The task library creation module is configured to create a plurality of task libraries in advance; The task assignment module is configured to store each execution task in the all execution tasks to be executed into a corresponding task library in the plurality of task libraries according to the timing trigger time corresponding to the each execution task, wherein the timing trigger times of all execution tasks in a same task library are the same; The trigger configuration module is configured to configure a trigger for each task library according to the timing trigger time of the execution tasks in the each task library, the trigger being configured to trigger all execution tasks in the task library corresponding to the trigger when the current time matches the timing trigger time of the execution tasks in the task library corresponding to the trigger; The task trigger module is configured to assign all execution tasks in a target task library to a preset thread pool when the current time matches the timing trigger time corresponding to the target task library in the plurality of task libraries, wherein the timing trigger times of all execution tasks in each task library are the same; The task execution module is configured to execute all execution tasks in the target task library by using threads in the preset thread pool; The thread quantity determination module is configured to sort the plurality of task libraries according to the timing trigger time from early to late to obtain a sorting result according to the timing trigger time of the execution tasks in each task library, determine an interval duration between the timing trigger time of the execution tasks in the each task library and the timing trigger time of the execution tasks in a task library after the each task library in the sorting result, obtain an interval duration corresponding to the each task library, and determine the thread quantity required for executing all execution tasks in the each task library within the interval duration corresponding to the each task library as the thread quantity required by the each task library based on the quantity of execution tasks in the each task library and the processing duration; The maximum quantity determination module is configured to determine a maximum thread quantity based on the thread quantity required by each task library; The thread pool creation module is configured to create the preset thread pool based on the maximum thread quantity, and the thread quantity of the preset thread pool is equal to the maximum thread quantity.
6. A computer device, comprising: The computer device comprises, comprising: one or more processors; a memory; one or more application programs, wherein the one or more application programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs are configured to execute the method of any one of claims 1-4.
7. A computer-readable storage medium, characterized in that, The computer readable storage medium stores program code, and the program code can be called and executed by the processor to execute the method of any one of claims 1-4.
Citation Information
Patent Citations
Electronic insurance policy generating method and apparatus, computer device and storage medium
CN107918864A
Timed task processing method and related equipment
CN112433833A