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

By obtaining and surviving the processing of target loop objects when the application enters the background, and using RunLoop to manage threads to execute tasks, the problem of low execution efficiency of application background tasks is solved, and more efficient resource utilization and stability is achieved.

CN114675946BActive Publication Date: 2025-07-18TENCENT CLOUD COMPUTING (BEIJING) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110575038.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-25
Publication Date
2025-07-18
Estimated Expiration
2041-06-14

AI Technical Summary

Technical Problem

After the application enters the background, it is difficult to ensure the efficiency of tasks, especially the smooth execution of important functions, and may lead to waste of resources or overheating of equipment.

Method used

By obtaining multiple reference loop objects of the application, selecting the target loop object for survival processing, and using the surviving loop object to execute tasks when listening to the target task, the RunLoop mechanism is used to manage threads to ensure continuous operation.

Benefits of technology

It improves the efficiency of the application's task execution in the background, reduces the consumption of the central processor, and enhances the stability and user experience of the application.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114675946B_ABST
    Figure CN114675946B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a data processing method, apparatus, device, and storage medium, which can be used in the field of cloud technologies to implement monitoring of tasks. The method includes: if an application enters the background, obtaining a target loop object from multiple reference loop objects corresponding to the application; performing survival processing on the target loop object to obtain the target loop object after survival processing; when a target task in a child thread corresponding to the target loop object is monitored, executing the target task by using the target loop object after survival processing. It is possible to ensure the execution of tasks corresponding to important child threads by using loop objects when the application enters the background, thereby improving the execution efficiency of tasks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of cloud technology, and in particular, to a data processing method, apparatus, device, and storage medium. Background Art

[0002] With the rapid development of computer technology, people's dependence on terminals such as smart phones and computers is increasing. For example, when a user uses a smart phone, the application programs in the smart phone can include three states, which can include startup, exit, and entering the background.

[0003] Currently, when an application program is in the state of entering the background, generally two methods can be used to make the application program continue to run. One is to use the application interfaces related to the application program to make the program application continue to run. For example, when a user is listening to music using a social application program, after pressing the home key to enter the background or the screen-off state, the social application program can still continue to run using the application interface for playing audio, that is, a large number of multi-threaded operations can still be performed in the background. The other is to use the related functions of background tasks to extend the survival time of the application program in the background. For the first method, it mainly depends on the user's operation. For example, in the above description, the social application program uses playing audio to keep the application program alive, but such an operation is likely to cause the mobile phone to get hot and reduce the life of the mobile phone. For the second method, tasks can be added when entering the background, but it may block the multi-threaded tasks that are already being executed and cannot ensure the smooth execution of important functions. Therefore, how to ensure the improvement of task execution efficiency after the application program enters the background has become an urgent problem to be solved. Summary of the Invention

[0004] Embodiments of this application provide a data processing method, apparatus, device, and storage medium, which help to improve the execution efficiency of tasks after the application program enters the background.

[0005] In a first aspect, an embodiment of this application discloses a data processing method, and the method includes:

[0006] If the application program enters the background, obtain a target loop object from a plurality of reference loop objects corresponding to the application program;

[0007] Perform survival processing on the target loop object to obtain a survived target loop object;

[0008] When a target task in the child thread corresponding to the target loop object is monitored, execute the target task using the survived target loop object.

[0009] In a second aspect, an embodiment of this application discloses a data processing apparatus, and the apparatus includes:

[0010] An acquisition unit, configured to obtain a target loop object from a plurality of reference loop objects corresponding to the application if the application enters the background;

[0011] A survival unit, configured to perform a survival process on the target loop object to obtain a survived target loop object;

[0012] An execution unit, configured to execute the target task by using the survived target loop object when a target task in a child thread corresponding to the target loop object is monitored.

[0013] A third aspect of the embodiments of the present application discloses a data processing device, including a processor and a memory. The memory is configured to store a computer program, the computer program includes program instructions, and the processor is configured to call the program instructions to execute the method of the first aspect above.

[0014] A fourth aspect of the embodiments of the present application discloses a computer-readable storage medium, which stores a computer program. The computer program includes program instructions, and when the program instructions are executed by a processor, the processor is caused to execute the method of the first aspect above.

[0015] A fifth aspect of the embodiments of the present application discloses a computer program product or a computer program. The computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. A processor of a data processing device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the data processing device executes the method of the first aspect above.

[0016] In the embodiments of the present application, after the application enters the background, a target loop object can be obtained from a plurality of reference loop objects corresponding to the application, and a survival process is performed on the target loop object to obtain a survived target loop object. When a target task in a child thread corresponding to the target loop object is monitored, the survived target loop object can be used to execute the target task. By implementing the above method, when the application enters the background, loop objects can be used to ensure the execution of some tasks, such as tasks corresponding to important child threads, thereby improving the execution efficiency of the tasks. Description of the Drawings

[0017] To more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0018] Figure 1aIt is a schematic structural diagram of an operating loop provided by an embodiment of the present application;

[0019] Figure 1b It is a schematic structural diagram of a mode in an operating loop provided by an embodiment of the present application;

[0020] Figure 2 It is a schematic flowchart of a data processing method provided by an embodiment of the present application;

[0021] Figure 3 It is a schematic flowchart of another data processing method provided by an embodiment of the present application;

[0022] Figure 4 It is a schematic flowchart of yet another data processing method provided by an embodiment of the present application;

[0023] Figure 5 It is a schematic structural diagram of a data processing device provided by an embodiment of the present application;

[0024] Figure 6 It is a schematic structural diagram of a data processing device provided by an embodiment of the present application. Detailed implementation manners

[0025] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.

[0026] Cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software, and networks within a wide area network or a local area network to achieve data calculation, storage, processing, and sharing.

[0027] Cloud technology is the general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool, be used on demand, and is flexible and convenient. Cloud computing technology will become an important support. The background services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites, and more portal websites. With the high development and application of the Internet industry, in the future, each item may have its own identification mark and needs to be transmitted to the background system for logical processing. Data at different levels will be processed separately, and various industry data requires a powerful system background support, which can only be achieved through cloud computing.

[0028] The present application stores the data required for traffic scheduling in the "cloud" and can obtain the data in the cloud at any time according to needs and expand at any time.

[0029] After the application enters the background, a large number of multi-threaded operations can still be performed in the background. Usually, a thread can only execute one task at a time, and the thread will exit after the execution is completed. In order to ensure that the tasks required by the user or relatively important tasks can continue to be executed, that is, the thread can handle tasks at any time but does not exit. Then, the above function can be implemented by using the event loop method. For example, the above function can be implemented by RunLoop (run loop) in the CoreFoundation framework, that is, the event loop method can be RunLoop. RunLoop can be understood as a loop object that manages various tasks that need to be processed. Optionally, the inside of RunLoop can specifically be a do-while loop, that is, various tasks can be continuously processed inside this loop.

[0030] For example, Figure 1a The following is a schematic diagram of the structure of running RunLoop, as Figure 1a shown, RunLoop receives input events from two sources: input source and timer source. Among them, the input source can include port-based input source (Port), custom input source (Custom), and selector-based input source (performSelector: onThread). It can be seen that the internal implementation of RunLoop is a do-while loop. The RunLoop corresponding to a thread can listen for port events (handlePort), input source events (customSrc), selector events (mySelector), and timer events (timerFired). RunLoop can continuously detect whether there are events generated outside. If an event is detected, the event can be obtained and the event can be executed.

[0031] Well, a RunLoop can be added to a thread and run. Adding a RunLoop to a thread is equivalent to adding a do-while loop, and the thread will be in the do-while loop all the time. If the tasks of the thread have not been completed, the thread does not need to exit. Each thread can have a RunLoop, which is created when it is first obtained and destroyed when the thread ends. By using RunLoop, the continuous operation of the application can be maintained. When the application starts, a thread is launched, and after the thread starts, the RunLoop corresponding to the thread can be run. RunLoop can ensure that the thread will not be destroyed, thus ensuring the continuous operation of the application. When the application is running but there are no tasks to execute, RunLoop can send information indicating no tasks to the CPU. After receiving this information, the CPU can release its resources to handle other tasks. Therefore, using RunLoop can effectively save CPU resources and improve the performance of the application.

[0032] In one implementation, in order to distinguish different events, RunLoop can run in different modes. As Figure 1b shown, a RunLoop can correspond to multiple modes, and each mode of RunLoop can include several events. For example, the event can be a source / timer / observer. Each time RunLoop is started, one of the multiple modes included in RunLoop can be specified, and this mode can be called the Current Mode. If it is necessary to switch modes, the current RunLoop can be exited, then RunLoop can be started again, and a different mode can be specified. This approach can separate different groups of sources / timers / observers and make them not affect each other.

[0033] Among them, the modes of the RunLoop can include NSDefaultRunLoopMode (the default running mode), NSConnectionReplyMode (the mode for listening to the connection event status), NSModalPanelRunLoopMode (the mode for differentiating events in the case of a modal panel), NSEventTrackingRunLoopMode (the mode for tracking touch event triggers), and NSRunLoopCommonModes (a set of RunLoop mode collections). The Mode used by the RunLoop in this application can be NSRunLoopCommonModes, and for tasks of other Modes, the RunLoop stops running.

[0034] It can be understood that the technical solution of this application can be applied to the client, or can be applied to the data processing device, or can be applied to the data processing equipment. Optionally, the data processing device can be a client, or the client can be deployed in the data processing equipment. Further optionally, the data processing equipment can be a terminal, a personal computer, a tablet computer, etc., which is not limited in this application.

[0035] The implementation details of the technical solution of the embodiments of this application are elaborated in detail below:

[0036] Please refer to Figure 2 , Figure 2 which is a schematic flowchart of a data processing method provided by the embodiments of this application. As Figure 2 shown, the data processing method may include:

[0037] S201: If the application enters the background, obtain the target loop object from multiple reference loop objects corresponding to the application.

[0038] Among them, the application can be any application in the terminal, or a specific application in the terminal. For example, the specific application can be an application frequently used by the user, or an application with more function modules. Considering that the task processing efficiency of the application can be improved when using the data processing method of this application, the user experience can be effectively improved. Optionally, the reference loop object can be a RunLoop formed by adding the events (tasks) processed by this application, such as a RunLoop formed by adding the events processed by this application to the existing RunLoop. The specific implementation process can refer to the following description and will not be elaborated here. The target loop object can refer to one or more of the multiple reference loop objects.

[0039] In one implementation, there can be multiple ways to determine the target loop object. For example, the target loop object can be obtained from multiple reference loop objects based on the processing priority of the reference tasks. Optionally, the processing priority of each reference task in the reference task set can be determined first. Here, the reference tasks can be tasks that each functional module included in the application needs to run in the background when the application is started. For example, the functional modules of a certain application can include a download module, a statistics module, etc. The reference tasks can be the download tasks included in the download module, or the statistics tasks included in the statistics module, and so on. After determining the processing priority of each reference task, the target loop object can be determined from the multiple reference loop objects corresponding to the application according to the processing priority of each reference task.

[0040] Optionally, the specific implementation of determining the processing priority of each reference task can be: after obtaining the reference task set, the interface of the server can be called to transmit the task information of each reference task in the reference task set to the server through this interface, so that the server can determine the processing priority of each reference task according to the task information. Here, the task information can include a task identifier and task status information. For example, if a certain reference task is a download task, the task identifier of this download task can be Task A, or Task B, etc., or other identification methods can be used to display the task identifier, which is not limited in this application; the task status information can be start downloading, downloading, download completed, etc. After the server receives the task information of each reference task, it can determine the processing priority of each reference task according to the task information. The setting rule of the processing priority is not limited in this application. For example, the mapping relationship between the task identifier, task status information, and processing priority can be set in advance. Then, after the server receives the task information, it can determine the processing priority corresponding to the reference task according to this mapping relationship and the task information. After the server determines the processing priority of each reference task, it can send the processing priority of each reference task to the application. So that the subsequent application can determine the target loop object from the multiple reference loop objects according to the processing priority of each reference task.

[0041] Optionally, the specific implementation of determining the target loop object from multiple reference loop objects according to the processing priority of each reference task may be as follows: The priorities of each reference loop object can be determined according to the processing priorities of each reference task. After determining the priorities of each reference loop object, the target loop object can be determined according to the priorities of each reference loop object. For example, the priorities of each reference loop object can be sorted in descending order to obtain the sorting result of loop object priorities, and the first L reference loop objects in the sorting result of loop object priorities can be determined as the target loop object. Wherein, L can be any value, such as values like 2 or 3. It can also be determined according to the power of the current terminal, etc. For example, when determining according to the power of the current terminal, it can be considered that when the power of the current terminal is low, the value set for L is small, so as to save the power of the terminal. It can also be determined according to the type of application. For example, when the application is a type frequently used by the user, it can be considered that the value set for L is large, so as to ensure the user experience.

[0042] Optionally, the specific implementation of determining the priorities of each reference loop object according to the processing priorities of each reference task may be described as follows. Each reference loop object is pre-set with a corresponding reference task. For example, if the reference tasks to be executed by a certain reference loop object include reference task A1, reference task A2, and reference task A3, then the priority of the reference loop object can be determined according to the processing priorities of the reference tasks included in the reference loop object. For example, the sum value between the processing priorities of reference task A1, reference task A2, and reference task A3 can be used as the priority of the reference loop object. Another example is that the sum value after weighting the processing priorities of reference task A1, reference task A2, and reference task A3 at different levels can be used as the priority of the reference loop object. Other methods can also be used to determine the priority of the reference loop object.

[0043] S202: Perform survival processing on the target loop object to obtain the target loop object after survival.

[0044] Among them, survival processing may refer to injecting a specified source into the target loop object. For example, the specified source can be a custom input source, and the target loop object after survival can refer to the target loop object that can run.

[0045] In one implementation, a specified source can be injected into a target loop object to keep the target loop object alive, that is, to enable the target loop object to run. Optionally, a target interface can be added to the target loop object to pass the source information of the specified source to the target loop object through the target interface. The specified source can be the above-mentioned custom input source, and the source information can include a source object and a source mode, and the source mode can be NSRunloopCommonModes. After the source information of the specified source is passed into the target loop object, the target loop object that has become alive can be obtained, that is, the target loop object can run. Then, the running target loop object can continuously monitor the tasks in the subroutine corresponding to the target loop object to execute the task using the target loop object.

[0046] S203: When the target task in the sub-thread corresponding to the target loop object is monitored, execute the target task using the target loop object that has become alive.

[0047] In one implementation, a sub-thread can manage one or more target tasks, that is, it can execute one or more target tasks. The target loop object corresponding to a sub-thread can monitor the one or more target tasks. When any of the one or more target tasks is to be executed, the target task can be obtained to execute the target task using the target loop object that has become alive. For example, the tasks to be managed by a certain sub-thread include a download task and a page loading task. Then, when the target loop object corresponding to the sub-thread monitors that there is a page loading task to be executed currently, the page loading task can be obtained and the page loading task can be executed using the target loop object that has become alive.

[0048] In one implementation, after a loop object is added and run in a sub-thread, the program of this sub-thread is always in a do-while loop, that is, if the tasks of the sub-thread are not completed, the sub-thread will not be destroyed. If this sub-thread is to be destroyed, the loop object can be stopped. In this application, when the tasks of the sub-thread corresponding to the target loop object end, the target loop object can be destroyed. That is to say, during the life cycle of the target loop object, if the target tasks in the sub-thread are executed completely. For example, if a certain network request and data processing to be executed in a sub-thread are already processed in the sub-thread, the target loop object can be destroyed. Optionally, the implementation manner of destroying the target loop object can be to remove the source information of the specified source in the target loop object that has become alive. Among them, CFRunloopRemoveSource can be called to remove the source information of the specified source in the target loop object. Optionally, the implementation manner of destroying the target loop object can be to remove the target interface added to the target loop object.

[0049] In one implementation, when a user starts a certain application using a terminal (such as a mobile phone) and enables the video playback function in the application, when the application enters the background, the video playback function has not stopped, that is, the user may still be able to hear the sound played by the video. At this time, the user may not need to continue video playback. And when the video playback function is running continuously, the mobile phone may get hot, or the life of the mobile phone may be reduced. It may also affect the normal operation of other functional modules, thus affecting the user experience. Therefore, after the application enters the background, it is possible to consider stopping some functional modules in the application to ensure the normal operation of each task in the background of the application.

[0050] Optionally, after the application enters the background, it is also possible to monitor whether the reference loop object corresponding to the target functional module in all functional modules included in the application is still running. Among them, the target functional module can be a low-priority functional module. If it is monitored that the reference loop object corresponding to the target functional module is in a running state, and it is detected that the call frequency of the reference loop object corresponding to the target functional module for the target event exceeds the specified frequency, then the reference loop object corresponding to the target functional module can be stopped from running. The specified frequency can be sent to the application by the server when sending the processing priorities of each reference task to the application. The specified frequency can be the inherent frequency of the RunLoop call event. For example, the inherent frequency can be 100 times per second. For example, assume that the specified frequency is 100 times per second, and the call frequency of the reference loop object for the target event is 130 times per second. Then it can be determined that the call frequency of the reference loop object corresponding to the target functional module for the target event exceeds the specified frequency. Then, the reference loop object corresponding to the target functional module can be stopped from running. Among them, the target event can include touch events, timer events, input source events, etc.

[0051] Optionally, the priority of a functional module can be determined according to the processing priorities of each reference task included in the functional module. For example, a certain functional module in the application is a video playback module. The video playback module can include a download task and a page loading task. The sum value between the processing priority of the download task and the processing priority of the page loading task can be used as the priority of the playback module. According to the above method, the priorities corresponding to all functional modules in the application can be determined. Then, the functional module with a lower priority can be determined as the target functional module. Optionally, the priorities corresponding to each functional module can also be set in advance, so that the functional module with a lower priority can be determined according to the priorities corresponding to each functional module set in advance. Among them, the target functional module can be the functional module corresponding to the priority located in the last K positions in the descending order sorting result of the priorities corresponding to the functional modules. The value of K can be a numerical value such as 1 or 2.

[0052] In the embodiments of the present application, after the application enters the background, a target loop object can be obtained from multiple reference loop objects corresponding to the application, and the target loop object can be processed for survival to obtain the target loop object after survival. When a target task in the child thread corresponding to the target loop object is monitored, the target task can be executed by using the target loop object after survival. By implementing the above method, when the application enters the background, the loop object can be used to ensure the execution of tasks corresponding to important child threads, tasks can be processed and scheduled according to the priorities of each task, the execution efficiency of tasks can be improved, the consumption of the central processing unit by the child threads of each functional module of the application can be managed, and the monitoring burden of the central processing unit on background applications can be reduced, thereby effectively enhancing the stability of the application.

[0053] Please refer to Figure 3 , Figure 3 which is a schematic flowchart of another data processing method provided by the embodiments of the present application. As Figure 3 shown, the data processing method may include:

[0054] S301: If the application is started, obtain the set of reference tasks for each functional module in the functional module set of the application that runs in the background.

[0055] In one implementation, when the application is started, the tasks that each functional module included in the application needs to run in the background can be obtained. For example, the functional modules of an application may include a download module, a statistics module, an advertisement module, etc. Among them, the download module can support offline download in the background, so the download module can include download tasks; the statistics module can report data on the user's operation behavior, so the statistics module can include statistics tasks; the advertisement module can preload advertisement content, so the advertisement module can include content preloading tasks. In each functional module of the application, multiple threads are usually used to ensure the normal operation of the functional module. For example, multiple threads can be used for time-consuming operations such as network requests and data processing. That is to say, the tasks in a functional module can include one or more tasks. For example, the download module can include one or more download tasks. Among them, the tasks that each functional module needs to run in the background can be used as reference tasks. Then, the set of reference tasks for each functional module in the functional module set of the application that runs in the background can be obtained, where the set of reference tasks can include multiple reference tasks.

[0056] In one implementation, considering that the functional modules in the application may be updated each time the application is launched. For example, the version of the functional module may be upgraded. Then, when obtaining the reference task currently, it can be detected whether the version of the functional module corresponding to the reference task is the same as the version of the functional module corresponding to the reference task obtained when the application was launched last time. If they are not the same, the reference task in the current version of the functional module can be obtained. If they are the same, there is no need to obtain the reference task again.

[0057] In one implementation, after obtaining the reference task set, a module processing class can also be created. A global dictionary and protocol attributes can be maintained in the module processing class. Among them, the global dictionary can include a task list, and the obtained reference tasks can be injected into the method list. The task list can include the task identifiers corresponding to each reference task and the processing priorities corresponding to each reference task. The processing priority of the reference task is determined after the server obtains the task information of each reference task. The specific determination method can refer to the description in step S201 above and will not be elaborated here. The protocol attributes define the status of tasks of each functional module after entering the background. The status can include stop or suspend. Stop means that the application stops executing tasks after entering the background, and suspend means that the application can continue to execute tasks after entering the background. For example, when the functional module is a download module, the status of the download task in the download module entering the background can be defined as stop or suspend. The protocol attributes can also include the mapping relationship between the module identifier and the functional module. Each module identifier corresponds to a functional module and is not repeated. So that when the functional module needs to be used subsequently, the corresponding functional module or module identifier can be determined according to this mapping relationship.

[0058] S302: Create a plurality of sub-threads and a reference loop object corresponding to each sub-thread according to the reference task set.

[0059] In one implementation, the existing initial loop object can usually be used to handle listening port events, input source events, selector events, and timer events. Then, in order to enable the initial loop object to handle more other tasks, a loop object classification can be created, that is, tasks (the tasks can be understood as the above events) are added to the initial loop object, and the tasks can be set according to the user's needs. For example, a download task, a statistical task, etc. can be added to the initial loop object. In this application, for any one of the plurality of sub-threads, determine the reference tasks to be managed by the sub-thread, that is, the reference tasks to be executed when the sub-thread is running. Among them, the number of reference tasks corresponding to the sub-thread can be one or more. When the number of reference tasks is multiple, the multiple reference tasks corresponding to the sub-thread can be reference tasks in the same functional module or reference tasks in different functional modules.

[0060] In one implementation, after determining the reference tasks corresponding to the child threads, one or more reference tasks corresponding to the child threads can be marked in each functional module to obtain the marked reference tasks. Optionally, the reference tasks in the sub-module header file can be obtained in the init method of each functional module. After obtaining the reference tasks, the reference tasks to be called by the child threads can be marked through Method swizzling, so as to obtain the marked reference tasks. The Method swizzling method allows the application to dynamically generate classes and objects during runtime to achieve task replacement. That is, the original reference tasks can be replaced with the marked reference tasks by using the Method swizzling method. Among them, the reference tasks to be marked in each functional module can be preset in the protocol attributes, and the reference tasks to be marked can be set according to requirements.

[0061] For example, some of the reference tasks in each functional module can be used as the reference tasks to be marked, or all of the reference tasks in each functional module can be used as the reference tasks to be marked. After obtaining the marked reference tasks, the marked reference tasks can be added to the initial loop object corresponding to the child thread, and then, the reference loop object corresponding to the child thread can be obtained. The reference loop object can listen for the marked reference tasks during runtime. When the marked reference tasks are monitored, the marked reference tasks can be obtained, and the marked reference tasks can be executed using the reference loop object.

[0062] S303: If the application enters the background, obtain the target loop object from the multiple reference loop objects corresponding to the application.

[0063] S304: Perform survival processing on the target loop object to obtain the survived target loop object.

[0064] S305: When the target task in the child thread corresponding to the target loop object is monitored, execute the target task using the survived target loop object.

[0065] Among them, for the specific implementation manners of steps S303 - S305, reference can be made to the specific descriptions of steps S201 - S203 in the above embodiments, which will not be elaborated here.

[0066] In the embodiment of the present application, when the application starts, the reference task set for each functional module running in the background in the functional module set of the application can be obtained, and multiple sub-threads and the corresponding reference loop objects for each sub-thread can be created according to the reference task set. When the application enters the background, the target loop object can be obtained from the multiple reference loop objects, and the target loop object can be processed for survival to obtain the survived target loop object. When the target task in the sub-thread corresponding to the target loop object is monitored, the survived target loop object can be used to execute the target task. By implementing the above method, when the application enters the background, the tasks processed by multiple threads can be injected into the task list, and the loop object can be used to ensure the execution of the tasks corresponding to the important sub-threads. The tasks can be processed and scheduled according to the priorities of each task, the execution efficiency of the tasks can be improved, and the consumption of the central processing unit by the sub-threads of each functional module of the application can be managed, thereby effectively enhancing the stability of the application.

[0067] For a better understanding of the data processing method provided by the embodiment of the present application, the following further description will be made in combination with Figure 4 the process shown below. As Figure 4 shown, when the application is started, the reference tasks that each functional module included in the application needs to run in the background can be obtained, and it can be determined whether the reference tasks have been injected into the task list. If the reference tasks have been injected into the method list, a global dictionary can be generated according to the processing priorities of each reference task sent from the server, and the global dictionary includes the processing priorities corresponding to each reference task in the method list. Among them, the processing priorities of each reference task sent from the server can be determined according to the task information corresponding to each reference task sent by the application. After the server determines the processing priorities corresponding to each reference task, the processing priorities corresponding to each reference task can be sent to the application.

[0068] In one implementation, there may be a situation where the reference tasks are not injected into the task list. In this case, the tasks that need to run in the background indicated in the header file of the functional module can be obtained and injected into the task list. Optionally, since the functional module may be updated in version each time it is started, there may also be a situation where the reference tasks are not injected into the task list. Then, the reference tasks corresponding to the functional module after the version update can be obtained and injected into the task list.

[0069] In one implementation, after the application determines the processing priorities of each reference task, it can determine the priorities of each reference loop object according to the processing priorities of each reference task, so that it can determine the target loop object from multiple reference loop objects according to the priorities of each reference loop object, and the target loop object can be a reference loop object with a higher priority.

[0070] For example, optionally, the implementation of determining the target loop object can be: the priorities of each reference loop object can be sorted in descending order to obtain the sorting result of the loop object priorities, and the application can cache the sorting result of the loop object priorities in the memory. After the application enters the background, the first L reference loop objects in the sorting result of the loop object priorities can be determined as the target loop object. Among them, L can be any value such as 2 or 3, or can be determined according to the current power of the terminal or the type of the application, etc. After determining the target loop object, it is also necessary to perform a survival process on the target loop object so that the target loop object can be run. Optionally, a custom input source (the custom input source can be understood as the specified source above) can be injected into the target loop object. Among them, the process of injecting the custom input source can be described as follows: a target interface can be added to the target loop object, and the custom input source is passed in through the target interface, and the input source can include a source object and a source mode, and the source mode can be NSRunloopCommonModes.

[0071] In one implementation, during the life cycle of the target loop object, if the target task in the child thread corresponding to the target loop object is executed, for example, a certain network request and data processing have been completed in the child thread, then CFRunloopRemoveSource can be called to remove the current custom input source so that the target loop object stops.

[0072] In one implementation, after the application enters the background, it can also detect whether a function module with a lower priority (the function module with a lower priority is the above-mentioned target function module) is running a reference loop object. If it is not detected that the function module with a lower priority is running a reference loop object, then the normal operation of the application in the background can be guaranteed. If it is detected that the function module with a lower priority is running a reference loop object, it can further detect whether the call frequency of the reference loop object for the target event exceeds the specified frequency. Among them, the target event can include touch events, timer events, input source events, etc. If it is not detected that the call frequency of the reference loop object for the target event exceeds the specified frequency, then the normal operation of the application in the background can be guaranteed. If it is detected that the call frequency of the reference loop object for the target event exceeds the specified frequency, then the reference loop object can be stopped to ensure the normal operation of the application in the background.

[0073] Please refer to Figure 5 , Figure 5 which is a schematic structural diagram of a data processing device provided by an embodiment of the present application. The data processing device described in this embodiment includes:

[0074] An acquisition unit 501, configured to obtain a target loop object from multiple reference loop objects corresponding to the application program if the application program enters the background;

[0075] A survival unit 502, configured to perform a survival process on the target loop object to obtain a survived target loop object;

[0076] An execution unit 503, configured to execute the target task by using the survived target loop object when a target task in a child thread corresponding to the target loop object is monitored.

[0077] In one implementation manner, the acquisition unit 501 is further configured to:

[0078] If the application program is started, obtain a set of reference tasks for each function module in the function module set of the application program running in the background, where the set of reference tasks includes multiple reference tasks;

[0079] Create multiple child threads and a reference loop object corresponding to each child thread according to the reference tasks included in the set of reference tasks.

[0080] In one implementation manner, the acquisition unit 501 is specifically configured to:

[0081] Determine the processing priority of each reference task in the set of reference tasks;

[0082] Determine a target loop object from multiple reference loop objects corresponding to the application program according to the processing priority of each reference task.

[0083] In one implementation manner, the acquisition unit 501 is specifically configured to:

[0084] Create multiple child threads according to the reference tasks included in the set of reference tasks, where any one of the multiple child threads includes one or more reference tasks;

[0085] For any one of the multiple child threads, mark the one or more reference tasks corresponding to the child thread in each function module of the function module set to obtain a marked reference task;

[0086] Add the marked reference task to an initial loop object corresponding to the child thread to obtain a reference loop object corresponding to the child thread.

[0087] In one implementation manner, the obtaining unit 501 is specifically configured to:

[0088] Transmit the task information of each reference task to the server, so that the server determines the processing priorities of the respective reference tasks according to the task information;

[0089] Receive the processing priorities of the respective reference tasks sent by the server;

[0090] Determine the priorities of the respective reference loop objects according to the processing priorities of the respective reference tasks;

[0091] Sort the priorities of the respective reference loop objects in descending order to obtain a priority sorting result;

[0092] Determine the reference loop objects corresponding to the first L priorities in the priority sorting result as target loop objects, where L is a positive integer.

[0093] In one implementation manner, the survival unit 502 is specifically configured to:

[0094] Add a target interface to the target loop object, and transmit the source information of a specified source through the target interface to obtain a target loop object after survival;

[0095] After executing the target task by using the target loop object after survival, the following is further included:

[0096] Remove the source information of the specified source in the target loop object after survival.

[0097] In one implementation manner, the execution unit 503 is further configured to:

[0098] If it is monitored that the reference loop object corresponding to the target function module in the function module is in a running state, and it is detected that the call frequency of the reference loop object corresponding to the target function module for a target event exceeds a specified frequency, then stop running the reference loop object corresponding to the target function module.

[0099] It can be understood that the division of units in the embodiments of the present application is illustrative, and is only a logical function division. In actual implementation, there may be other division methods. Each functional unit in the embodiments of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above integrated units may be implemented in the form of hardware or in the form of software functional units.

[0100] Please refer to Figure 6 , Figure 6It is a schematic structural diagram of a data processing device provided by an embodiment of the present application. The data processing device described in this embodiment may include: a processor 601 and a memory 602. Optionally, the data processing device may further include a network interface 603. Data can be exchanged between the above-mentioned processor 601, memory 602, and network interface 603.

[0101] The above-mentioned processor 601 may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0102] The above-mentioned memory 602 may include a read-only memory and a random access memory, and provide program instructions and data to the processor 601. A part of the memory 602 may also include a non-volatile random access memory. Wherein, when the processor 601 calls the program instructions, it is used to execute:

[0103] If the application enters the background, obtain a target loop object from multiple reference loop objects corresponding to the application;

[0104] Perform a survival process on the target loop object to obtain a survived target loop object;

[0105] When a target task in the child thread corresponding to the target loop object is monitored, use the survived target loop object to execute the target task.

[0106] In one implementation, the processor 601 is further used for:

[0107] If the application is started, obtain a set of reference tasks for each function module in the background operation of the function module set of the application, and the set of reference tasks includes multiple reference tasks;

[0108] Create multiple child threads and corresponding reference loop objects for each child thread according to the reference tasks included in the set of reference tasks.

[0109] In one implementation, the processor 601 is specifically used for:

[0110] Determine the processing priority of each reference task in the reference task set;

[0111] Determine a target loop object from the multiple reference loop objects corresponding to the application according to the processing priority of each reference task.

[0112] In one implementation, the processor 601 is specifically configured to:

[0113] Create multiple child threads according to the reference tasks included in the reference task set, and any one of the multiple child threads includes one or more reference tasks;

[0114] For any one of the multiple child threads, mark one or more reference tasks corresponding to the child thread in each function module of the function module set to obtain marked reference tasks;

[0115] Add the marked reference tasks to the initial loop object corresponding to the child thread to obtain the reference loop object corresponding to the child thread.

[0116] In one implementation, the processor 601 is specifically configured to:

[0117] Transmit the task information of each reference task to the server so that the server determines the processing priority of each reference task according to the task information;

[0118] Receive the processing priorities of the respective reference tasks sent by the server;

[0119] Determine the priorities of the respective reference loop objects according to the processing priorities of the respective reference tasks;

[0120] Sort the priorities of the respective reference loop objects in descending order to obtain a priority sorting result;

[0121] Determine the reference loop objects corresponding to the first L priorities in the priority sorting result as target loop objects, where L is a positive integer.

[0122] In one implementation, the processor 601 is specifically configured to:

[0123] Add a target interface to the target loop object, and transmit the source information of a specified source through the target interface to obtain a survived target loop object;

[0124] After executing the target task using the survived target loop object, it further includes:

[0125] Remove the source information of the specified source from the survived target loop object.

[0126] In one implementation, the processor 601 is further configured to:

[0127] If it is monitored that the reference loop object corresponding to the target function module in the function module is in a running state, and it is detected that the call frequency of the reference loop object corresponding to the target function module for the target event exceeds the specified frequency, then stop running the reference loop object corresponding to the target function module.

[0128] The embodiment of the present application further provides a computer storage medium, in which program instructions are stored, and when the program is executed, it may include partial or all steps of the data processing method in the Figure 2 or Figure 3 corresponding embodiment.

[0129] It should be noted that for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present application is not limited by the described action sequence, because according to the present application, some steps may be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present application.

[0130] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing relevant hardware through a program. This program can be stored in a computer-readable storage medium, and the storage medium can include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disc, etc.

[0131] The embodiment of the present application further provides a computer program product or a computer program. The computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the data processing device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the data processing device executes the steps performed in the above embodiments of the various methods.

[0132] The above has introduced in detail a data processing method, device, equipment, and storage medium provided by the embodiments of the present application. Specific examples are used in this article to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application; at the same time, for those of ordinary skill in the art, according to the idea of the present application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present application.

Claims

1. A data processing method, characterized in that Including: If the application enters the background, obtain a target loop object from multiple reference loop objects corresponding to the application; The reference loop object is a run loop with a reference task added, and a corresponding child thread is created for each reference loop object. The target loop object is one or more of the multiple reference loop objects; Perform survival processing on the target loop object to obtain the survived target loop object; Performing survival processing on the target loop object includes: adding a target interface to the target loop object and passing the source information of a specified source through the target interface; When a target task in the child thread corresponding to the target loop object is monitored, execute the target task using the survived target loop object.

2. The method according to claim 1, wherein Before obtaining the target loop object from multiple reference loop objects, it further includes: If the application is started, obtain the set of reference tasks for each function module in the application's function module set to run in the background. The set of reference tasks includes multiple reference tasks; Create multiple child threads and the corresponding reference loop objects for each child thread according to the reference tasks included in the set of reference tasks.

3. The method according to claim 2, wherein The obtaining of the target loop object from multiple reference loop objects corresponding to the application includes: Determine the processing priority of each reference task in the set of reference tasks; Determine the target loop object from multiple reference loop objects corresponding to the application according to the processing priority of each reference task.

4. The method according to claim 2, wherein The creating of multiple child threads and the corresponding reference loop objects for each child thread according to the reference tasks included in the set of reference tasks includes: Create multiple child threads according to the reference tasks included in the set of reference tasks. Any one of the multiple child threads includes one or more reference tasks; For any one of the multiple child threads, mark the one or more reference tasks corresponding to the child thread in each function module of the function module set to obtain the marked reference tasks; Add the marked reference tasks to the initial loop object corresponding to the child thread to obtain the reference loop object corresponding to the child thread.

5. The method according to claim 3, wherein The determining of the processing priority of each reference task in the set of reference tasks includes: Pass the task information of each reference task to the server so that the server determines the processing priority of each reference task according to the task information; Receive the processing priority of each reference task sent by the server; The determining of the target loop object from multiple reference loop objects according to the processing priority of each reference task includes: Determine the priority of each reference loop object according to the processing priority of each reference task; Sort the priorities of each reference loop object in descending order to obtain a priority sorting result; Determine the reference loop objects corresponding to the first L priorities in the priority sorting result as the target loop objects, where L is a positive integer.

6. The method according to any one of claims 1-5, characterized in that, After executing the target task using the survived target loop object, it further includes: Remove the source information of the specified source from the survived target loop object.

7. The method according to any one of claims 2-5, characterized in that The method further includes: If it is monitored that the reference loop object corresponding to the target function module in the function module is in a running state, and it is detected that the call frequency of the reference loop object corresponding to the target function module for the target event exceeds the specified frequency, then stop running the reference loop object corresponding to the target function module.

8. A data processing device, characterized in that, It includes: An acquisition unit, configured to, if the application enters the background, acquire a target loop object from multiple reference loop objects corresponding to the application; The reference loop object is a run loop added with a reference task, and a corresponding child thread is created for each reference loop object, and the target loop object is one or more of the multiple reference loop objects; A survival unit, configured to perform a survival process on the target loop object to obtain a survived target loop object; Performing a survival process on the target loop object includes: adding a target interface to the target loop object, and passing in source information of a specified source through the target interface; An execution unit, configured to, when a target task in the child thread corresponding to the target loop object is monitored, execute the target task by using the survived target loop object.

9. A data processing device, characterized in that, It includes a processor and a memory. Among them, the memory is used to store a computer program, the computer program includes program instructions, and the processor is configured to call the program instructions to execute the method according to any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program includes program instructions, and the program instructions, when executed by a processor, cause the processor to execute the method according to any one of claims 1-7.

11. A computer program product, characterized in that, The computer program product includes computer instructions, and when the computer instructions are executed, the data processing device is caused to execute the method according to any one of claims 1-7.

Citation Information

Patent Citations

  • Thread management method and device, electronic equipment and storage medium

    CN111552567A

  • Multithread-based task processing method, device and equipment and storage medium

    CN112148480A