A multi-tasking method, system and medium
By proportionally decomposing system tasks into subtasks in the task library, and utilizing multi-threaded parallel processing and restart mechanisms, the problem of task accumulation and abnormal restarts is solved, and efficient task execution and frequency improvement are achieved.
Patent Information
- Application Number
- CN202011622611.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-30
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2040-12-30
AI Technical Summary
Existing technology cannot effectively solve the problem of task accumulation and abnormal system restart caused by producers processing faster than consumers, resulting in some tasks being unable to be executed and falling into an infinite loop.
By extracting the metadata of system tasks from the task library, decompose them into subtasks in proportion, and execute them in the task queue. Multi-thread parallel processing and the unique access key mechanism are used to prioritize subtasks, record the execution status, and start the restart program based on the status. , and adjust task priorities to keep the execution progress deviation within the threshold range.
It achieves reasonable decomposition and efficient execution of tasks, increases the running frequency of system tasks, reduces the running risks of long tasks, and avoids abnormal restart loops caused by task accumulation.
Smart Images

Figure CN112732424B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of task processing, and in particular to a multi-task processing method, system and medium. Background Art
[0002] In computer applications, there are often many task units at the business logic level, and some of these tasks are relatively large and can be divided into a series of subtasks. In the entire process of the program processing all tasks, there is generally such a process: the producer stores all tasks in the task queue, and the consumer reads the tasks from the task queue for processing. Among them, the producer refers to the module that produces tasks; the consumer refers to the module that processes tasks; the task queue is the container for storing tasks, and as a queue, it has the characteristics of first-in-first-out. The generator generates tasks and puts them into the queue, and the consumer obtains tasks from the queue for processing. System resources usually include operating system resources, such as CPU, memory, etc.; they also include business system resources, such as task processors, thread pools and other program-level task processing units.
[0003] When the program is processing the task queue, the processing speed of the consumer may not catch up with the processing speed of the producer, resulting in task accumulation, and the system running abnormally, causing the program to restart manually or automatically. In extreme cases, there may be a cycle like this: the producer creates tasks -> adds them to the task queue -> the consumer consumes the queue -> tasks accumulate -> the system restarts abnormally -> the producer creates tasks. As a result, some of the tasks that were added to the queue first are executed, while the tasks that were added later will never be executed, that is, the tasks are starved, causing the program to be stuck in an endless loop state of abnormal restart. The existing operating system thread scheduling method and CPU time slicing method obviously cannot solve the above problems. Summary of the invention
[0004] The purpose of the present invention is to provide a multi-task processing solution to solve the above technical problems existing in the prior art.
[0005] A first aspect of the present invention provides a multi-task processing method, the method comprising: step S1, based on the metadata of the system tasks stored in the task library, extracting some subtasks from each of the system tasks in proportion to the task queue, the system task is associated with at least one independent subtask; step S2, reading the extracted subtasks in the task queue to execute processing, and recording the execution status of the processing; and step S3, based on the execution status, starting a restart program; wherein the metadata is the number of subtasks associated with the system task.
[0006] According to the method provided in the first aspect of the present invention, in the step S2, executing the processing includes executing the extracted subtasks in parallel by multiple threads, and when a plurality of the extracted subtasks synchronously access the same object, the subtask that obtains the unique access key of the object has priority to access the object.
[0007] According to the method provided in the first aspect of the present invention, the step S3 specifically includes: when any of the execution states is an abnormal state, starting the restart program; and after the restart program is executed, preferentially executing the system task whose execution state is an abnormal state; wherein determining that the execution state is an abnormal state includes: obtaining the execution time of the extracted subtask, and when the execution time is greater than a first threshold and the execution state of the extracted subtask is incomplete, determining that the execution state is an abnormal state.
[0008] According to the method provided in the first aspect of the present invention, the method also includes: based on the execution status of the extracted subtasks of each of the system tasks, updating the ratio so that the execution progress deviation of each of the system tasks is within a threshold range; wherein: after the currently extracted subtask is executed, lowering the execution priority of the system task associated with the currently extracted subtask; and after all the extracted subtasks are executed, restoring the execution priority to reallocate the ratio of extracting some subtasks from each of the system tasks in the next round.
[0009] A second aspect of the present invention provides a multi-task processing system, the system comprising: an extraction unit, configured to extract part of the subtasks from each of the system tasks in proportion to a task queue based on the metadata of the system tasks stored in a task library, wherein the system tasks are associated with at least one independent subtask; an execution unit, configured to read the extracted subtasks in the task queue to perform processing and record the execution status of the processing; and a restart unit, configured to update the proportion or start a restart program based on the execution status; wherein the metadata is the number of subtasks associated with the system task.
[0010] According to the system provided by the second aspect of the present invention, the execution unit is specifically configured to execute the processing including multi-threaded parallel execution of the extracted subtasks. When a plurality of the extracted subtasks synchronously access the same object, the subtask that obtains the unique access key of the object has priority to access the object.
[0011] According to the system provided by the second aspect of the present invention, the restart unit is specifically configured to: start the restart program when any of the execution states is an abnormal state; and after the restart program is executed, preferentially execute the system task whose execution state is an abnormal state; wherein determining that the execution state is an abnormal state includes: obtaining the execution time of the extracted subtask, and when the execution time is greater than a first threshold and the execution state of the extracted subtask is incomplete, determining that the execution state is an abnormal state.
[0012] According to the system provided by the second aspect of the present invention, the system also includes an updating unit, which is configured to update the ratio based on the execution status of the extracted subtasks of each of the system tasks so that the execution progress deviation of each of the system tasks is within a threshold range; wherein: after the currently extracted subtask is executed, the execution priority of the system task associated with the currently extracted subtask is lowered; and after all the extracted subtasks are executed, the execution priority is restored to reallocate the ratio of extracting some subtasks from each of the system tasks in the next round.
[0013] A third aspect of the present invention provides a non-transitory computer-readable medium storing instructions, which, when executed by a processor, executes the steps of the multitasking method according to the first aspect of the present invention.
[0014] In summary, this solution can decompose tasks into a reasonable number of subtasks. Each time a task is started, each task only adds a certain proportion of subtasks that have not been executed to the task queue. After the task is executed, the status of these subtasks is recorded, so that all tasks can be run. This increases the running frequency of each system task and reduces the running risk of long tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0016] Figure 1 A schematic diagram of a multi-tasking processing method according to an embodiment of the present invention; and
[0017] Figure 2 FIG. 4 is a structural diagram of a multi-tasking processing system according to an embodiment of the present invention. DETAILED DESCRIPTION
[0018] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0019] A first aspect of the present invention provides a multi-task processing method. Figure 1 FIG. 1 is a schematic diagram of a multi-task processing method according to an embodiment of the present invention. Figure 1 As shown, the method 100 includes: step S1, based on the metadata of the system tasks stored in the task library, extracting some subtasks from each of the system tasks in proportion to the task queue, and the system task is associated with at least one independent subtask; step S2, reading the extracted subtasks in the task queue to perform processing, and recording the execution status of the processing; and step S3, based on the execution status, starting a restart program; wherein the metadata is the number of subtasks associated with the system task.
[0020] In step S1, based on the metadata of the system tasks stored in the task library, some subtasks are proportionally extracted from each of the system tasks to the task queue, and the system tasks are associated with at least one independent subtask. The metadata is the number of subtasks associated with the system tasks. Specifically, after starting the application, first, the system tasks are stored in the task library, and each task is associated with an independent subtask. Subsequently, the task metadata, that is, the number of subtasks associated with each system task, is read, the system tasks are sliced, and certain subtasks are proportionally extracted from each task and added to the task queue. This ensures that each system task can be executed.
[0021] In step S2, the extracted subtasks in the task queue are read to execute processing, and the execution status of the processing is recorded. Executing the processing includes executing the extracted subtasks in parallel with multiple threads. When multiple extracted subtasks synchronously access the same object, the subtask that obtains the unique access key of the object has priority to access the object.
[0022] When processing subtasks, the extracted subtasks are executed in parallel with multiple threads. When multiple extracted subtasks access the same object synchronously, the wait() function can be called to achieve this. Specifically, there is a synchronization model in Java - monitor, which is responsible for managing the access of threads to the synchronization methods in the object. Its principle is: give the object a unique key. When multiple threads enter the object, only the thread that obtains the key of the object can access the synchronization method. Other threads wait in the object until the thread gives up the key with the wait() method. Other waiting threads seize the key. The thread that seizes the key can be executed, while the thread that does not obtain the key is still blocked in the object waiting, so that only one thread can enter the critical code area. Note that the producer only produces when the warehouse is not full, and the producer process is blocked when the warehouse is full; the consumer only consumes when the warehouse is not empty, and the consumer process is blocked when the warehouse is empty.
[0023] In step S3, based on the execution status, a restart program is started. Specifically, when any of the execution statuses is an abnormal state, the restart program is started; and after the restart program is executed, the system task whose execution status is an abnormal state is preferentially executed; wherein determining that the execution status is an abnormal state includes: obtaining the execution time of the extracted subtask, and when the execution time is greater than a first threshold and the execution status of the extracted subtask is incomplete, determining that the execution status is an abnormal state.
[0024] When any of the execution states is abnormal (e.g., starvation), that is, the system task associated with the executed subtask enters an infinite loop and has not been executed for a long time, resulting in a backlog of tasks in the task queue, the system can be restarted. Application system tasks are generally long tasks, which can easily cause abnormal states such as system pseudo-death during execution. By using the task slicing method to divide the execution cycle of each long task, the running frequency of each task is greatly increased and the running risk of long tasks is reduced.
[0025] In some embodiments, the method further includes: based on the execution status of the extracted subtasks of each of the system tasks, updating the ratio so that the execution progress deviation of each of the system tasks is within a threshold range; specifically, based on the execution status, determining whether the extracted subtasks in each system task are executed evenly; if the extracted subtasks in individual system tasks are executed too fast or too slow, that is, the execution progress deviation exceeds the threshold range, adjusting the extraction ratio.
[0026] In some embodiments, after the currently extracted subtask is executed, the execution priority of the system task associated with the currently extracted subtask is lowered; and after all the extracted subtasks are executed, the execution priority is restored to reallocate the proportion of extracting some subtasks from each of the system tasks in the next round.
[0027] A second aspect of the present invention provides a multi-tasking processing system. Figure 2 is a structural diagram of a multi-task processing system according to an embodiment of the present invention, such as Figure 2 As shown, the system 200 includes: an extraction unit 201, configured to extract part of the subtasks from each of the system tasks in proportion to a task queue based on the metadata of the system tasks stored in the task library, and the system tasks are associated with at least one independent subtask; an execution unit 202, configured to read the extracted subtasks in the task queue to perform processing and record the execution status of the processing; and a restart unit 203, configured to update the proportion or start a restart program based on the execution status; wherein the metadata is the number of subtasks associated with the system task.
[0028] According to the system provided by the second aspect of the present invention, the execution unit 202 is specifically configured to execute the processing including multi-threaded parallel execution of the extracted subtasks. When multiple extracted subtasks access the same object synchronously, the subtask that obtains the unique access key of the object has priority to access the object.
[0029] According to the system provided by the second aspect of the present invention, the restart unit 203 is specifically configured to: when any of the execution states is an abnormal state, start the restart program; and after the restart program is executed, give priority to executing the system task whose execution state is an abnormal state; wherein determining that the execution state is an abnormal state includes: obtaining the execution time of the extracted subtask, and when the execution time is greater than a first threshold and the execution state of the extracted subtask is incomplete, determining that the execution state is an abnormal state.
[0030] According to the system provided by the second aspect of the present invention, the system also includes an updating unit 204, which is configured to update the ratio based on the execution status of the extracted subtasks of each of the system tasks so that the execution progress deviation of each of the system tasks is within a threshold range; wherein: after the currently extracted subtask is executed, the execution priority of the system task associated with the currently extracted subtask is lowered; and after all the extracted subtasks are executed, the execution priority is restored to reallocate the ratio of extracting some subtasks from each of the system tasks in the next round.
[0031] A third aspect of the present invention provides a non-transitory computer-readable medium storing instructions, which, when executed by a processor, executes the steps of the multitasking method according to the first aspect of the present invention.
[0032] In summary, the various aspects of the present disclosure can decompose a task into a reasonable number of subtasks. Each time a task is started, each task only adds a certain proportion of subtasks that have not been executed to the task queue. After the task is executed, the status of these subtasks is recorded, so that all tasks can be run. This increases the running frequency of each system task and reduces the running risk of long tasks. It solves the problem of a dead loop in which a program task is abnormally restarted after a task pileup.
[0033] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A multitasking method, characterized in that: The method comprises: Step S1, based on the metadata of the system tasks stored in the task library, extracting some subtasks from each of the system tasks in proportion to the task queue, wherein the system task is associated with at least one independent subtask; Step S2, reading the extracted subtask in the task queue to execute processing, and recording the execution status of the processing; In the step S2, executing the processing includes executing the extracted subtasks in parallel in multiple threads, and when multiple extracted subtasks synchronously access the same object, the subtask that obtains the unique access key of the object has priority to access the object; Step S3, starting a restart procedure based on the execution status; The metadata is the number of subtasks associated with the system task; The step S3 specifically includes: When any of the execution states is an abnormal state, starting the restart procedure; and After the restart program is executed, the system task whose execution status is abnormal is executed first; Wherein determining that the execution state is an abnormal state comprises: Acquire the execution time of the extracted subtask, and when the execution time is greater than a first threshold and the execution status of the extracted subtask is incomplete, determine that the execution status is an abnormal state; The method further includes, based on the execution status of the extracted subtasks of each of the system tasks, updating the ratio so that the execution progress deviation of each of the system tasks is within a threshold range; in: After the currently extracted subtask is executed, lowering the execution priority of the system task associated with the currently extracted subtask; and After all the extracted subtasks are executed, the execution priority is restored to reallocate the proportion of extracting some subtasks from each of the system tasks in the next round.
2. A multi-tasking processing system, characterized in that: The system comprises: An extraction unit is configured to extract part of subtasks from each of the system tasks to the task queue in proportion based on metadata of the system tasks stored in the task library, wherein the system tasks are associated with at least one independent subtask; an execution unit configured to read the extracted subtask in the task queue to execute processing, and record the execution status of the processing; The execution unit is specifically configured to execute the processing including executing the extracted subtasks in parallel by multiple threads, and when multiple extracted subtasks synchronously access the same object, the subtask that obtains the unique access key of the object has priority to access the object; a restart unit, configured to start a restart procedure based on the execution state; The metadata is the number of subtasks associated with the system task; The restart unit is specifically configured as follows: When any of the execution states is an abnormal state, starting the restart procedure; and After the restart program is executed, the system task whose execution status is abnormal is executed first; Wherein determining that the execution state is an abnormal state comprises: Acquire the execution time of the extracted subtask, and when the execution time is greater than a first threshold and the execution status of the extracted subtask is incomplete, determine that the execution status is an abnormal state; The system further includes an updating unit configured to update the ratio based on the execution status of the extracted subtasks of each of the system tasks so that the execution progress deviation of each of the system tasks is within a threshold range; wherein: After the currently extracted subtask is executed, lowering the execution priority of the system task associated with the currently extracted subtask; and After all the extracted subtasks are executed, the execution priority is restored to reallocate the proportion of extracting some subtasks from each of the system tasks in the next round.
3. A non-transitory computer-readable medium storing instructions, which, when executed by a processor, executes the steps in the multitasking method according to claim 1.
Citation Information
Patent Citations
ETL (Extraction-Transformation-Loading) dispatching system and method for error-correction restarting and automatic-judgment starting
CN103034554A
Batch rights and interests data processing method and device
CN111679920A
