A task processing method, apparatus, device, and storage medium

By predicting the idle time of the target thread and handling non-immediate tasks when the idle time meets the conditions, the lag caused by task backlog in the Android system is solved, and the smooth execution of tasks and the stability of application is achieved.

CN114416320BActive Publication Date: 2025-08-05DOUYIN VISION CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210066796.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-20
Publication Date
2025-08-05
Estimated Expiration
2042-01-20

AI Technical Summary

Technical Problem

In Android systems, tasks cannot be processed in time, resulting in a backlog of thread tasks, resulting in the application's unresponsive ANR detection mechanism that determines that the application is unresponsive, and there is lag or downtime.

Method used

By determining the idle time of the target thread, using the trained time prediction model to predict the idle time of the thread, and when the idle time is greater than or equal to the preset specified time, the target task is determined based on the task processing time and the specified time, and load it into the target thread for processing.

Benefits of technology

Effectively alleviate the pressure of thread tasks processing, reduce the chance of unresponsiveness and lag in applications, avoid tasks not being executed for a long time, and ensure smooth execution of tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114416320B_ABST
    Figure CN114416320B_ABST
Patent Text Reader

Abstract

The present disclosure provides a task processing method, apparatus, device and storage medium, which determines at least one pending task to be processed by a target thread, wherein the pending task is a non-immediate processing task; when the target thread is in an idle state, predicts the idle duration of the target thread; when the idle duration is greater than or equal to a preset specified duration, determines a target task from the at least one pending task based on the task processing duration of each pending task and the preset specified duration; and loads the target task into the target thread for processing. In this way, by utilizing the idle duration of the target thread to process non-immediate processing tasks, the time when the task is placed into the thread and the timing of execution are controlled, which can reduce the task cache amount of the target thread, relieve the pressure on the target thread, and thus reduce the probability of the application becoming unresponsive or stuck.
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 storage medium. Background Art

[0002] With the continuous development of science and technology, smart terminals have gradually entered people's lives and occupied an increasingly important position in people's lives. In smart terminals, the system of smart terminals plays an important role. It is mainly a computer program that manages the hardware and software resources of the terminal. The operating system needs to handle basic matters such as managing and configuring memory, determining the priority of system resource supply and demand, controlling input and output devices, operating the network and managing the file system.

[0003] Regarding task scheduling in the system, taking the Android system as an example, in the task scheduling process and message passing mechanism of the Android system, if a task needs to be processed, the message pump looper of the corresponding thread can be obtained, the task can be encapsulated into a message and put into the thread for execution. When the task cannot be processed in time or the computing power of the device is limited, the tasks that need to be processed in the thread will accumulate more and more, and the number will be uncontrolled, especially in the main thread. If the number of tasks is backlogged, it is easy to cause the task to fail to respond in time, and thus be judged as unresponsive by the application's unresponsive ANR detection mechanism, causing the terminal or application to freeze or crash. Summary of the Invention

[0004] The embodiments of the present disclosure at least provide a task processing method, apparatus, device, and storage medium.

[0005] The present disclosure provides a task processing method, the method comprising:

[0006] Determining at least one pending task to be processed by the target thread, wherein the pending task is a non-immediate processing task;

[0007] When the target thread is in an idle state, predicting the idle duration of the target thread;

[0008] When the idle time is greater than or equal to the preset specified time, determining a target task from the at least one to-be-processed task according to the task processing time of each to-be-processed task and the preset specified time;

[0009] The target task is loaded into the target thread for processing.

[0010] In an optional implementation, when the target thread is in an idle state, predicting the idle duration of the target thread includes:

[0011] Get the trained duration prediction model;

[0012] When the target thread is in an idle state, the idle duration of the target thread is predicted by the duration prediction model based on the task processing feature information of the target thread.

[0013] In an optional implementation, the duration prediction model is trained by the following steps:

[0014] Obtaining a plurality of sample idle durations when the target thread is in the idle state, and sample feature information for each sample idle duration, wherein the sample idle durations include positive samples and negative samples, the duration of the positive samples being greater than the preset specified duration, and the duration of the negative samples being less than the preset specified duration;

[0015] The constructed idle time prediction model is trained using the plurality of sample idle time periods and sample feature information of each sample idle time period.

[0016] In an optional embodiment, determining the target task from the at least one to-be-processed task based on the task processing duration of each to-be-processed task and the preset designated duration includes:

[0017] Based on the task processing time of each to-be-processed task, determining a first candidate task whose task processing time is less than or equal to the preset specified time from the at least one to-be-processed task;

[0018] The first candidate task is used as the target task.

[0019] In an optional implementation, after predicting the idle duration of the target thread, the method includes:

[0020] If the idle time is less than the preset specified time, determining the preset time classification range in which the idle time falls;

[0021] Based on the task processing time of each to-be-processed task, determining a second candidate task whose task processing time is within the preset time classification range from the at least one to-be-processed task;

[0022] The second candidate task is used as the target task.

[0023] In an optional embodiment, when the first candidate task or the second candidate task includes multiple candidate tasks, the first candidate task is used as the target task or the second candidate task is used as the target task, including

[0024] Determine the latest processing time for each candidate task;

[0025] Determine, from the plurality of candidate tasks, a candidate task with the smallest time difference between the latest processing time and the current time as the target candidate task;

[0026] The target candidate task is used as the target task.

[0027] In an optional implementation, after determining at least one pending task to be processed by the target thread, the method includes:

[0028] Taking the at least one pending task out of the thread task queue of the target thread;

[0029] Adding the at least one task to be processed that has been taken out to a custom task queue for the target thread;

[0030] The step of loading the target task into the target thread for processing includes:

[0031] The determined target task is taken out from the custom task queue, and the taken out target task is loaded into the target thread for processing.

[0032] In an optional implementation, when the target thread is in an idle state, before predicting the idle duration of the target thread, the method includes:

[0033] Detect whether there is a pending task in the custom task queue;

[0034] If there are pending tasks in the custom task queue, the step of predicting the idle duration of the target thread is performed when the target thread is in an idle state.

[0035] In an optional implementation manner, loading the target task into the target thread for processing includes:

[0036] The target task is encapsulated into a target message, and the target message is loaded into the target thread for processing.

[0037] In an optional implementation, after determining at least one pending task to be processed by the target thread, the method includes:

[0038] According to the latest processing time of each to-be-processed task, detecting whether there is a to-be-processed task that has reached the latest processing time in the at least one to-be-processed task;

[0039] If there is one, the pending task that reaches the latest processing time will be determined as the target task.

[0040] If not, executing the step of predicting the idle duration of the target thread when the target thread is in an idle state.

[0041] The present disclosure also provides a task processing device, comprising:

[0042] A task determination module, configured to determine at least one pending task to be processed by a target thread, wherein the pending task is a non-immediate processing task;

[0043] A duration prediction module, configured to predict the idle duration of the target thread when the target thread is in an idle state;

[0044] a target task determining module, configured to determine a target task from the at least one to-be-processed task based on the task processing time of each to-be-processed task and the preset specified time when the idle time is greater than or equal to the preset specified time;

[0045] The task loading module is used to load the target task into the target thread for processing.

[0046] In an optional implementation, the duration prediction module is specifically configured to:

[0047] Get the trained duration prediction model;

[0048] When the target thread is in an idle state, the idle duration of the target thread is predicted by the duration prediction model based on the task processing feature information of the target thread.

[0049] In an optional implementation, the duration prediction module is configured to train the duration prediction model through the following steps:

[0050] Obtaining a plurality of sample idle durations when the target thread is in the idle state, and sample feature information for each sample idle duration, wherein the sample idle durations include positive samples and negative samples, the duration of the positive samples being greater than the preset specified duration, and the duration of the negative samples being less than the preset specified duration;

[0051] The constructed idle time prediction model is trained using the plurality of sample idle time periods and sample feature information of each sample idle time period.

[0052] In an optional implementation, the target task determination module is specifically configured to:

[0053] Based on the task processing time of each to-be-processed task, determining a first candidate task whose task processing time is less than or equal to the preset specified time from the at least one to-be-processed task;

[0054] The first candidate task is used as the target task.

[0055] In an optional implementation, the target task determination module is further configured to:

[0056] If the idle time is less than the preset specified time, determining the preset time classification range in which the idle time falls;

[0057] Based on the task processing time of each to-be-processed task, determining a second candidate task whose task processing time is within the preset time classification range from the at least one to-be-processed task;

[0058] The second candidate task is used as the target task.

[0059] In an optional implementation, when the first candidate task or the second candidate task includes multiple candidate tasks, the target task determination module is specifically configured to:

[0060] Determine the latest processing time for each candidate task;

[0061] Determine, from the plurality of candidate tasks, a candidate task with the smallest time difference between the latest processing time and the current time as the target candidate task;

[0062] The target candidate task is used as the target task.

[0063] In an optional implementation, the task processing device further includes a task adding module, wherein the task adding module is configured to:

[0064] Taking the at least one pending task out of the thread task queue of the target thread;

[0065] Adding the at least one to-be-processed task taken out to the custom task queue for the target thread;

[0066] The task loading module is specifically used for:

[0067] The determined target task is taken out from the custom task queue, and the taken out target task is loaded into the target thread for processing.

[0068] In an optional implementation, the task processing device further includes a task detection module, and the task detection module is configured to:

[0069] Detect whether there is a pending task in the custom task queue;

[0070] If there are pending tasks in the custom task queue, the step of predicting the idle duration of the target thread is performed when the target thread is in an idle state.

[0071] In an optional implementation manner, the task loading module is specifically configured to:

[0072] The target task is encapsulated into a target message, and the target message is loaded into the target thread for processing.

[0073] In an optional implementation, the target task determination module is further configured to:

[0074] According to the latest processing time of each to-be-processed task, detecting whether there is a to-be-processed task that has reached the latest processing time in the at least one to-be-processed task;

[0075] If there is one, the pending task that reaches the latest processing time will be determined as the target task.

[0076] If not, executing the step of predicting the idle duration of the target thread when the target thread is in an idle state.

[0077] An embodiment of the present disclosure also provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the memory communicate through the bus, and when the machine-readable instructions are executed by the processor, the steps of the above-mentioned task processing method are performed.

[0078] An embodiment of the present disclosure further provides a computer storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned task processing method are executed.

[0079] The task processing method, apparatus, device and storage medium provided by the embodiments of the present disclosure determine at least one pending task to be processed by a target thread, wherein the pending task is a non-immediate processing task; when the target thread is in an idle state, predict the idle duration of the target thread; when the idle duration is greater than or equal to a preset specified duration, determine a target task from the at least one pending task based on the task processing duration of each pending task and the preset specified duration; and load the target task into the target thread for processing.

[0080] In this way, by utilizing the idle time of the target thread to process non-immediate tasks, and controlling the time when tasks are placed into the thread and the timing of execution, the task cache amount of the target thread can be reduced, the pressure on the target thread can be relieved, and the chance of the application becoming unresponsive or stuck can be reduced.

[0081] Furthermore, combined with the latest processing time of the target task that can be processed that is pre-set for each pending task, it is possible to effectively avoid the situation where the task is not executed for a long time, reduce the probability of the task being missed, and ensure the smooth execution of the task.

[0082] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0083] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following briefly introduces the drawings required for use in the embodiments. The drawings herein are incorporated into and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and, together with the specification, are used to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For those of ordinary skill in the art, other relevant drawings can be obtained based on these drawings without inventive effort.

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

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

[0086] Figure 3 Schematic diagram of each task stage in the embodiment of the present disclosure;

[0087] Figure 4 This is one of the schematic diagrams of a task processing device provided in an embodiment of the present disclosure;

[0088] Figure 5 A second schematic diagram of a task processing device provided in an embodiment of the present disclosure;

[0089] Figure 6 A schematic diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0090] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, not all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the disclosure for which protection is sought, but merely represents selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present disclosure.

[0091] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined or explained in subsequent drawings.

[0092] The term "and / or" herein simply describes an association relationship, indicating that three relationships can exist. For example, A and / or B can represent the existence of A alone, the simultaneous existence of A and B, and the existence of B alone. In addition, the term "at least one" herein refers to any combination of at least two of any one or more of a plurality of items. For example, "at least one of A, B, and C" can represent any one or more elements selected from the set consisting of A, B, and C.

[0093] Research has found that in electronic devices, taking Android devices as an example, the systems of electronic devices mostly obtain the message pump looper of the corresponding thread for task processing, and then encapsulate the task into a message and put it into the thread for execution. When the task cannot be processed in time or the computing power of the device is limited, the tasks that need to be processed in the thread will accumulate more and more, and the number will be uncontrolled, especially in the main thread. If the number of tasks is large, it is easy to cause the tasks to fail to respond in time, and thus be judged as unresponsive by the application's unresponsiveness (ANR) detection mechanism, causing the terminal or application to freeze or crash.

[0094] Based on the above research, the present disclosure provides a task processing method that can utilize the idle time of the thread to process non-immediate processing tasks, and can further combine the latest processing time of the target task that can be processed that is pre-set for each task to be processed to control the time when the task is placed in the thread and the execution timing. It can not only effectively alleviate the thread task processing pressure, but also greatly reduce the number and frequency of application unresponsiveness and application freezes when the task is not executed, avoid the task from being not executed for a long time, and ensure the smooth execution of the task.

[0095] To facilitate understanding of this embodiment, a task processing method disclosed in an embodiment of the present disclosure is first introduced in detail. The execution subject of the task processing method provided in the embodiment of the present disclosure is generally a computer device with certain computing capabilities. The computer device includes, for example, a terminal device or a server or other processing device. The terminal device can be a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, an in-vehicle device, a wearable device, etc. In some possible implementations, the task processing method can be implemented by a processor calling computer-readable instructions stored in a memory.

[0096] Please also see Figure 1 , Figure 1 This is a flowchart of a task processing method provided by an embodiment of the present disclosure. Figure 1 As shown in , the task processing method provided by the embodiment of the present disclosure includes:

[0097] S101: Determine at least one pending task to be processed by a target thread, where the pending task is a non-immediate processing task.

[0098] In this step, to relieve the pressure of the target thread, multiple tasks that need to be processed by the target thread can be traversed, such as traversing each task in the thread task queue of the target thread, so as to filter out at least one non-immediate task to be processed.

[0099] The target thread may be a main thread of the terminal or a sub-thread of the terminal.

[0100] S102: When the target thread is in an idle state, predict the idle duration of the target thread.

[0101] In this step, while the target thread is running, the target thread can be monitored in real time to monitor the real-time running status of the target thread. If the target thread is found to be in an idle state, the idle time of the target thread in this idle state can be predicted.

[0102] Among them, the idle state can refer to a state in which all timely tasks in the thread task queue of the target thread have been processed and there are no timely tasks that need to be processed. It can also refer to a state in which when the target thread is executing two adjacent timely tasks in the thread task queue, there is a time gap between the two tasks in which no tasks need to be processed.

[0103] For predicting the idle time of the target thread, a neural network obtained by deep learning can be used to predict the idle time of the target thread. For example, when the tasks processed in the target thread are disordered and randomly added to the queue, it is particularly suitable to make predictions through a neural network. It can also be set according to the processing status and queuing status of the tasks in the target thread. For example, when the target thread is periodically added to the queue and needs to periodically process the tasks in the queue, when periodically processing tasks, the processing gap in between can be inferred based on the processing progress and processing time of the two tasks, so as to process non-immediate tasks.

[0104] Specifically, in an optional implementation, for predicting the idle time of the target thread by means of a neural network, a trained time prediction model can be obtained first, and then when the target thread is in an idle state, the idle time of the target thread can be predicted by the time prediction model based on the task processing feature information of the target thread.

[0105] Here, the duration prediction model is obtained by training the neural network with the help of deep learning method as mentioned above.

[0106] The task processing characteristic information includes one or more of the following characteristic information related to task scheduling:

[0107] The target thread's working information; the target thread's most recent task processing information; and the target thread's calling information.

[0108] The working information of the target thread may include information such as the current working scenario of the terminal, the current application scenario of the target thread, the startup type of the target thread, and the task processing method of the target thread.

[0109] The processing information of the most recent task in the target thread may include the processing time of the most recent task in the task queue processed by the target thread before being in the idle state, the time when the previous thread activity in the target thread was in an invisible state, and the time when the most recent animated image of the target thread disappeared in the thread work display interface of the terminal, the time when the most recent animation in the target thread disappeared, the time when the target thread last stopped sliding, the length of the most recent sliding of the target thread, and other information.

[0110] The calling information of the target thread may include information such as the time when the target thread last interacted with the user, the time when the target thread was last applied to the foreground, and the time when the target thread last stopped drawing.

[0111] The duration prediction model needs to be pre-trained. In an optional implementation, the duration prediction model can be trained by the following steps:

[0112] Obtaining a plurality of sample idle durations when the target thread is in the idle state, and sample feature information for each sample idle duration, wherein the sample idle durations include positive samples and negative samples, the duration of the positive samples being greater than the preset specified duration, and the duration of the negative samples being less than the preset specified duration;

[0113] The constructed idle time prediction model is trained using the plurality of sample idle time periods and sample feature information of each sample idle time period.

[0114] Here, the idle time of the target thread after processing the task can be sampled to obtain the sample idle time of the target thread in the idle state, as well as the sample feature information of each sample idle time, that is, the sample task feature information. Moreover, the collected multiple sample idle times can be classified according to the preset specified time to divide positive samples and negative samples. Then, the multiple sample idle times and the sample feature information of each sample idle time are input as input data into the constructed neural network for training to obtain the trained time prediction model.

[0115] The duration prediction model may be a binary classification model. For example, the idle duration predicted for the target thread may have only two classifications, such as whether it is greater than a certain threshold. Accordingly, the sample idle duration may include positive samples and negative samples, where the duration of the positive sample is greater than or equal to the preset specified duration, and the duration of the negative sample is less than the preset specified duration.

[0116] In addition, the duration prediction model can be a multi-classification model. For example, for the idle duration predicted for the target thread, it can be determined which pre-divided duration interval the result falls into. Accordingly, the sample idle duration can include samples located in each pre-divided duration interval.

[0117] The constructed neural network may be, for example, an Extreme Gradient Boosting (XGBoost) network.

[0118] S103: When the idle time is greater than or equal to the preset designated time, a target task is determined from the at least one task to be processed according to the task processing time of each task to be processed and the preset designated time.

[0119] In this step, if the predicted idle time of the target thread is greater than the preset specified time, it can be considered that the target thread has sufficient time to process each task. Therefore, the preset specified time can be referred to, and the at least one pending task can be screened according to the task processing time of each pending task, and the target task that can be added to the target thread for processing can be selected.

[0120] The preset specified duration may be a pre-configured fixed time interval, or a time interval dynamically configured according to the situation of each task to be processed.

[0121] S104: Load the target task into the target thread for processing.

[0122] In this step, after the target task is determined, the target task may be loaded into the target thread so as to be processed by the target thread.

[0123] Specifically, loading the target task into the target thread for processing may be encapsulating the target task into a target message, and then loading the target message into the target thread for processing.

[0124] The target message may include the task ID of the target task, the task processing object, and the task processing data.

[0125] The task processing method provided by the embodiment of the present disclosure determines at least one pending task to be processed by a target thread, where the pending task is a non-immediate processing task. When the target thread is in an idle state, the idle duration of the target thread is predicted. When the idle duration is greater than or equal to a preset specified duration, a target task is determined from the at least one pending task based on the task processing duration of each pending task and the preset specified duration, and the target task is loaded into the target thread for processing.

[0126] In this way, the idle time of the thread can be used to handle non-immediate tasks, which can not only effectively alleviate the pressure of thread task processing, but also greatly reduce the number and frequency of application unresponsiveness and application freezes when the task is not executed, avoid tasks not being executed for a long time, and ensure the smooth execution of tasks.

[0127] See also Figure 2 , Figure 2 This is a flowchart of another task processing method provided by an embodiment of the present disclosure. Figure 2 As shown in , the task processing method provided by the embodiment of the present disclosure includes:

[0128] S201: Determine at least one pending task to be processed by a target thread, where the pending task is a non-immediate processing task.

[0129] S202: According to the latest processing time of each to-be-processed task, detecting whether there is a to-be-processed task that has reached the latest processing time in the at least one to-be-processed task.

[0130] In this step, after determining the at least one pending task, each pending task can be traversed to first determine the latest processing time of each pending task, and then detect whether there is a pending task that reaches the latest processing time to detect whether there is a non-immediate task that needs to be processed urgently.

[0131] Among them, the latest processing time can be based on factors such as the task information, resource occupancy information, and application information of the task to be processed, and can also be combined with the actual situation of the terminal, such as hardware configuration and task execution status, to configure the time for each task to be processed when the task to be processed is received. It can also be the latest time that the task is allowed to be delayed based on factors such as the actual task information of the corresponding task to be processed.

[0132] S203: If so, determine the to-be-processed task that reaches the latest processing time as the target task; if not, execute the step of predicting the idle duration of the target thread when the target thread is in an idle state.

[0133] In this step, if it is detected that there is a pending task that has reached the latest processing time, it can be considered that the pending task has reached the point where it must be processed. Therefore, the traversed pending task can be directly used as the target task that needs to be processed. On the contrary, if it does not exist, it can be considered that there is no task that needs to be processed urgently. Then, for the at least one pending task, the step of predicting the idle time of the target thread when the target thread is in an idle state can be executed, and the idle time of the target thread can be matched with the task time.

[0134] S204: When the target thread is in an idle state, predict the idle duration of the target thread.

[0135] S205: When the idle time is greater than or equal to the preset designated time, determine a target task from the at least one task to be processed according to the task processing time of each task to be processed and the preset designated time.

[0136] S206: Load the target task into the target thread for processing.

[0137] Among them, the description of step S201, step S204, step S205, and step S206 can refer to the description of step S101 to step S104, and can achieve the same technical effects and solve the same technical problems, so they are not repeated here.

[0138] Next, this embodiment is further described in conjunction with specific implementation methods.

[0139] In one possible real-time approach, step S205 includes:

[0140] Based on the task processing duration of each to-be-processed task, a first candidate task having a task processing duration less than or equal to the preset specified duration is determined from the at least one to-be-processed task; and the first candidate task is used as the target task.

[0141] In this step, when screening the target tasks, the task processing time of each task to be processed can be determined first, and then the determined task processing time of each task can be compared with the preset specified time. If the task processing time is less than or equal to the preset specified time, it can be considered that the target thread has sufficient spare time to process this task, that is, the task with a task processing time less than or equal to the preset specified time can be used as the first candidate task, and then the first candidate task can be used as the target task for the target thread to process.

[0142] Here, it can be used for a solution that uses a binary classification model to predict the idle time of the target thread, that is, it only needs to compare whether it is greater than the preset specified time.

[0143] Accordingly, when predicting the idle duration of the target thread, if the idle duration is predicted using multiple classifications, it is not necessary to simply check whether the idle duration is greater than or equal to the preset specified duration.

[0144] Accordingly, in a possible implementation manner, after step S204, the method further includes:

[0145] If the idle time is less than the preset specified time, determine the preset time classification range within which the idle time falls; based on the task processing time of each pending task, determine a second candidate task whose task processing time falls within the preset time classification range from the at least one pending task; and use the second candidate task as the target task.

[0146] In this step, if the predicted idle time is less than the preset specified time, then the idle time can be further detected, and the preset time classification range of the idle time can be detected, that is, for multiple classification results, which time classification the idle time belongs to. Further, the task processing time of each task to be processed can be traversed to select the task whose task processing time is within the preset time classification range as the second candidate task. The second candidate task is the target task that the target thread can process.

[0147] Furthermore, whether it is a binary classification or multi-classification case, in order to reduce the computing power pressure and resource pressure of the target thread, the target thread can only process one task at a time when processing the pending tasks. Then, when screening the first candidate task or the second candidate task, if the first candidate task or the second candidate task includes multiple candidate tasks, it is necessary to further select the target task to be processed from the multiple candidate tasks.

[0148] Accordingly, in a possible implementation, when the first candidate task or the second candidate task includes multiple candidate tasks, the first candidate task is used as the target task or the second candidate task is used as the target task, including

[0149] Determine the latest processing time of each candidate task; determine the candidate task with the smallest time difference between the latest processing time and the current time from the multiple candidate tasks as the target candidate task; and use the target candidate task as the target task.

[0150] In this step, for the multiple candidate tasks that are initially screened, it is possible to detect which task has the smallest time difference between its latest processing time and the current time based on the latest processing time of the candidate tasks, that is, which task is in urgent need of processing. The target candidate task with the smallest time difference between its latest processing time and the current time can be used as the target task that urgently needs to be processed by the target thread.

[0151] In a possible implementation, after step S201, the method further includes:

[0152] The at least one to-be-processed task is taken out from the thread task queue of the target thread; and the at least one to-be-processed task that is taken out is added to the custom task queue for the target thread.

[0153] In this step, after determining at least one pending task to be processed by the target thread, in order to avoid the target thread from processing according to the established task arrangement, each pending task can be taken out from the thread task queue of the target thread, thereby reducing the task cache pressure of the target thread, and then a custom task queue can be created for the target thread, and the at least one pending task can be added to the custom task queue.

[0154] Among them, the custom task queue can be customized manually or by the system.

[0155] Furthermore, step S206 includes:

[0156] The determined target task is taken out from the custom task queue, and the taken out target task is loaded into the target thread for processing.

[0157] Here, when the target thread is capable of processing the target task, the target task can be taken out from the custom task queue and loaded into the target thread for processing.

[0158] In an optional implementation, before step S204, the method includes:

[0159] Detect whether there is a pending task in the custom task queue;

[0160] If there are pending tasks in the custom task queue, the step of predicting the idle duration of the target thread is performed when the target thread is in an idle state.

[0161] In this step, when the target thread is in an idle state, before the step of predicting the idle duration of the target thread, it is possible to first detect whether there are pending tasks in the custom task queue. If there are pending tasks in the custom task queue, it is determined that the target task needs to be filtered for the target thread, and then the step of predicting the idle duration of the target thread when the target thread is in an idle state can be continued.

[0162] On the contrary, if there is no task to be processed in the custom task queue, the step of predicting the idle duration of the target thread is not performed, that is, the process can be stopped.

[0163] For example, please refer to Figure 3 , Figure 3 Schematic diagram of each task stage in the embodiment of the present disclosure. Figure 3As shown in , the task processing process mainly includes three stages, namely the training data collection stage, the model training stage and the task processing stage. These three stages are sequential in time, but may not be continuous in time. For example, for the training data collection stage and the model training stage, the two can be separated from the task processing stage, that is, before starting the task processing stage, the model to be used needs to be trained in advance through the training data collection stage and the model training stage, and after the model training is completed, it can be used in each task processing stage.

[0164] Specifically, in the training data collection stage, it is necessary to collect feature data related to task scheduling and duration data related to the idle time of the target thread. Then, in the model training stage, the collected feature data and duration data can be preprocessed, such as extracting dirty data, and then performing data annotation. For example, the duration data needs to be labeled to indicate whether it belongs to a sample that is greater than the preset specified duration, or specifically to which pre-divided duration interval it belongs. Then, the processed data can be used to train the neural network to obtain a duration prediction model that can be used to predict the idle time. These two stages can be performed in the background server. Accordingly, the background server can send the duration prediction model to the user's terminal. After receiving the duration prediction model and entering the task processing stage, the terminal can collect non-immediate tasks in the target thread and add them to a custom processing queue. When there are tasks in the queue, the idle time can be predicted by the model, and the task can be processed in combination with the latest processing time of the task and the task processing duration.

[0165] The task processing method provided by the embodiment of the present disclosure determines at least one pending task to be processed by a target thread, where the pending task is a non-immediate processing task. Based on the latest processing time of each pending task, it is detected whether there is a pending task that has reached the latest processing time in the at least one pending task. If so, the pending task that has reached the latest processing time is determined as the target task. If not, the step of predicting the idle time of the target thread when the target thread is in an idle state is executed. When the idle time is greater than or equal to a preset specified time, the target task is determined from the at least one pending task based on the task processing time of each pending task and the preset specified time, and the target task is loaded into the target thread for processing.

[0166] In this way, the idle time of the thread can be used to process non-immediate tasks, and the latest processing time of the target task that can be processed can be pre-set for each task to be processed to control the time when the task is placed in the thread and the timing of execution. This can not only effectively alleviate the pressure of thread task processing, but also greatly reduce the number and frequency of application unresponsiveness and application freezes when the task is not executed, avoid tasks not being executed for a long time, and ensure the smooth execution of tasks.

[0167] Those skilled in the art will understand that in the above-mentioned method of the specific implementation method, the writing order of each step does not mean a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.

[0168] Based on the same inventive concept, the embodiment of the present disclosure also provides a task processing device corresponding to the task processing method. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned task processing method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.

[0169] See also Figures 4 and 5 , Figure 4 This is one of the schematic diagrams of a task processing device provided by an embodiment of the present disclosure. Figure 5 This is a second schematic diagram of a task processing device provided in an embodiment of the present disclosure.

[0170] like Figure 4 As shown in , the task processing device 400 provided by the embodiment of the present disclosure includes:

[0171] The task determination module 410 is configured to determine at least one pending task to be processed by a target thread, wherein the pending task is a non-immediate processing task.

[0172] The duration prediction module 420 is configured to predict the idle duration of the target thread when the target thread is in an idle state.

[0173] The target task determination module 430 is configured to determine a target task from the at least one pending task based on the task processing time of each pending task and the preset specified time when the idle time is greater than or equal to the preset specified time.

[0174] The task loading module 440 is configured to load the target task into the target thread for processing.

[0175] In an optional implementation, the duration prediction module 420 is specifically configured to:

[0176] Get the trained duration prediction model;

[0177] When the target thread is in an idle state, the idle duration of the target thread is predicted by the duration prediction model based on the task processing feature information of the target thread.

[0178] In an optional implementation, the duration prediction module 420 is configured to train the duration prediction model through the following steps:

[0179] Obtaining a plurality of sample idle durations when the target thread is in the idle state, and sample feature information for each sample idle duration, wherein the sample idle durations include positive samples and negative samples, the duration of the positive samples being greater than the preset specified duration, and the duration of the negative samples being less than the preset specified duration;

[0180] The constructed idle time prediction model is trained using the plurality of sample idle time periods and sample feature information of each sample idle time period.

[0181] In an optional implementation, the target task determination module 430 is specifically configured to:

[0182] Based on the task processing time of each to-be-processed task, determining a first candidate task whose task processing time is less than or equal to the preset specified time from the at least one to-be-processed task;

[0183] The first candidate task is used as the target task.

[0184] In an optional implementation, the target task determination module 430 is further configured to:

[0185] If the idle time is less than the preset specified time, determining the preset time classification range in which the idle time falls;

[0186] Based on the task processing time of each to-be-processed task, determining a second candidate task whose task processing time is within the preset time classification range from the at least one to-be-processed task;

[0187] The second candidate task is used as the target task.

[0188] In an optional implementation, when the first candidate task or the second candidate task includes multiple candidate tasks, the target task determination module 430 is specifically configured to:

[0189] Determine the latest processing time for each candidate task;

[0190] Determine, from the plurality of candidate tasks, a candidate task with the smallest time difference between the latest processing time and the current time as the target candidate task;

[0191] The target candidate task is used as the target task.

[0192] In an optional embodiment, as Figure 5 As shown in , the task processing device 400 further includes a task adding module 450, and the task adding module 450 is used to:

[0193] Taking the at least one pending task out of the thread task queue of the target thread;

[0194] Adding the at least one task to be processed that has been taken out to a custom task queue for the target thread;

[0195] The task loading module 440 is specifically used to:

[0196] The determined target task is taken out from the custom task queue, and the taken out target task is loaded into the target thread for processing.

[0197] In an optional embodiment, as Figure 5 As shown in , the task processing device 400 further includes a task detection module 460, which is used to:

[0198] Detect whether there is a pending task in the custom task queue;

[0199] If there are pending tasks in the custom task queue, the step of predicting the idle duration of the target thread is performed when the target thread is in an idle state.

[0200] In an optional implementation, the task loading module 440 is specifically configured to:

[0201] The target task is encapsulated into a target message, and the target message is loaded into the target thread for processing.

[0202] In an optional implementation, the target task determination module 430 is further configured to:

[0203] According to the latest processing time of each to-be-processed task, detecting whether there is a to-be-processed task that has reached the latest processing time in the at least one to-be-processed task;

[0204] If there is one, the pending task that reaches the latest processing time will be determined as the target task.

[0205] If not, executing the step of predicting the idle duration of the target thread when the target thread is in an idle state.

[0206] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference can be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.

[0207] The task processing device provided by the embodiment of the present disclosure determines at least one pending task to be processed by a target thread, where the pending task is a non-immediate processing task; predicts the idle duration of the target thread when the target thread is in an idle state; determines a target task from the at least one pending task based on the task processing duration of each pending task and the preset specified duration when the idle duration is greater than or equal to a preset specified duration; and loads the target task into the target thread for processing.

[0208] In this way, by utilizing the idle time of the target thread to process non-immediate tasks, and controlling the time when tasks are placed into the thread and the timing of execution, the task cache amount of the target thread can be reduced, the pressure on the target thread can be relieved, and the chance of the application becoming unresponsive or stuck can be reduced.

[0209] Furthermore, combined with the latest processing time of the target task that can be processed that is pre-set for each pending task, it is possible to effectively avoid the situation where the task is not executed for a long time, reduce the probability of the task being missed, and ensure the smooth execution of the task.

[0210] Based on the same technical concept, the embodiment of the present application further provides an electronic device 600, such as Figure 6 FIG. 6 is a schematic structural diagram of an electronic device 600 provided in an embodiment of the present disclosure, including:

[0211] Processor 610, memory 620, and bus 630; memory 620 is used to store execution instructions, including internal memory 621 and external memory 622; the memory 621 here is also called internal memory, which is used to temporarily store the calculation data in the processor 610, as well as the data exchanged with the external memory 622 such as the hard disk. The processor 610 exchanges data with the external memory 622 through the memory 621. When the electronic device 600 is running, the processor 610 and the memory 620 communicate through the bus 630, so that the processor 610 can execute the steps of the task processing method shown in the above method embodiment.

[0212] The present disclosure also provides a computer storage medium having a computer program stored thereon, which, when executed by a processor, executes the steps of the task processing method described in the above method embodiment. The storage medium may be volatile or non-volatile computer storage medium.

[0213] The embodiments of the present disclosure also provide a computer program product, which carries program code. The instructions included in the program code can be used to execute the steps of the task processing method described in the above method embodiment. For details, please refer to the above method embodiment and will not be repeated here.

[0214] The computer program product may be implemented in hardware, software, or a combination thereof. In one embodiment, the computer program product is implemented as a computer storage medium. In another embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).

[0215] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the storage media, devices and equipment described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed storage media, devices, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0216] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0217] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0218] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0219] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The scope of protection of the present disclosure is not limited thereto. Although the present disclosure has been described in detail with reference to the above-described embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above-described embodiments within the technical scope disclosed in the present disclosure, or replace some of the technical features therein with equivalents. Such modifications, changes, or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the scope of protection of the present disclosure. Therefore, the scope of protection of the present disclosure shall be subject to the scope of protection of the claims.

Claims

1. A task processing method, characterized in that: The method comprises: Determining at least one pending task to be processed by the target thread, wherein the pending task is a non-immediate processing task; When the target thread is in an idle state, predicting the idle duration of the target thread; When the idle time is greater than or equal to the preset specified time, determining a target task from the at least one to-be-processed task according to the task processing time of each to-be-processed task and the preset specified time; Loading the target task into the target thread for processing; Wherein, when the target thread is in an idle state, predicting the idle duration of the target thread includes: Get the trained duration prediction model; When the target thread is in an idle state, predicting the idle duration of the target thread by using the duration prediction model based on the task processing feature information of the target thread; The duration prediction model is trained by the following steps: Obtaining a plurality of sample idle durations when the target thread is in the idle state, and sample feature information for each sample idle duration, wherein the sample idle durations include positive samples and negative samples, the duration of the positive samples being greater than the preset specified duration, and the duration of the negative samples being less than the preset specified duration; The constructed duration prediction model is trained using the plurality of sample idle durations when the target thread is in the idle state and the sample feature information for each sample idle duration.

2. The method according to claim 1, characterized in that The determining of a target task from the at least one task to be processed according to the task processing duration of each task to be processed and the preset designated duration includes: Based on the task processing time of each to-be-processed task, determining a first candidate task whose task processing time is less than or equal to the preset specified time from the at least one to-be-processed task; The first candidate task is used as the target task.

3. The method according to claim 1, characterized in that After predicting the idle duration of the target thread, the method includes: If the idle time is less than the preset specified time, determining the preset time classification range in which the idle time falls; Based on the task processing time of each to-be-processed task, determining a second candidate task whose task processing time is within the preset time classification range from the at least one to-be-processed task; The second candidate task is used as the target task.

4. The method according to claim 2 or 3, characterized in that In a case where the first candidate task or the second candidate task includes a plurality of candidate tasks, taking the first candidate task as the target task or taking the second candidate task as the target task includes: Determine the latest processing time for each candidate task; Determine, from the plurality of candidate tasks, a candidate task with the smallest time difference between the latest processing time and the current time as a target candidate task; The target candidate task is used as the target task.

5. The method according to claim 1, wherein After determining at least one pending task to be processed by the target thread, the method includes: Taking the at least one pending task out of the thread task queue of the target thread; Adding the at least one to-be-processed task taken out to the custom task queue for the target thread; The step of loading the target task into the target thread for processing includes: The determined target task is taken out from the custom task queue, and the taken out target task is loaded into the target thread for processing.

6. The method according to claim 5, characterized in that When the target thread is in an idle state, before predicting the idle duration of the target thread, the method includes: Detect whether there is a pending task in the custom task queue; If the to-be-processed task exists in the custom task queue, the step of predicting the idle duration of the target thread is performed when the target thread is in an idle state.

7. The method according to claim 1, characterized in that The step of loading the target task into the target thread for processing includes: The target task is encapsulated into a target message, and the target message is loaded into the target thread for processing.

8. The method according to claim 1, characterized in that After determining at least one pending task to be processed by the target thread, the method includes: According to the latest processing time of each to-be-processed task, detecting whether there is a to-be-processed task that has reached the latest processing time in the at least one to-be-processed task; If so, the pending task that reaches the latest processing time is determined as the target task; If not, executing the step of predicting the idle duration of the target thread when the target thread is in an idle state.

9. A task processing device, characterized in that: include: A task determination module, configured to determine at least one pending task to be processed by a target thread, wherein the pending task is a non-immediate processing task; A duration prediction module, configured to predict the idle duration of the target thread when the target thread is in an idle state; a target task determining module, configured to determine a target task from the at least one to-be-processed task based on the task processing time of each to-be-processed task and the preset specified time when the idle time is greater than or equal to the preset specified time; A task loading module, used for loading the target task into the target thread for processing; The duration prediction module is further used to: Get the trained duration prediction model; When the target thread is in an idle state, predicting the idle duration of the target thread by using the duration prediction model based on the task processing feature information of the target thread; The duration prediction module is further configured to train the duration prediction model through the following steps: Obtaining a plurality of sample idle durations when the target thread is in the idle state, and sample feature information for each sample idle duration, wherein the sample idle durations include positive samples and negative samples, the duration of the positive samples being greater than the preset specified duration, and the duration of the negative samples being less than the preset specified duration; The constructed duration prediction model is trained using the plurality of sample idle durations when the target thread is in the idle state and the sample feature information for each sample idle duration.

10. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the task processing method according to any one of claims 1 to 8 are performed.

11. A computer storage medium, characterized in that The computer storage medium stores a computer program, which, when executed by a processor, executes the steps of the task processing method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Batch data processing method and device, computer equipment and storage medium

    CN110297711A