A task processing method, device, equipment and medium

By pre-processing part of the execution phase in the task queue, the problem of long queue task processing time is solved, and the task processing efficiency is improved and the queue throughput is increased.

CN113918307BActive Publication Date: 2025-09-30BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111299782.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-04
Publication Date
2025-09-30
Estimated Expiration
2041-11-04

AI Technical Summary

Technical Problem

In the existing technology, queues can only execute tasks serially, resulting in long task processing time and low efficiency. This becomes a bottleneck, especially in applications with multiple queued tasks and requirements on task completion time.

Method used

Before the task is at the head of the queue, the first execution stage of the task is processed in advance, and the unfinished second execution stage is processed when the task is at the head of the queue, and independent threads are used to perform parallel processing of some execution stages.

Benefits of technology

By pre-processing part of the execution phase while the task is waiting in the queue, the total processing time when the task reaches the head of the queue is shortened, and the task processing efficiency and queue throughput are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113918307B_ABST
    Figure CN113918307B_ABST
Patent Text Reader

Abstract

The disclosed embodiments relate to a task processing method, apparatus, device, and medium, wherein the method comprises: obtaining a target task from a target queue; wherein the target queue contains multiple serial tasks to be executed, and the target task comprises at least two execution phases; before the target task is placed at the top of the target queue, pre-processing the first execution phase of the target task; and when the target task is placed at the top of the target queue, processing the unprocessed second execution phase of the target task. The disclosed embodiments can effectively shorten the total time required for task processing and improve task processing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a task processing method, apparatus, device, and medium. Background Art

[0002] A queue is a common data structure that can contain multiple serial tasks to be executed. It uses the FIFO (First Input First Output) principle, meaning new tasks are always inserted at the end of the queue, and tasks are read and executed starting from the head of the queue. Each time a task is read, a new task is released from the queue. Conventional queues can only execute one task at a time; the next task can only be executed after the current task completes.

[0003] From an external perspective, the time it takes to process a task is equal to the time the task waits in the queue plus the time it takes for the task to be completed after it reaches the top of the queue and obtains the execution right. Therefore, it takes a long time to complete a task, and task processing is relatively inefficient. Summary of the Invention

[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a task processing method, apparatus, device and medium.

[0005] An embodiment of the present disclosure provides a task processing method, which includes: obtaining a target task in a target queue; wherein the target queue contains multiple serial tasks to be executed, and the target task contains at least two execution stages; before the target task is located at the first place in the target queue, pre-processing the first execution stage of the target task; when the target task is located at the first place in the target queue, processing the unprocessed second execution stage of the target task.

[0006] Optionally, the step of obtaining the target task in the target queue includes: determining a candidate task including at least two execution stages from a plurality of tasks to be executed in the target queue; and selecting at least one target task from the candidate tasks according to a preset task selection strategy.

[0007] Optionally, the task selection strategy includes one of the following: taking all candidate tasks as target tasks; taking candidate tasks selected by the user as target tasks; taking candidate tasks with a specified stage as target tasks; taking candidate tasks of a specified category as target tasks.

[0008] Optionally, the number of the target tasks is at least two; the step of pre-processing the first execution stage of the target tasks includes: processing at least two of the target tasks in parallel to complete the first execution stage of each of the target tasks.

[0009] Optionally, before the step of obtaining the target task in the target queue, the method also includes: in response to receiving the task to be executed, obtaining user-defined task allocation logic, and determining the target queue corresponding to the task to be executed based on the task allocation logic; placing the task to be executed at the tail of the target queue.

[0010] Optionally, the step of pre-processing the first execution stage of the target task includes: obtaining user-defined queue pre-processing logic; using an independent thread created outside the main thread to execute the queue pre-processing logic, so as to pre-process the first execution stage of the target task through the queue pre-processing logic to obtain a processing result; wherein, the main thread is a thread used to execute the first task of the target queue.

[0011] Optionally, the step of processing the unprocessed second execution stage of the target task includes: obtaining a user-defined main queue processing logic; obtaining a processing result obtained by the queue preprocessing logic; and using the main thread to execute the main queue processing logic based on the processing result, so as to process the unprocessed second execution stage of the target task through the main queue processing logic.

[0012] An embodiment of the present disclosure also provides a task processing device, including: a task acquisition module, used to acquire a target task in a target queue; wherein the target queue contains multiple serial tasks to be executed, and the target task contains at least two execution stages; a first processing module, used to pre-process the first execution stage of the target task before the target task is located at the first place in the target queue; and a second processing module, used to process the unprocessed second execution stage of the target task when the target task is located at the first place in the target queue.

[0013] An embodiment of the present disclosure also provides an electronic device, which includes: a processor; a memory for storing instructions executable by the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the task processing method provided by the embodiment of the present disclosure.

[0014] An embodiment of the present disclosure further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is used to execute the task processing method provided by the embodiment of the present disclosure.

[0015] The above technical solution provided by the embodiment of the present disclosure can obtain the target task (including at least two execution stages) in the target queue; then, before the target task is at the head of the target queue, the first execution stage of the target task is pre-processed; and when the target task is at the head of the target queue, the second execution stage that has not been processed in the target task is processed. The above method can make full use of the queuing time of the target task, and process a part of the execution stages (that is, the aforementioned first execution stage) contained in the target task while the target task is waiting in the queue. When the target task is at the head of the queue, only the remaining second execution stage that has not been processed needs to be processed, thereby shortening the processing time required when the target task is at the head of the queue. Therefore, the above method can effectively shorten the total time consumed by task processing and improve task processing efficiency.

[0016] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0018] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0019] Figure 1 A flowchart of a task processing method provided by an embodiment of the present disclosure;

[0020] Figure 2 A schematic diagram of a task processing flow provided by an embodiment of the present disclosure;

[0021] Figure 3 A flowchart of another task processing method provided by an embodiment of the present disclosure;

[0022] Figure 4 A schematic diagram of the structure of a task processing device provided in an embodiment of the present disclosure;

[0023] Figure 5 A schematic structural diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0024] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features therein can be combined with each other in the absence of conflict.

[0025] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.

[0026] In the prior art, the actual total time consumed by serial tasks in a queue can be considered as the cumulative time consumed by waiting and processing. When there are many tasks in the queue, it takes a long time to complete the tasks, resulting in low task processing efficiency. This is especially true for applications such as online collaborative editing, which typically have multiple queued tasks and have requirements for task completion time. Low task processing efficiency can cause bottlenecks in the application, directly affecting application performance and reducing user experience. To improve the above problems, the present disclosure provides a task processing method, apparatus, device, and medium, which are described in detail below:

[0027] Figure 1 This is a flow chart of a task processing method provided by an embodiment of the present disclosure. The method can be executed by a task processing device, wherein the device can be implemented using software and / or hardware and can generally be integrated into an electronic device. Figure 1 As shown, the method mainly includes the following steps S102 to S106:

[0028] Step S102: Obtain a target task in a target queue, wherein the target queue contains a plurality of serial tasks to be executed, and the target task contains at least two execution phases. The target task is one or more of the tasks to be executed.

[0029] The target queue contains multiple serial tasks to be executed, so there is a clear order in which tasks are executed, and the tasks are executed on a first-in-first-out basis. The later tasks in the queue will not be completed in priority over the earlier tasks. In actual applications, the number of target tasks can be one or more, and each target task contains at least two execution stages. The execution stages can also be understood as pre-divided execution steps or subtasks contained in the target task. It is understandable that when completing tasks, some tasks can be divided according to stages (or steps, subtasks), and then executed in stages. The specific division method is not limited in the embodiment of the present disclosure, and can be divided according to actual tasks or actual needs. The above steps mainly involve obtaining a target task containing at least two execution stages from a target queue containing multiple serial tasks to be executed.

[0030] Step S104: before the target task is placed at the head of the target queue, the first execution phase of the target task is pre-processed, wherein the first execution phase is a portion of the execution phases required to be executed by the target task.

[0031] Before the target task is at the head of the target queue, it is in a queue waiting state. In the prior art, tasks in a queue waiting state are not executed, but only tasks at the head of the queue are executed. Only the task at the head of the queue has the execution right. After the task is completed, the next task is executed. In the embodiment of the present disclosure, the first execution stage of the target task can be processed in advance while the target task is in the queue waiting state, so as not to waste the queue waiting time. Since the target task has been pre-processed while waiting in the queue, the time required for the target task to be executed when it reaches the head of the queue can be further shortened. Moreover, since the above method only processes part of the execution stage, the target task will not be fully executed while waiting in the queue. Ultimately, the subsequent stages can be executed to complete the task only when it reaches the head of the queue. Therefore, it still complies with the first-in-first-out principle, and the later tasks in the queue will not be completed before the previous tasks.

[0032] The embodiments of the present disclosure do not limit which one or several execution stages of the multiple execution stages that the target task needs to execute that the first execution stage is, that is, the embodiments of the present disclosure do not limit which part of the execution stage is specifically processed, nor do they limit the number of partial execution stages or the proportion of partial execution stages in the total execution stages. It can be determined specifically according to the task itself and the processing logic set by the user. In some embodiments, when the multiple execution stages included in the target task have an execution order, the above-mentioned pre-processed first execution stage can be determined according to the execution order, such as giving priority to the execution stage with a higher execution order. For example, task A includes three execution stages A1, A2 and A3, among which A1 is executed first and A3 is executed last. At this time, only A1 can be used as the first execution stage of task A during the waiting period in the queue, or A1 and A2 can be used together as the first execution stage of task A during the waiting period in the queue. It can be determined specifically according to the processing logic set by the user. In other embodiments, when there are execution stages that can be completed independently and execution stages that need to rely on the processing results of other execution stages among the multiple execution stages included in the target task, the execution stage that can be completed independently is used as the first execution stage for pre-processing, and the execution stage that needs to rely on the processing results of other execution stages is used as the second execution stage to be completed when the target task is queued to the head of the queue.

[0033] In addition, in other embodiments, if the target task includes more execution stages, or the execution time required for some execution stages is long, and the time required to complete all execution stages is greater than the waiting time in queue, then before the target task is at the head of the target queue, it can be executed in sequence according to the order of the multiple execution stages until the target task is at the head of the queue. If the target task includes fewer execution stages, or the execution time required for the first execution stage is short, and the time required to complete all execution stages is shorter than the waiting time in queue, then before the target task is at the head of the target queue, only the specified first execution stage can be completed, or only the first execution stage can be executed in the order of the multiple execution stages, and the number or proportion of the first execution stage can be preset. Regardless of the implementation method, since the target queue includes serial tasks, all execution stages of the target task cannot be completed while the target task is waiting in queue, but it is necessary to ensure that there are unexecuted execution stages before the target task is at the head of the queue.

[0034] In addition, it should be noted that when the first execution phase of the target task is pre-processed before the target task is placed at the top of the target queue, other tasks at the top of the target queue are also being executed simultaneously. In actual applications, an additional thread independent of the main thread (queue processing thread) can be created to pre-process the first execution phase.

[0035] Step S106: When the target task is at the top of the target queue, the unprocessed second execution phase of the target task is processed. The second execution phase may be the remaining execution phases of the target task except the first execution phase.

[0036] In some implementations, a processing result obtained by processing the first execution stage before the target task is located at the top of the target queue may be obtained, and then the unprocessed second execution stage of the target task may be processed based on the processing result.

[0037] The above method can make full use of the queuing time of the target task. When the target task is waiting in the queue, a part of the execution stage it contains (that is, the aforementioned first execution stage) is processed. When the target task is ranked at the head of the queue, only the remaining second execution stage that has not been processed needs to be processed, thereby shortening the processing time required when the target task is ranked at the head of the queue. Therefore, the above method can effectively shorten the total time required for task processing and improve task processing efficiency.

[0038] For easier understanding, see Figure 2A task processing flow diagram is shown, in which a normal flow and an optimized flow are illustrated, wherein the normal flow is the conventional flow adopted in the prior art, and the optimized flow is the flow implemented by the task processing method of the embodiment of the present disclosure. Assume that task A can be divided into three execution stages, namely step 1, step 2 and step 3, wherein step 3 depends on the processing results of step 1 and step 2, while step 1 and step 2 are independent of each other. In the normal flow, when task A is ranked at the head of the queue and obtains the queue execution right, step 1, step 2 and step 3 are executed in sequence. In the optimized flow, the logic of step 1 can be put into the process when task A is waiting in the queue, and then step 2 is directly executed when task A is ranked at the head of the queue and obtains the queue execution right. After executing step 2 and waiting for the execution result of step 1 to return, step 3 is executed. Since step 1 starts to execute when the queue is in line, compared to the normal flow, if the current state is high-loaded and there are tasks waiting in the queue, the optimized flow can effectively improve the task processing performance. It should be noted that the above is only an example. In the above example, the processing time of step 1 is longer than the waiting time of task A in queue. If the processing time of step 1 is shorter than the waiting time of task A in queue, step 2 can be continued after step 1 is completed during the waiting period. In actual applications, the part of the execution stage that the task needs to be processed during the waiting period can be set according to the task itself, and there is no restriction here.

[0039] In some implementations, the above step S102, i.e., the step of obtaining the target task in the target queue, can be implemented by referring to the following steps a and b:

[0040] Step a: Determine candidate tasks that have at least two execution phases from among the multiple pending tasks in the target queue. It is understood that the target queue may contain multiple pending tasks, some of which may have only one execution phase, while others may be divided into multiple execution phases. In step a, pending tasks with multiple execution phases may be selected as candidate tasks to facilitate subsequent determination of the target task from among the candidate tasks.

[0041] Step b: Select at least one target task from the candidate tasks according to a preset task selection strategy. The task selection strategy is a method for selecting the target task from the candidate tasks. In some embodiments, the task selection strategy includes one of the following (1) to (4):

[0042] (1) All candidate tasks are taken as target tasks. That is, all tasks that include at least two (or more) execution phases can be taken as target tasks.

[0043] (2) Taking the candidate task selected by the user as the target task. That is, according to the user's needs, the task specified by the user that includes at least two execution stages can be taken as the target task.

[0044] (3) Selecting a candidate task with a specified stage as the target task. A candidate task contains multiple execution stages. The execution stages contained in different candidate tasks may be the same or different. A candidate task with a specified stage can be selected as the target task based on actual needs. The specified stage can be set by the user. For example, it can be an execution stage with a long processing time (longer than a specified time), an execution stage that can be executed independently without relying on the processing results of other stages, or an execution stage corresponding to a specified type of processing method, etc. There is no limitation here.

[0045] (4) Select candidate tasks of a specified category as target tasks. The categories of different tasks may be the same or different. Candidate tasks of a specified category may be selected as target tasks based on user needs. The candidate tasks of the specified category may be tasks with higher processing time requirements.

[0046] In order to further improve the task processing efficiency, when the number of target tasks is at least two, the above-mentioned step S104, that is, the step of pre-processing the first execution stage of the target task, includes: processing at least two target tasks in parallel to complete the first execution stage of each target task. Exemplarily, the target tasks waiting in the target queue include serial target tasks A, target tasks B, and target tasks C from front to back. While target tasks A, target tasks B, and target tasks C are waiting in the queue, the first execution stages of target tasks A, target tasks B, and target tasks C (that is, the stages that can be partially executed in advance) can be executed in parallel to further improve the task processing efficiency of the queue.

[0047] In practical applications, in order to facilitate the implementation of the task processing method provided by the embodiment of the present disclosure, users can pre-customize the task allocation logic, queue pre-processing logic, and main queue processing logic, which are explained below:

[0048] Task assignment logic can be implemented using key(), also known as a task dispatch function. To-be-executed tasks are assigned to a specific queue using the specified key attribute. In other words, task attributes, represented by keys, can be used as the basis for queue assignment. Tasks with the same key are assigned to the same queue for execution. This allows tasks with the same key to be processed serially, ensuring consistent task processing. In a specific implementation, key() returns a value, which is then used to assign tasks to the corresponding queue using hash routing.

[0049] The queue preprocessing logic can be implemented using the QueueProcess() function, which can also be called the queue preprocessing function. It is mainly the processing logic that runs asynchronously when the queue is waiting. By customizing the QueueProcess() function, users can set the specific implementation method of the above step S104 (pre-processing the first execution stage of the target task before the target task is at the top of the target queue) according to the actual application scenario and needs.

[0050] The main queue processing logic can be implemented using the Process() function, which can also be called the main queue processing function. It mainly reflects the processing logic of the task. The processing result of the QueueProcess() function can be written into a pipeline, and the processing result can be passed to the Process() function through the pipeline. The Process() function can use the processing result to improve the task processing performance.

[0051] On the basis of the foregoing, in some embodiments, before the step of obtaining the target task in the target queue, the embodiment of the present disclosure further provides the following method: in response to receiving the task to be executed, obtain the user-defined task allocation logic, and determine the target queue corresponding to the task to be executed based on the task allocation logic; place the task to be executed at the tail end of the target queue. Exemplarily, the task allocation logic is: obtain the attributes of the task to be executed, search in the memory to see if there is a queue that currently contains the attribute, if so, use the found queue as the target queue corresponding to the task to be executed; if not, create a new queue for the attribute, and use the created new queue as the target queue corresponding to the task to be executed. After determining the target queue, the task to be executed can be placed at the tail end of the target queue to queue for execution.

[0052] In some embodiments, the above-mentioned step of pre-processing the first execution stage of the target task includes: obtaining user-defined queue pre-processing logic; using an independent thread created outside the main thread to execute the queue pre-processing logic, so as to pre-process the first execution stage of the target task through the queue pre-processing logic to obtain a processing result; wherein, the main thread is a thread used to execute the first task of the target queue.

[0053] Compared with the related art of opening only one main thread to process queue tasks, and starting the next task after one task is completed, the embodiment of the present disclosure can create an independent thread in addition to the main thread, and execute the queue preprocessing logic through the independent thread, thereby realizing the preprocessing of part of the execution stage while the target task is waiting in queue.

[0054] In some embodiments, the above-mentioned step of processing the unprocessed second execution stage of the target task includes: obtaining user-defined main queue processing logic; obtaining the processing result obtained by the queue pre-processing logic; and using the main thread to execute the main queue processing logic based on the processing result, so as to process the unprocessed second execution stage of the target task through the main queue processing logic. Since part of the execution stage of the target task (i.e., the aforementioned first execution stage) has been processed by the independent thread, the main thread only needs to process the remaining execution stage (i.e., the second execution stage) based on the processing result of the independent thread. This can effectively shorten the main thread's processing time for the target task that currently has queue execution rights (i.e., the target task at the head of the queue), thereby improving the overall task processing efficiency.

[0055] Based on the above, the present disclosure provides the following Figure 3 The flowchart of another task processing method shown in FIG. mainly includes the following steps:

[0056] Step 1.0: Use the attributes of the pending task to find the target queue and determine whether it exists. If so, proceed to step 1.1; if not, proceed to step 1.2. In practice, when a pending task is received and dispatched, the first step is to determine whether the queue corresponding to the key exists.

[0057] Step 1.1: Add the task to be executed to the target queue found. Specifically, add the task to be executed to the end of the target queue and wait for the queue processing thread (also known as the main thread) to execute it. In some embodiments, the above thread can also be called a coroutine.

[0058] Step 1.1.1: Run the queue preprocessing function. The queue preprocessing function is also the aforementioned queue preprocessing logic, which can be implemented using a user-defined QueueProcess() function. In actual applications, you can create another thread independent of the main thread and use this independent thread to execute the queue preprocessing function. This thread can be an asynchronous thread. The queue preprocessing function can process part of the execution phase of the task to be executed and obtain the processing results. The processing results can be written into a pipe. Different threads can communicate / transfer information through the pipe. The pipe where the processing results are written can pass parameters to the Process() function so that the Process() function receives the processing results of the QueueProcess() function. The method of writing and transmitting processing results through the pipe is more flexible and convenient.

[0059] Step 1.2: Create a queue and initialize a queue processing thread. This thread can be an asynchronous thread.

[0060] Step 1.2.1: Read tasks from the queue. Specifically, the queue processing thread (main thread) will continuously read tasks from the queue.

[0061] Step 1.2.2: Run the main queue processing function. The main queue processing function is the main queue processing logic mentioned above and can be implemented using a user-defined Process() function.

[0062] After obtaining the pending task from the queue through step 1.2.1, the user-implemented main queue processing function (i.e., the Process() function) can be executed in step 1.2.2. After processing the task, the process returns to step 1.2.1 and then obtains the next pending task from the queue for processing. The next pending task was added to the queue through step 1.1, and so on, in a continuous cycle. In specific implementation, the Process() function can receive the processing results of the queue pre-processing function (i.e., the QueueProcess() function) in step 1.1.1 through a pipeline and further process the results based on them. This can shorten the task processing time of the Process() function and improve the processing performance of the Process() function, thereby comprehensively improving task efficiency.

[0063] In practical applications, the implementation framework for this task processing method can also be called a task dispatch queue framework. This framework requires only user-defined functions: Key(), Process(), and QueueProcess(). This allows asynchronous pre-processing of tasks while they are waiting in the queue, effectively improving task processing efficiency. These three functions can also be understood as user-defined interfaces that allow users to configure task dispatch logic, queue pre-processing logic, and main queue processing logic.

[0064] In summary, the task processing method provided by the embodiment of the present disclosure can provide the ability of queue waiting for concurrent processing, can make full use of the time that the task to be executed waits in the queue, and use an independent thread to pre-process part of the execution stage of the task, so as to shorten the time required for the task to be executed to be queued to the head of the queue and processed by the main thread, thereby improving the overall task processing efficiency and queue throughput, and effectively improving application performance. The above method can be well applied to a variety of occasions. For applications such as online collaborative editing, which usually have multiple queued tasks and have requirements on the time it takes to complete the task, it can significantly improve the performance of such applications. The following is an example of online collaborative editing: In the editing scenario of online collaborative tables, when the server processes user change requests, it needs to ensure that the editing requests of the same document are processed serially for the sake of concurrency safety. When the QPS (Query Per Second) of the editing request of a single document reaches a bottleneck threshold of the server's processing capacity, it will cause the request to be backlogged on the server and time out. Therefore, it is crucial to improve the processing performance of a single document. The task processing method provided by the embodiment of the present disclosure can fully improve the task processing efficiency, and the server's processing performance of a single document is significantly improved, which correspondingly increases the upper limit of the number of people that can be supported for single document collaboration.

[0065] Corresponding to the aforementioned task processing method, Figure 4 This is a structural diagram of a task processing device provided by an embodiment of the present disclosure. The device can be implemented by software and / or hardware and can generally be integrated into an electronic device, such as Figure 4 As shown, the task processing device mainly includes:

[0066] The task acquisition module 402 is used to acquire a target task in a target queue; wherein the target queue contains a plurality of serial tasks to be executed, and the target task includes at least two execution stages;

[0067] A first processing module 404 is configured to pre-process the first execution phase of the target task before the target task is placed at the top of the target queue;

[0068] The second processing module 406 is configured to process the unprocessed second execution phase of the target task when the target task is at the top of the target queue.

[0069] The above-mentioned device can make full use of the queuing time of the target task, and process a part of the execution stage (that is, the aforementioned first execution stage) contained in the target task while the target task is waiting in the queue. When the target task is ranked at the head of the queue, only the remaining second execution stage that has not been processed needs to be processed, thereby shortening the processing time required when the target task is ranked at the head of the queue. Therefore, the above-mentioned method can effectively shorten the total time required for task processing and improve task processing efficiency.

[0070] In some embodiments, the task acquisition module 402 is specifically used to: determine a candidate task including at least two execution stages from a plurality of tasks to be executed in the target queue; and select at least one target task from the candidate tasks according to a preset task selection strategy.

[0071] In some embodiments, the task selection strategy includes one of the following: taking all candidate tasks as target tasks; taking candidate tasks selected by the user as target tasks; taking candidate tasks with specified stages as target tasks; taking candidate tasks of specified categories as target tasks.

[0072] In some embodiments, the number of the target tasks is at least two; the first processing module 404 is specifically used to: process at least two of the target tasks in parallel to complete the first execution stage of each of the target tasks.

[0073] In some embodiments, the above-mentioned device also includes: a queue determination module, which is used to obtain user-defined task allocation logic in response to receiving a task to be executed, and determine the target queue corresponding to the task to be executed based on the task allocation logic; and a task placement module, which is used to place the task to be executed at the tail of the target queue.

[0074] In some embodiments, the first processing module 404 is specifically used to: obtain user-defined queue preprocessing logic; use an independent thread created outside the main thread to execute the queue preprocessing logic, so as to pre-process the first execution stage of the target task through the queue preprocessing logic to obtain a processing result; wherein, the main thread is a thread used to execute the first task of the target queue.

[0075] In some embodiments, the second processing module 406 is specifically used to: obtain the user-defined main queue processing logic; obtain the processing results obtained by the queue preprocessing logic; and use the main thread to execute the main queue processing logic based on the processing results, so as to process the unprocessed second execution stage in the target task through the main queue processing logic.

[0076] The task processing device provided by the embodiments of the present disclosure can execute the task processing method provided by any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method.

[0077] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described device embodiment can refer to the corresponding process in the method embodiment, and will not be repeated here.

[0078] An embodiment of the present disclosure further provides an electronic device, comprising: a processor; a memory for storing processor-executable instructions; and a processor for reading executable instructions from the memory and executing the instructions to implement any one of the above-mentioned task processing methods. Figure 5 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. Figure 5 As shown, the electronic device 500 includes one or more processors 501 and a memory 502 .

[0079] The processor 501 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 500 to perform desired functions.

[0080] The memory 502 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 501 may execute the program instructions to implement the task processing method of the embodiment of the present disclosure described above and / or other desired functions. Various contents such as input signals, signal components, noise components, etc. may also be stored in the computer-readable storage medium.

[0081] In one example, the electronic device 500 may further include an input device 503 and an output device 504 , and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).

[0082] In addition, the input device 503 may also include, for example, a keyboard, a mouse, and the like.

[0083] The output device 504 can output various information to the outside, including determined distance information, direction information, etc. The output device 504 can include, for example, a display, a speaker, a printer, a communication network and its connected remote output device, etc.

[0084] Of course, to simplify, Figure 5 Only some of the components related to the present disclosure in the electronic device 500 are shown, and components such as buses, input / output interfaces, etc. are omitted. In addition, the electronic device 500 may further include any other appropriate components according to specific application scenarios.

[0085] In addition to the above-mentioned methods and devices, the embodiments of the present disclosure may also be a computer program product, which includes computer program instructions. When the computer program instructions are executed by a processor, the processor executes the task processing method provided by the embodiments of the present disclosure.

[0086] The computer program product may be written in any combination of one or more programming languages ​​to implement the operations of the disclosed embodiments, including object-oriented programming languages ​​such as Java, C++, and conventional procedural programming languages ​​such as C or similar programming languages. The program code may be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0087] In addition, the embodiment of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon. When the computer program instructions are executed by a processor, the processor is enabled to execute the task processing method provided by the embodiment of the present disclosure.

[0088] The computer-readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can, for example, include but is not limited to a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.

[0089] The embodiments of the present disclosure further provide a computer program product, including a computer program / instruction, which implements the task processing method in the embodiments of the present disclosure when executed by a processor.

[0090] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0091] The foregoing description is intended only to provide specific embodiments of the present disclosure, intended to enable those skilled in the art to understand and implement the present disclosure. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the embodiments described herein, but rather to be construed in the broadest manner consistent with the principles and novel features disclosed herein.

Claims

1. A task processing method, characterized in that: include: Obtaining a target task in a target queue; wherein the target queue contains a plurality of serial tasks to be executed, and the target task contains at least two execution stages; Before the target task is queued to the first position of the target queue, the first execution phase of the target task is processed in advance; When the target task is at the first position in the target queue, processing the unprocessed second execution phase of the target task; The pre-processing of the first execution phase of the target task includes: obtaining a user-defined queue pre-processing logic; executing the queue pre-processing logic using an independent thread created outside the main thread, so as to pre-process the first execution phase of the target task using the queue pre-processing logic to obtain a processing result; wherein the main thread is a thread used to execute the first task in the target queue; The processing of the unprocessed second execution phase of the target task includes: obtaining a user-defined main queue processing logic; obtaining a processing result obtained by the queue pre-processing logic; and using the main thread to execute the main queue processing logic based on the processing result, so as to process the unprocessed second execution phase of the target task through the main queue processing logic; When there are execution stages that can be completed independently and execution stages that need to rely on the processing results of other execution stages among the multiple execution stages included in the target task, the execution stage that can be completed independently will be used as the first execution stage for pre-processing, and the execution stage that needs to rely on the processing results of other execution stages will be used as the second execution stage to be completed when the target task is placed at the head of the queue; when the first execution stage of the target task is processed in advance, other tasks at the head of the target queue are also being executed simultaneously.

2. The method according to claim 1, characterized in that The steps to obtain the target task in the target queue include: Determining a candidate task including at least two execution phases from a plurality of tasks to be executed in the target queue; At least one target task is selected from the candidate tasks according to a preset task selection strategy.

3. The method according to claim 2, characterized in that The task selection strategy includes one of the following: taking all candidate tasks as target tasks; taking candidate tasks selected by the user as target tasks; taking candidate tasks with a specified stage as target tasks; taking candidate tasks of a specified category as target tasks.

4. The method according to claim 1, wherein The number of the target tasks is at least two; The step of pre-processing the first execution phase of the target task includes: At least two of the target tasks are processed in parallel to complete the first execution phase of each of the target tasks.

5. The method according to claim 1, wherein Before the step of obtaining the target task in the target queue, the method further includes: In response to receiving a task to be executed, obtaining a user-defined task allocation logic, and determining a target queue corresponding to the task to be executed based on the task allocation logic; The task to be executed is placed at the end of the target queue.

6. A task processing device, characterized in that: include: A task acquisition module is used to acquire a target task in a target queue; wherein the target queue contains a plurality of serial tasks to be executed, and the target task includes at least two execution stages; A first processing module is used to pre-process the first execution phase of the target task before the target task is queued to the first position of the target queue; a second processing module, configured to process an unprocessed second execution phase of the target task when the target task is at the first position in the target queue; The first processing module is specifically configured to: obtain user-defined queue pre-processing logic; execute the queue pre-processing logic using an independent thread created outside the main thread, so as to pre-process the first execution phase of the target task using the queue pre-processing logic to obtain a processing result; wherein the main thread is a thread used to execute the first task in the target queue; The second processing module is specifically configured to: obtain a user-defined main queue processing logic; obtain a processing result obtained by the queue pre-processing logic; and use the main thread to execute the main queue processing logic based on the processing result, so as to process the unprocessed second execution stage of the target task through the main queue processing logic; When there are execution stages that can be completed independently and execution stages that need to rely on the processing results of other execution stages among the multiple execution stages included in the target task, the execution stage that can be completed independently will be used as the first execution stage for pre-processing, and the execution stage that needs to rely on the processing results of other execution stages will be used as the second execution stage to be completed when the target task is placed at the head of the queue; when the first execution stage of the target task is processed in advance, other tasks at the head of the target queue are also being executed simultaneously.

7. An electronic device, characterized in that: The electronic device comprises: processor; a memory for storing instructions executable by the processor; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the task processing method according to any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that The storage medium stores a computer program, and the computer program is used to execute the task processing method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Data processing method and device

    CN110928905A

  • Task processing method and device

    CN112546617A