Task processing method and device for background thread, equipment and storage medium
By creating background threads when front-end application starts and controlling task scheduling according to computer equipment's performance indicators, background threads solve the problem of interface lag caused by computing-intensive or time-consuming tasks, improving processing efficiency and user experience.
Patent Information
- Application Number
- CN202411550958.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-02-18
AI Technical Summary
With the complexity of front-end application functions, when background threads process calculation-intensive or time-consuming tasks, it is easy to cause the front-end application interface to be stuck or slow response, thereby reducing processing efficiency.
By detecting the front-end application to obtain its configuration file when it is started, we can determine whether the task type meets the background thread creation conditions, create a background thread, and control the scheduling order of the background thread processing tasks according to the current performance indicators of the computer device.
It effectively improves the processing efficiency of the background threads on front-end application tasks, reduces interface lag and response delay, and improves user interaction experience.
Smart Images

Figure CN119473601A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of thread management, and in particular to a method, device, equipment and storage medium for processing tasks of a background thread. Background Art
[0002] With the continuous development of front-end technology, the functions of front-end applications are becoming more and more complex, and the performance requirements are becoming higher and higher. In the related technology, the computer device can combine the main thread and the background thread to process the tasks of the front-end application. For example, the background thread executes computationally intensive or time-consuming tasks to improve the performance of the front-end application. However, when executing computationally intensive or time-consuming tasks through the background thread, as the number of computationally intensive or time-consuming tasks increases, it is still easy for the application interface of the front-end application to freeze or respond slowly, which easily leads to poor processing efficiency of the background thread for the tasks of the front-end application. Summary of the invention
[0003] The main purpose of this application is to provide a background thread task processing method, device, equipment and storage medium, aiming to improve the processing efficiency of the background thread for the front-end application tasks.
[0004] In a first aspect, the present application provides a method for processing tasks of a background thread, comprising:
[0005] When it is detected that the front-end application is started, a configuration file corresponding to the front-end application is obtained;
[0006] When the configuration file indicates that the preset task type corresponding to the task included in the front-end application meets the background thread creation condition, create a background thread corresponding to the front-end application;
[0007] Obtaining current performance indicators of the computer device where the front-end application is located;
[0008] According to the current performance indicator, the background thread is controlled to process the tasks of the front-end application.
[0009] In a second aspect, the present application further provides a task processing device for a background thread, the task processing device comprising:
[0010] A first acquisition module is used to acquire a configuration file corresponding to the front-end application when detecting that the front-end application is started;
[0011] A thread creation module, configured to create a background thread corresponding to the front-end application when the configuration file indicates that a preset task type corresponding to a task included in the front-end application meets a background thread creation condition;
[0012] A second acquisition module is used to acquire the current performance index of the computer device where the front-end application is located;
[0013] The thread control module is used to control the background thread to process the task of the front-end application according to the current performance indicator.
[0014] In a third aspect, the present application further provides a computer device, the computer device comprising a memory and a processor;
[0015] The memory is used to store computer programs;
[0016] The processor is used to execute the computer program and implement the steps of the above-mentioned background thread task processing method when executing the computer program.
[0017] In a fourth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the background thread task processing method as described above are implemented.
[0018] The present application provides a method, apparatus, device and storage medium for processing tasks of a background thread, the method comprising: when it is detected that a front-end application is started, obtaining a configuration file corresponding to the front-end application; when the configuration file indicates that a preset task type corresponding to a task included in the front-end application meets a background thread creation condition, creating a background thread corresponding to the front-end application; obtaining the current performance index of the computer device where the front-end application is located; and according to the current performance index, controlling the background thread to process the tasks of the front-end application to improve the processing efficiency of the background thread on the tasks of the front-end application.
[0019] For example, when the current performance index of the computer device where the front-end application is located is used to control the background thread to process the tasks of the front-end application, the computer device can control the scheduling order of the back-end thread for the tasks of the front-end application based on the current performance index to maintain the current performance index or further optimize the current performance index. When the current performance index is maintained or optimized, the computer device can release the computing resources occupied by more front-end application tasks, and use the released computing resources to process more front-end application tasks, which is conducive to improving the processing efficiency of the back-end thread for the tasks of the front-end application. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0021] Figure 1It is a flowchart of a method for processing tasks of a background thread provided by an embodiment of the present application;
[0022] Figure 2 is a schematic block diagram of a background thread task processing device provided by an embodiment of the present application;
[0023] Figure 3 It is a schematic block diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0024] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0025] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.
[0026] The embodiments of the present application provide a method, apparatus, device and storage medium for processing tasks of a background thread. Among them, the task processing method of the background thread can be applied to a computer device. The computer device can be a tablet computer, a laptop computer, a desktop computer and other devices. It can also be applied to a server, which can be a separate server or a server cluster, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.
[0027] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0028] See also Figure 1 , Figure 1It is a flowchart of a method for processing a task of a background thread provided by an embodiment of the present application. It should be noted that the method for processing a task of a background thread provided by an embodiment of the present application can be used in a computer device, and of course can also be used in a server. For example, when the server detects that the front-end application is started, it can obtain a configuration file corresponding to the front-end application from the computer device, and according to the task processing of the background thread, control the computer device to create a background thread corresponding to the front-end application, and control the background thread accordingly. Of course, it is not limited to this, and no limitation is made here.
[0029] In specific implementation, the computer device includes but is not limited to: any one of a tablet computer, a laptop computer, and a desktop computer; the server can be a single server or a server cluster, or a cloud server that provides cloud computing services.
[0030] like Figure 1 As shown, the task processing method of the background thread includes steps S101 to S104.
[0031] Step S101: When it is detected that the front-end application is started, a configuration file corresponding to the front-end application is obtained.
[0032] In some embodiments, when the computer device detects that the front-end application is started, the computer device may determine that the front-end application needs to perform a corresponding task in response to the user's operation. The tasks that the front-end application needs to perform are likely to affect the response rate of the front-end application. Accordingly, tasks of different preset task types included in the front-end application may have different effects on the response rate of the front-end application.
[0033] Based on this, when the configuration file corresponding to the front-end application can be used to indicate the preset task type corresponding to the task included in the front-end application, the computer device can obtain the configuration file corresponding to the front-end application, so as to subsequently determine whether it is necessary to create a background thread based on the configuration file, so as to schedule the tasks of the front-end application through the background thread.
[0034] Step S102: When the configuration file indicates that the preset task type corresponding to the task included in the front-end application meets the background thread creation condition, a background thread corresponding to the front-end application is created.
[0035] For example, the tasks included in the front-end application may include user interface rendering tasks, event processing tasks, computationally intensive tasks, I / O intensive tasks, other tasks that require parallel processing, and the like, which are not limited here. For example, computationally intensive tasks may include a large number of mathematical calculations, data processing, and other computationally intensive tasks, which are not limited here. I / O intensive tasks may include file reading and writing, network communication, and other tasks that require waiting for I / O operations to complete, which are not limited here. Other tasks that require parallel processing may include image processing, video encoding, and other tasks that can improve execution efficiency through parallel processing, which are not limited here.
[0036] The preset task types corresponding to the different tasks included in the front-end application may be different. For example, for computationally intensive tasks, such as excessive js operations, since array operations, set operations, and complex string processing are involved, the computer device can determine that the preset task type corresponding to the computationally intensive task is a data operation class. For I / O intensive tasks, such as network communications, since the processing and response processing of network requests are involved, the processing of network requests may include data resource requests, file upload / download processing, image segmentation requests, etc., the computer device can determine that the preset task type corresponding to the I / O intensive task is a network request class. For other tasks that require parallel processing, such as image processing, since they involve image processing, analysis, transformation, and binary data conversion, etc., the computer device can determine that the preset task type corresponding to other tasks that require parallel processing is an image processing class.
[0037] In some embodiments, since computationally intensive tasks, I / O intensive tasks, and other tasks that require parallel processing are all computationally intensive or time-consuming tasks, if the computer device processes computationally intensive or time-consuming tasks through the main thread, it is easy for the application interface of the front-end application to freeze or respond slowly. For example, the computer device can process computationally intensive or time-consuming tasks through the background thread by creating a background thread corresponding to the front-end application to reduce the possibility of the application interface of the front-end application freezing or responding slowly. Based on this, the computer device can set the background thread creation condition to the preset task type including at least one of the data operation class, the network request class, and the image processing class. In an exemplary embodiment, when the configuration file corresponding to the front-end application indicates that the task type corresponding to the task included in the front-end application is at least one of the data operation class, the network request class, and the image processing class, the computer device can determine that the preset task type indicated by the configuration file meets the background thread creation condition. Accordingly, the computer device can create the background thread corresponding to the front-end application.
[0038] For example, a computer device may create a background thread corresponding to a front-end application through a background thread constructor. The number of background threads may include one or more, which is not limited here. The background thread constructor may be a function constructed based on a literal language, such as JavaScript (JS). Taking the background thread including a Web Worker thread as an example, the background thread constructor may include a Worker() constructor. Of course, it is not limited to this and is not limited here.
[0039] When a background thread corresponding to a front-end application is created, each background thread can execute an independent running code file. The running code file may include the code running in the background thread. The running code file may include a JS file, etc., which is not limited here.
[0040] Accordingly, when a background thread corresponding to a front-end application is created, the computer device can mark each background thread to determine the identification information of the background thread. The computer device can monitor the background thread based on the identification information of the background thread to obtain the monitoring log corresponding to the background thread.
[0041] In some embodiments, the computer device is responsible for maintaining a background thread pool, which may include multiple background threads, and the computer device may allocate and recycle the background threads. The size of the background thread pool may be dynamically adjusted according to the needs of the front-end application and the resource status of the computer. Accordingly, the computer device may perform data statistics for each background thread to view and calculate the operating efficiency of the background thread, which is not limited here.
[0042] For example, the background thread can communicate with the main thread based on a preset communication mechanism. For example, the background thread can communicate through preset communication functions, such as postMessage() and onmessage events, which are not limited here. The main thread can send data or messages to the background thread, and the background thread can also send data or results back to the main thread.
[0043] The background thread and the main thread can synchronize data. For example, for data that needs to be shared, the computer device can use a shared memory or database to synchronize data to ensure the consistency and correctness of the data in a multi-threaded environment.
[0044] In this way, when the configuration file indicates that the preset task type corresponding to the task included in the front-end application meets the background thread creation conditions, the computer device can create a background thread corresponding to the front-end application. The background thread can be used by the computer device to process computing-intensive or time-consuming tasks to avoid hindering the task processing efficiency of the main thread, thereby reducing the occurrence of application interface freezes or slow responses of the front-end application.
[0045] Step S103: Obtain the current performance index of the computer device where the front-end application is located.
[0046] When creating a background thread corresponding to the front-end application, since the computer device can schedule the tasks of the front-end application through the background thread, the computer device can evaluate the freeze of the application interface of the front-end application and the response speed of the front-end application when the background thread schedules the tasks of the front-end application, so as to evaluate the processing effect of the background thread on the tasks of the front-end application.
[0047] For example, the computer device can evaluate the processing effect of the background thread on the front-end application's tasks based on the current performance index. For example, when the background thread schedules the front-end application's tasks, the current performance index of the computer device continues to deteriorate, then the computer device can determine that it is necessary to perform task scheduling management on the background thread to maintain the current performance index or further optimize the current performance index. Based on this, the computer device can use the current performance index of the computer device as the basis for performing task scheduling management on the background thread.
[0048] In some implementations, the current performance indicator is determined based on at least one of a CPU occupancy rate, a memory usage rate, and a capacity ratio between a background thread occupancy capacity and a total system capacity of the computer device.
[0049] For example, the computer device may obtain the CPU occupancy rate, memory usage rate, and the capacity ratio between the background thread occupancy capacity and the total system capacity. Accordingly, the computer device may calculate the average value corresponding to at least one of the CPU occupancy rate, memory usage rate, and capacity ratio to determine the current performance indicator. For example, when the computer device obtains the CPU occupancy rate, memory usage rate, and capacity ratio, the computer device may calculate the average value between the CPU occupancy rate, memory usage rate, and capacity ratio, and determine the average value as the current performance indicator of the computer device.
[0050] In this way, when the current performance indicators of the computer device where the front-end application is located are obtained, the computer device can subsequently perform task scheduling management on the background thread based on the current performance indicators, so as to subsequently improve the processing efficiency of the background thread for the tasks of the front-end application, thereby reducing the possibility of the front-end application interface being stuck or the front-end application responding slowly, and improving the user's interactive experience with the front-end application.
[0051] Step S104: Control the background thread to process the tasks of the front-end application according to the current performance index.
[0052] The computer device can combine the monitoring log of the background thread and the historical performance indicators of the computer device to perform a large amount of data analysis to determine the task scheduling management strategy of the background thread corresponding to different historical performance indicators. The task scheduling management strategy can limit the scheduling order of tasks of different preset task types. Accordingly, the computer device can obtain the task scheduling management strategy corresponding to the current performance indicator from the task scheduling management strategy of the background thread corresponding to different historical performance indicators based on the current performance indicator, and control the background thread to process the tasks of the front-end application based on the task scheduling management strategy.
[0053] In some embodiments, based on the association between a preset performance indicator and a preset task scheduling order, a target task scheduling order corresponding to the current performance indicator is determined according to the current performance indicator; and the background thread is controlled to process the tasks of the front-end application according to the target task scheduling order.
[0054] For example, the computer device may establish an association relationship between a preset performance indicator and a preset task scheduling order based on the task scheduling management strategy of the background threads corresponding to different historical performance indicators. Among them, the preset performance indicator may be determined based on the historical performance indicator, and the preset task scheduling order may be determined based on the scheduling order between tasks of different preset task types indicated by the task scheduling management strategy. Accordingly, the computer device may store the association relationship between the preset performance indicator and the preset task scheduling order for managing the background thread when the background thread processes the task of the front-end application. In an exemplary embodiment, the computer device may configure the association relationship between the preset performance indicator and the preset task scheduling order into a configuration file corresponding to the front-end application for managing the background thread corresponding to the front-end application, which is not limited here.
[0055] When the computer device obtains the current performance indicator, it can determine whether there is a preset performance indicator corresponding to the current performance indicator. For example, the preset performance indicator can be embodied as a performance indicator parameter, or as a performance indicator parameter range. When the current performance indicator is the same as the performance indicator parameter indicated by the preset performance indicator, or the current performance indicator is within the performance indicator parameter range indicated by the preset performance indicator, the computer device can determine that the preset performance indicator is the preset performance indicator corresponding to the current performance indicator. In the case where there is a preset performance indicator corresponding to the current performance indicator, the computer device can determine the preset task scheduling order associated with the preset performance indicator as the target task scheduling order corresponding to the current performance indicator based on the association relationship between the preset performance indicator and the preset task scheduling order.
[0056] Accordingly, when the target task scheduling order corresponding to the current performance indicator is determined, the computer device can control the background thread to process the tasks of the front-end application according to the target task scheduling order, so that the computer device can maintain the current performance indicator or further optimize the current performance indicator, thereby improving the processing efficiency of the background thread for the tasks of the front-end application.
[0057] In some implementations, when the current performance indicator is less than or equal to a first indicator threshold, the target task scheduling order is determined to be any one of a first-in-first-out order and a first priority order among a plurality of preset task types.
[0058] When the current performance index is less than or equal to the first index threshold, the computer device can determine that the computing resources of the computer device are relatively sufficient, and the flexibility of the task scheduling management strategy of the computer device for the background thread can be relatively high. The first index threshold can be pre-set or set by the user. For example, the first index threshold can include 10%, 15%, 20%, etc., which is not limited here.
[0059] For example, the computer device may determine that the target task scheduling order corresponding to the current performance indicator is any one of a first-in-first-out order and a first priority order among multiple preset task types based on the current performance indicator being less than or equal to a first indicator threshold.
[0060] When the target scheduling order is a first-in-first-out order, the computer device may preferentially schedule the earliest arriving task in the task queue corresponding to the background thread, so as to control the background thread to process the earliest arriving task.
[0061] When the target scheduling order is the first priority order, the computer device can control the background thread to process tasks of different preset task types according to the preset task types corresponding to each task in the task queue corresponding to the background thread, combined with the scheduling priorities between the multiple preset task types indicated by the first priority order. Taking the first priority order indicating that the data operation class takes precedence over the network request class, and the network request class takes precedence over the image processing class as an example, the computer device can prioritize the data operation class tasks in the task queue corresponding to the background thread, then schedule the network request class tasks, and finally schedule the image processing class tasks. Of course, the first priority order is not limited to this. The first priority order, for example, indicates that the network request class takes precedence over the data operation class, and the data operation class takes precedence over the image processing class, or the first priority order, for example, indicates that the data operation class takes precedence over the image processing class, and the image processing class takes precedence over the network request class, and so on, which are not limited here.
[0062] In this way, when the current performance index is less than or equal to the first index threshold, since the target task scheduling order is any one of the first-in-first-out order and the first priority order among multiple preset task types, the computer device can flexibly control the background thread to process the tasks of the front-end application based on the first-in-first-out order and the first priority order among multiple preset task types, which is conducive to the subsequent improvement of the flexibility of the background thread to process the tasks of the front-end application. Based on the improvement of the processing flexibility of the background thread to the front-end application, the computer device can flexibly control the background thread to process the tasks of the front-end application based on the actual task processing requirements of the front-end application, which is conducive to maintaining the current performance index of the computer device or further optimizing the current performance index, thereby facilitating the improvement of the processing efficiency of the background thread to the tasks of the front-end application.
[0063] In some implementations, when the current performance indicator is greater than a first indicator threshold and less than or equal to a second indicator threshold, the target task scheduling order is determined to be a second priority order among a plurality of preset task types.
[0064] When the current performance index is greater than the first index threshold and less than or equal to the second index threshold, the computer device can determine that the computing resources of the computer device are gradually decreasing, and the computer device can maintain the current performance index or further optimize the current performance index by gradually reducing the flexibility of the task scheduling management strategy of the background thread. The second index threshold may include 25%, 30%, 35%, 40%, etc., which are not limited here.
[0065] For example, the computer device may determine that the target task scheduling order corresponding to the current performance indicator is the second priority order based on the current performance indicator being greater than the first indicator threshold and less than or equal to the second indicator threshold. The second priority order may be the same as the first priority order or different from the first priority order, which is not limited here.
[0066] In an exemplary embodiment, the computer device may divide the indicator threshold range between the first indicator threshold and the second indicator threshold into a plurality of indicator threshold sub-ranges based on the first indicator threshold and the second indicator threshold. Taking the first indicator threshold as 20% and the second indicator threshold as 40% as an example, the computer device may divide the indicator threshold range between 20% and 40% into an indicator threshold sub-range between 20% and 30% and an indicator threshold sub-range between 30% and 40%. For different indicator threshold sub-ranges, the corresponding second priority order may be different. For example, for the indicator threshold sub-range between 20% and 30%, the second priority order may be used to indicate that the data operation class takes precedence over the network request class, and the network request class takes precedence over the image processing class. For the indicator threshold sub-range between 30% and 40%, the second priority order may be used to indicate that the network request class takes precedence over the data operation class, and the data operation class takes precedence over the image processing class. Since image processing tasks have the highest computational complexity and consume the most computing resources of the computer device, network request tasks have the second highest computational complexity and consume less computing resources of the computer device than image processing tasks, and data computing tasks have the lowest computational complexity and consume less computing resources of the computer device than network request tasks, when the target task scheduling order is the second priority, when the computer device subsequently controls the background thread to process the tasks of the front-end application, it can give priority to processing at least one of the network request tasks and the data computing tasks, so as to avoid image processing tasks from causing processing congestion to tasks of other preset task types in the task queue, so as to maintain the current performance indicators of the computer device or further optimize the current performance indicators, thereby improving the processing efficiency of the background thread on the tasks of the front-end application.
[0067] In this way, when the current performance indicator is greater than the first indicator threshold and less than or equal to the second indicator threshold, since the target task scheduling order is the second priority order among multiple preset task types, the computer device can subsequently control the background thread to give priority to tasks with less computing resource consumption, so as to avoid tasks with greater computing resource consumption from blocking other tasks with less computing resource consumption, so that the background thread can process more tasks within a certain period of time, which is conducive to the subsequent improvement of the background thread's task processing efficiency for the front-end application.
[0068] In some embodiments, when the current performance indicator is greater than the second indicator threshold and less than or equal to the third indicator threshold, the target task scheduling order is determined to be a third priority order among multiple preset task types; the third priority order is determined based on preset priority configuration information among multiple preset task types.
[0069] Exemplarily, the preset priority configuration information is configured by the user. For example, when the user is using a front-end application, the computer device may determine the third priority order by considering the user's interaction requirements for the front-end application.
[0070] For example, when the current performance indicator is greater than the second indicator threshold and less than or equal to the third indicator threshold, the preset task scheduling order associated with the preset performance indicator corresponding to the current performance indicator may include at least one task scheduling order to be configured. The third indicator threshold may include 45%, 50%, 55%, 60%, etc., which are not limited here.
[0071] In an exemplary embodiment, when the current performance index is greater than the second index threshold and less than or equal to the third index threshold, the computer device can determine that the computing resources of the computer device are less, and the computer device can output a priority order configuration prompt based on maintaining the current performance index or further optimizing the current performance index and the user's interactive needs for the application. In the case where the user gives feedback to the priority order configuration prompt, the computer device can determine the preset priority configuration information according to the configuration feedback information corresponding to the priority order configuration prompt, so as to configure the scheduling order of the task to be configured according to the preset priority configuration information, and obtain the target task scheduling order, that is, the third priority order between multiple preset task types. For example, the priority order configuration prompt can be displayed in at least one of the forms of text, animation, animated image, etc., for multiple preset task types, such as network request type, data operation type, and image processing type. The computer device can determine the configuration feedback information corresponding to the priority order configuration prompt based on the display position change information of multiple preset task types after the user's interactive operation on at least one preset task type, so that the computer device can determine the third priority order. Interactive operations include, for example, moving operations, drag operations, etc., which are not limited here.
[0072] In another exemplary embodiment, when the current performance indicator is greater than the second indicator threshold and less than or equal to the third indicator threshold, the user can change the working mode of the computer device. Working modes include, for example, normal mode, power saving mode, extreme speed mode, etc., which are not limited here. Different working modes may correspond to different preset priority configuration information. Based on this, the computer device can further combine the preset priority configuration information corresponding to the working mode of the computer device to determine the target task scheduling order, that is, the third priority order between multiple preset task types, when the preset task scheduling order that is associated with the preset performance indicator corresponding to the current performance indicator includes multiple task scheduling orders to be configured.
[0073] In this way, the computer device can comprehensively consider the relationship between the preset performance indicators and the preset task scheduling order and the preset priority configuration information to determine the target task scheduling order, such as the third priority order, so as to subsequently improve the processing efficiency of the background thread for the tasks of the front-end application, while giving priority to meeting the user's interaction needs for the front-end application, which is conducive to improving the user's experience of the front-end application.
[0074] In some embodiments, the preset task types include a first task type and a second task type other than the first task type; the computational complexity of the tasks of the first task type is less than that of the tasks of the second task type, and the computational resource consumption of the tasks of the first task type is less than that of the tasks of the second task type.
[0075] When the current performance indicator is greater than the third indicator threshold, the target task scheduling order is determined to be a scheduling order of tasks of the first task type before a scheduling order of tasks of the second task type.
[0076] When the current performance indicator is greater than the third indicator threshold, the computer device can determine that the computing resources of the computer device are extremely few, and accordingly, the use of computing resources is relatively tight. The computer device can then give priority to processing tasks with low computational complexity and less consumption of computing resources, so as to minimize the occupancy rate of computing resources by tasks, so that the computer device can provide more computing resources to process subsequent tasks.
[0077] Take the preset task types including data computing, network request and image processing as an example. When the current performance index is greater than the third index threshold, since the computational complexity of data computing tasks is the smallest and the consumption of computing resources is the least, the computer device can determine the first task type as data computing. The computer device can set the second task type to network request and image processing. Accordingly, the computer device can determine the scheduling order of the target task to be that the scheduling order of data computing tasks is before that of network request and image processing tasks. Based on this, the computer device can subsequently control the background thread to give priority to data computing tasks.
[0078] Of course, it is not limited to this, the computer device can also perform dimension reduction and delay scheduling on the tasks of the second task type. For example, the computer device can subsequently control the background thread to prioritize data computing tasks, and perform dimension reduction and delay scheduling on network request tasks and image processing tasks.
[0079] In this way, when the current performance indicator is greater than the third indicator threshold, the target task scheduling order is determined to be that the scheduling order of tasks of the first task type is before the scheduling order of tasks of the second task type, so that the computer device controls the background thread to give priority to processing tasks with the smallest computational complexity and the smallest computing resource consumption, and provides more computing resources to subsequent tasks, thereby optimizing the current performance indicator of the computer device, which is beneficial to improving the processing efficiency of the background thread for the tasks of the front-end application.
[0080] The task processing method of the background thread provided in the above embodiment obtains the configuration file corresponding to the front-end application when it is detected that the front-end application is started; creates the background thread corresponding to the front-end application when the configuration file indicates that the preset task type corresponding to the task included in the front-end application meets the background thread creation conditions; obtains the current performance indicator of the computer device where the front-end application is located; and controls the background thread to process the tasks of the front-end application according to the current performance indicator, so as to improve the processing efficiency of the background thread on the tasks of the front-end application.
[0081] For example, when the current performance index of the computer device where the front-end application is located is used to control the background thread to process the tasks of the front-end application, the computer device can control the scheduling order of the back-end thread for the tasks of the front-end application based on the current performance index to maintain the current performance index or further optimize the current performance index. When the current performance index is maintained or optimized, the computer device can release the computing resources occupied by more front-end application tasks, and use the released computing resources to process more front-end application tasks, which is conducive to improving the processing efficiency of the back-end thread for the tasks of the front-end application.
[0082] See also Figure 2 , Figure 2 The present invention provides a schematic block diagram of a task processing device for a background thread provided in an embodiment of the present invention. The task processing device can be configured in a server to execute the task processing method for the background thread described above.
[0083] like Figure 2 As shown, the task processing device includes: a first acquisition module 110 , a thread creation module 120 , a second acquisition module 130 and a thread control module 140 .
[0084] The first acquisition module 110 is used to acquire a configuration file corresponding to the front-end application when it is detected that the front-end application is started.
[0085] The thread creation module 120 is used to create a background thread corresponding to the front-end application when the configuration file indicates that the preset task type corresponding to the task included in the front-end application meets the background thread creation condition.
[0086] The second acquisition module 130 is used to acquire the current performance index of the computer device where the front-end application is located.
[0087] The thread control module 140 is used to control the background thread to process the task of the front-end application according to the current performance indicator.
[0088] It should be noted that technicians in the relevant field can clearly understand that for the convenience and simplicity of description, the specific working processes of the above-described devices and modules and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0089] The method of the present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld devices or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0090] Exemplarily, the above method and apparatus may be implemented in the form of a computer program, which may be run on a computer device.
[0091] See also Figure 3 , Figure 3 1 is a schematic block diagram of a computer device provided in an embodiment of the present application. The computer device may be a server or an electronic device.
[0092] like Figure 3 As shown, the computer device includes a processor, a memory, and a network interface connected via a system bus, wherein the memory may include a storage medium and an internal memory.
[0093] The storage medium can store an operating system and a computer program. The computer program includes program instructions, and when the program instructions are executed, the processor can execute any background thread task processing method.
[0094] The processor is used to provide computing and control capabilities and support the operation of the entire computer equipment.
[0095] The internal memory provides an environment for the operation of the computer program in the storage medium. When the computer program is executed by the processor, the processor can execute any task processing method of the background thread.
[0096] The network interface is used for network communication, such as sending assigned tasks, etc. Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0097] It should be understood that the processor may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0098] In one embodiment, the processor is used to execute a computer program and implement the following steps when executing the computer program:
[0099] When it is detected that the front-end application is started, a configuration file corresponding to the front-end application is obtained;
[0100] When the configuration file indicates that the preset task type corresponding to the task included in the front-end application meets the background thread creation condition, create a background thread corresponding to the front-end application;
[0101] Obtaining current performance indicators of the computer device where the front-end application is located;
[0102] According to the current performance indicator, the background thread is controlled to process the tasks of the front-end application.
[0103] It should be noted that technical personnel in the relevant field can clearly understand that, for the convenience and brevity of description, the specific working process of the task processing of the background thread described above can refer to the corresponding process in the aforementioned background thread task processing method embodiment, and will not be repeated here.
[0104] An embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. The method implemented when the computer program is executed by a processor can refer to the various embodiments of the task processing method of the background thread of the present application.
[0105] The computer-readable storage medium may be an internal storage unit of the computer device described in the foregoing embodiment, such as a hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc., equipped on the computer device.
[0106] It should be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0107] It should also be understood that the term "and / or" used in the specification of this application and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, including these combinations. It should be noted that, in this article, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "including a..." does not exclude the presence of other identical elements in the process, method, article or system including the element.
[0108] It should also be understood that the non-Company software tools or components appearing in the embodiments of the present application are merely examples and do not represent actual use.
[0109] The serial numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments. The above description is only a specific implementation mode of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A task processing method for a background thread, characterized in that: include: When it is detected that the front-end application is started, a configuration file corresponding to the front-end application is obtained; When the configuration file indicates that the preset task type corresponding to the task included in the front-end application meets the background thread creation condition, create a background thread corresponding to the front-end application; Obtaining current performance indicators of the computer device where the front-end application is located; According to the current performance indicator, the background thread is controlled to process the tasks of the front-end application.
2. The task processing method according to claim 1, characterized in that: The controlling the background thread to process the task of the front-end application according to the current performance indicator includes: Based on the association relationship between the preset performance indicator and the preset task scheduling order, according to the current performance indicator, determine the target task scheduling order corresponding to the current performance indicator; The background thread is controlled to process the tasks of the front-end application according to the target task scheduling order.
3. The task processing method according to claim 2, characterized in that: The determining, according to the current performance indicator, a target task scheduling order corresponding to the current performance indicator comprises: When the current performance indicator is less than or equal to the first indicator threshold, the target task scheduling order is determined to be any one of a first-in-first-out order and a first priority order among a plurality of preset task types.
4. The task processing method according to claim 2, characterized in that: The determining, according to the current performance indicator, a target task scheduling order corresponding to the current performance indicator comprises: When the current performance indicator is greater than a first indicator threshold and less than or equal to a second indicator threshold, the target task scheduling order is determined to be a second priority order among a plurality of preset task types.
5. The task processing method according to claim 2, characterized in that: The determining, according to the current performance indicator, a target task scheduling order corresponding to the current performance indicator comprises: When the current performance indicator is greater than the second indicator threshold and less than or equal to the third indicator threshold, the target task scheduling order is determined to be a third priority order among multiple preset task types; the third priority data is determined based on preset priority configuration information among multiple preset task types.
6. The task processing method according to claim 2, characterized in that: The preset task types include a first task type and a second task type other than the first task type; the computational complexity of the tasks of the first task type is less than the computational complexity of the tasks of the second task type, and the computational resource consumption of the tasks of the first task type is less than the computational resource consumption of the tasks of the second task type; The determining, according to the current performance indicator, a target task scheduling order corresponding to the current performance indicator comprises: When the current performance indicator is greater than a third indicator threshold, the target task scheduling order is determined to be a scheduling order of tasks of the first task type before a scheduling order of tasks of the second task type.
7. The task processing method according to any one of claims 1 to 6, characterized in that: The obtaining of the current performance index of the computer device where the front-end application is located includes: The current performance indicator is determined according to at least one of a central processing unit occupancy rate, a memory usage rate, and a capacity ratio between a background thread occupancy capacity and a total system capacity of the computer device.
8. A task processing device for a background thread, characterized in that: The task processing device comprises: A first acquisition module is used to acquire a configuration file corresponding to the front-end application when detecting that the front-end application is started; A thread creation module, configured to create a background thread corresponding to the front-end application when the configuration file indicates that a preset task type corresponding to a task included in the front-end application meets a background thread creation condition; A second acquisition module is used to acquire the current performance index of the computer device where the front-end application is located; The thread control module is used to control the background thread to process the task of the front-end application according to the current performance indicator.
9. A computer device, characterized in that: The computer device includes a memory and a processor; The memory is used to store computer programs; The processor is used to execute the computer program and implement the background thread task processing method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the background thread task processing method according to any one of claims 1 to 7 are implemented.