Thread dynamic management method, electronic device and computer readable storage medium
By updating the thread pool based on the resource amount and thread usage rate of the task execution system, the problem of non-dynamic thread management in the existing technology is solved, and the stability of thread management and the reliability of task execution are improved.
Patent Information
- Application Number
- CN202510195777.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2045-02-21
AI Technical Summary
Existing thread management methods cannot dynamically manage threads according to task needs, which may lead to insufficient or too many threads when the task is executed, resulting in high management difficulty and low reliability.
By obtaining the target task to be executed, the thread usage rate of the busy thread is determined based on the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool, and the initial thread pool is updated according to this rate to obtain the target thread pool, and then execute the task.
Dynamic management of threads is realized, the stability of thread management and the reliability of task execution are improved, and the rationality of the number of threads is ensured to meet task requirements.
Smart Images

Figure CN119668818B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of thread management, and in particular to a thread dynamic management method, an electronic device and a computer-readable storage medium. Background Art
[0002] With the rapid development of the intelligent Internet of Things, more and more businesses are beginning to use systems for intelligent processing. A thread is the smallest unit that the system can use for computing and scheduling, and is the smallest unit of program execution flow. Currently, in order to meet the growth in the number of businesses, the system is gradually adopting multi-threaded parallelism to improve business processing speed. The more threads there are, the more difficult it is to manage.
[0003] The current thread management method usually creates and destroys threads based on the comparison result between the number of idle threads and the preset thread threshold. However, this method cannot dynamically manage threads according to task needs, which may result in insufficient or too many threads when tasks need to be executed. Therefore, a method for dynamically managing threads is needed. Summary of the invention
[0004] The main technical problem solved by the present application is to provide a thread dynamic management method, an electronic device and a computer-readable storage medium, which can dynamically manage threads.
[0005] In order to solve the above technical problems, the present application provides a thread dynamic management method.
[0006] In one embodiment, a thread dynamic management method is applied to a task execution system, wherein the task execution system includes an initial thread pool, and the method includes: obtaining a target task to be executed; determining a thread usage rate of the busy thread based on a current amount of running resources of the task execution system and a current amount of running resources of a busy thread in the initial thread pool; updating the initial thread pool based on the thread usage rate to obtain a target thread pool; and executing the target task to be executed based on a target thread in the target thread pool.
[0007] In one embodiment, the step of determining the current usage rate of the busy thread based on the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool includes: calculating the ratio between the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool; and using the ratio as the thread usage rate.
[0008] In one embodiment, before the step of determining the current usage rate of the busy thread based on the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool, the method also includes: determining the total resource usage of the threads in the task execution system based on the number of busy threads and the current thread resource ratio in the task execution system; determining the task resource usage of the task execution system based on the resource usage of each currently executed task of the task execution system and a preset resource consumption index; and determining the difference between the total resource usage of the threads in the task execution system and the task resource usage as the current running resource amount of the busy thread in the initial thread pool.
[0009] In one embodiment, the step of updating the initial thread pool according to the thread usage rate to obtain the target thread pool includes: in response to the thread usage rate being greater than or equal to a preset usage threshold, performing thread addition processing on the initial thread pool to obtain the target thread pool; in response to the thread usage rate being less than the preset usage threshold, performing thread deletion processing on the initial thread pool to obtain the target thread pool.
[0010] In one embodiment, the step of performing thread addition processing on the initial thread pool to obtain the target thread pool includes: determining idle threads based on the total number of threads in the initial thread pool and the number of busy threads; determining the number of newly added threads based on the idle threads and a first preset multiple; and adding threads of the newly added number to the initial thread pool to obtain the target thread pool.
[0011] In one embodiment, the step of performing thread deletion processing on the initial thread pool to obtain the target thread pool includes: determining idle threads based on the total number of threads in the initial thread pool and the number of busy threads; determining the number of deletion threads based on the idle threads and a second preset multiple; and performing deletion processing on threads with a preset number of deletion threads in the initial thread pool to obtain the target thread pool.
[0012] In one embodiment, before the step of executing the target task to be executed according to the target thread in the target thread pool, the method further includes: sorting the threads in the target thread pool to obtain sorted threads; and determining the thread located before a preset sorting position in the sorted threads as the target thread.
[0013] In one embodiment, the step of obtaining the target task to be executed includes: in response to receiving an algorithm detection result, determining a corresponding execution task from a preset execution task mapping table according to the algorithm detection result, wherein the preset execution task mapping table stores a correspondence between preset algorithm detection results and preset execution tasks; and determining the corresponding execution task as the target task to be executed.
[0014] In order to solve the above technical problems, the present application provides an electronic device, including a memory and a processor, wherein the memory stores program instructions, and the processor retrieves the program instructions from the memory to execute the above thread dynamic management method.
[0015] In order to solve the above technical problems, the present application provides a computer-readable storage medium, including: storing program data, and the program data is used to implement the above thread dynamic management method when executed by a processor.
[0016] The above scheme obtains the target task to be executed, determines the thread usage rate of the busy thread according to the current running resource volume of the task execution system and the current running resource volume of the busy thread in the initial thread pool, updates the initial thread pool according to the thread usage rate, obtains the target thread pool, and executes the target task to be executed according to the target thread in the target thread pool. Thus, after obtaining the target task to be executed, the thread in the initial thread pool is updated according to the thread usage rate of the busy thread, thereby realizing dynamic management of the thread, which is conducive to improving the stability of thread management, and further improving the reliability of the thread executing the target task to be executed. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments are briefly introduced below. Obviously, the drawings described below are only 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 work, among which:
[0018] Figure 1 It is a flowchart of an exemplary embodiment of a thread dynamic management method shown in the present application;
[0019] Figure 2 It is a schematic diagram of the application process of an exemplary embodiment of the thread dynamic management method shown in the present application;
[0020] Figure 3 is a schematic diagram of the application process of another exemplary embodiment of the thread dynamic management method shown in the present application;
[0021] Figure 4is a block diagram of a thread dynamic management device shown in an exemplary embodiment of the present application;
[0022] Figure 5 It is a structural schematic diagram of an embodiment of an electronic device provided by the present application;
[0023] Figure 6 It is a structural schematic diagram of an embodiment of a computer-readable storage medium provided by the present application. DETAILED DESCRIPTION
[0024] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It will be appreciated that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for ease of description, only some but not all structures related to the present application are shown in the drawings. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the art without making creative work are within the scope of protection of the present application.
[0025] First of all, it should be noted that with the rapid development of the intelligent Internet of Things, more and more businesses are beginning to use systems for intelligent processing. A thread is the smallest unit that the system can use for computing scheduling and the smallest unit of program execution flow. Currently, in order to meet the growth in the number of businesses, the system is gradually adopting multi-threaded parallelism to improve business processing speed. The more threads there are, the more difficult it is to manage.
[0026] The current thread management method usually creates and destroys threads based on the comparison result between the number of idle threads and the preset thread threshold. However, this method cannot dynamically manage threads according to task needs, which may result in insufficient or too many threads when tasks need to be executed. Therefore, a method for dynamically managing threads is needed.
[0027] Based on this, the present application provides a thread dynamic management method, an electronic device and a computer-readable storage medium. Figure 1 , Figure 1 It is a flowchart of an exemplary embodiment of a thread dynamic management method shown in the present application.
[0028] The execution subject of the thread dynamic management method may be a terminal device or a server or other processing device, wherein the terminal device may be a computer, a mobile device, a terminal, a computing device, a vehicle-mounted device, etc. The execution subject of the thread dynamic management method may also be a thread dynamic management device. In some possible implementations, the thread dynamic management method may be implemented by a processor calling a computer-readable instruction stored in a memory.
[0029] Specifically, a thread dynamic management method provided in this embodiment is applied to a task execution system, the task execution system includes an initial thread pool, and the thread dynamic management method includes the following steps:
[0030] Step S110: Obtain the target task to be executed.
[0031] The target pending tasks refer to tasks that need to be executed. The target pending tasks may be early warning tasks, status display tasks of preset objects, attribute display tasks of preset objects, etc.
[0032] The thread dynamic management device obtains the target task to be executed. Specifically, the thread dynamic management device obtains an input task request and determines the input task request as the target task to be executed.
[0033] Step S120: determining the thread usage rate of the busy thread according to the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool.
[0034] The task execution system refers to the system used to execute tasks. The current running resource amount of the task execution system refers to the current actual running amount of all resources in the task execution system. The current running resource amount of the busy thread refers to the running resource amount used by the busy thread in the task execution system to execute tasks.
[0035] The initial thread pool may include busy threads and idle threads. Busy threads are threads that are executing tasks, and idle threads are threads that are not executing tasks.
[0036] The thread dynamic management device determines the thread usage rate of the busy thread according to the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool. Specifically, the thread dynamic management device determines the difference between the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool as the thread usage rate of the busy thread.
[0037] Step S130: updating the initial thread pool according to the thread usage rate to obtain a target thread pool.
[0038] The target thread pool refers to the thread pool after adding or deleting threads in the initial thread pool.
[0039] The thread dynamic management device updates the initial thread pool according to the thread usage rate to obtain the target thread pool. Specifically, in response to the thread usage rate being greater than or equal to the first preset usage rate threshold, the thread dynamic management device adds a first preset number of threads to the initial thread pool to obtain the target thread pool; in response to the thread usage rate being less than or equal to the second preset usage rate threshold, the thread dynamic management device deletes a second preset number of idle threads from the initial thread pool to obtain the target thread pool; in response to the thread usage rate being greater than the second preset usage rate threshold and less than the first preset usage rate threshold, the initial thread pool is determined as the target thread pool, and the first preset usage rate threshold is greater than the second preset usage rate threshold.
[0040] Step S140: executing the target task to be executed according to the target thread in the target thread pool.
[0041] The target thread refers to a thread selected from the target thread pool. For example, in response to the presence of a newly added thread in the target thread pool, the thread dynamic management device determines the newly added thread in the target thread pool as the target thread.
[0042] The thread dynamic management device performs an execution operation on the target task to be executed according to the target thread in the target thread pool. Specifically, the thread dynamic management device uses the target thread in the target thread pool to execute the target task to be executed.
[0043] In one embodiment, the target thread pool includes an idle thread pool and a busy thread pool. The thread dynamic management device adds the target task to be executed to the idle thread pool for binding waiting. In response to the arrival of the execution order of the target task to be executed, the target task to be executed is added to the busy thread pool, and the target thread in the busy thread pool is used to execute the target task to be executed.
[0044] It can be seen that by obtaining the target task to be executed, the thread usage rate of the busy thread is determined according to the current running resource volume of the task execution system and the current running resource volume of the busy thread in the initial thread pool, and the initial thread pool is updated according to the thread usage rate to obtain the target thread pool, and the target task to be executed is executed according to the target thread in the target thread pool. Therefore, after obtaining the target task to be executed, the thread in the initial thread pool is updated according to the thread usage rate of the busy thread, thereby realizing dynamic management of the thread, which is conducive to improving the stability of thread management, and further improving the reliability of the thread executing the target task to be executed.
[0045] The steps for the thread dynamic management device to obtain the target task to be executed include: in response to receiving the algorithm detection result, determining the corresponding execution task from the preset execution task mapping table according to the algorithm detection result, the preset execution task mapping table storing the correspondence between the preset algorithm detection result and the preset execution task; determining the corresponding execution task as the target task to be executed.
[0046] The algorithm detection result may be a detection result of the YOLO (you only look once) algorithm. The task execution system in the thread dynamic management device is in communication connection with the target detection device. The thread dynamic management device receives the algorithm detection result obtained by the target detection device through detecting the objects in the preset area by using the preset algorithm, determines the corresponding execution task from the preset execution task mapping table according to the algorithm detection result, and determines the corresponding execution task as the target task to be executed. Among them, the target detection device can obtain a collected video by shooting the road with a camera, use the YOLO algorithm to detect the organisms, motor vehicles and non-motor vehicles in the collected video, obtain the algorithm detection result, and send the algorithm detection result to the thread dynamic management device.
[0047] Before the thread dynamic management device determines the current usage rate of the busy thread according to the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool, the thread dynamic management method also includes: determining the total resource usage of the threads in the task execution system according to the number of busy threads and the current thread resource ratio in the task execution system; determining the task resource usage of the task execution system according to the resource usage of each currently executed task of the task execution system and a preset resource consumption index; and determining the difference between the total resource usage of the threads in the task execution system and the task resource usage as the current running resource amount of the busy thread in the initial thread pool.
[0048] For example, the number of busy threads, the current thread resource ratio in the task execution system, and the total resource usage of threads in the task execution system satisfy the following formula:
[0049]
[0050] In the above formula, Represents the current running resources of busy threads in the initial thread pool, Represents the number of busy threads of the nth process in the task execution system, where the total number of processes in the task execution system is N , Represents the thread resource ratio at time t, that is, the current thread resource ratio.
[0051] The thread dynamic management device determines the ratio between the current total running resource amount in the task execution system and the number of threads of the current busy green thread as the current thread resource ratio. For example, the current thread resource ratio satisfies the following formula:
[0052] a = S / D
[0053] In the above formula, aIndicates the current thread resource ratio. S Represents the current total operating resources. D Represents the current number of threads in the initial thread pool.
[0054] For example, the resource usage of each currently executed task of the task execution system, the preset resource consumption index, and the task resource usage of the task execution system satisfy the following formula:
[0055]
[0056] In the above formula, Characterizes the task resource usage of the task execution system, Characterization i The amount of resources used by the currently executing tasks, where the total number of currently executing tasks in the task execution system is m, Characterization i The preset resource consumption index of the currently executing task.
[0057] For example, the total resource usage of threads in the task execution system, the task resource usage, and the current running resource usage of busy threads in the initial thread pool satisfy the following formula:
[0058] -
[0059] In the above formula, E Represents the current running resources of busy threads in the initial thread pool.
[0060] In one embodiment, the number of busy threads, the current thread resource ratio in the task execution system, the resource usage of each currently executed task in the task execution system, the preset resource consumption index, and the current running resource usage of the busy threads in the initial thread pool satisfy the following formula:
[0061]
[0062] In the above formula, E Represents the current running resources of busy threads in the initial thread pool, Characterizes the number of busy threads of the nth process in the task execution system, where the total number of processes in the task execution system is N, Represents the current thread resource ratio at time t, Characterization i The amount of resources used by the currently executing tasks, where the total number of currently executing tasks in the task execution system is m, Characterization i The preset resource consumption index of the currently executing task.
[0063] The thread dynamic management device determines the current utilization rate of the busy thread according to the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool, including: calculating the ratio between the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool; and taking the ratio as the thread utilization rate.
[0064] For example, the current running resource amount of the task execution system, the current running resource amount of the busy threads in the initial thread pool, and the thread utilization rate satisfy the following formula:
[0065]
[0066] In the above formula, Characterizes thread usage, Characterizes the current amount of running resources of the task execution system, Represents the current running resources of busy threads in the initial thread pool.
[0067] In one embodiment, the currently executed task in the task execution system may be a serial task and / or a parallel task.
[0068] The running resource amount of a serial task satisfies the following formula:
[0069] }
[0070] In the above formula, S 1 represents the amount of running resources of the serial task, Characterizes the preset resource consumption index of the first subtask in the serial task, Characterizes the running resource matrix of the first subtask in the serial task, Characterizes the preset resource consumption index of the second subtask in the serial task, The running resource matrix representing the second subtask in the serial task, Characterizes the preset resource consumption index of the third subtask in the serial task, The running resource matrix representing the third subtask in the serial task, wherein the first subtask may be an alarm result processing task, the second subtask may be a target state output task, and the third subtask may be a target attribute output task.
[0071] In one embodiment, the amount of running resources of the parallel tasks satisfies the following formula:
[0072]
[0073] In the above formula, S 2 represents the amount of running resources for parallel tasks.
[0074] The thread dynamic management device updates the initial thread pool according to the thread usage rate to obtain the target thread pool, including: in response to the thread usage rate being greater than or equal to a preset usage threshold, performing thread addition processing on the initial thread pool to obtain the target thread pool; in response to the thread usage rate being less than the preset usage threshold, performing thread deletion processing on the initial thread pool to obtain the target thread pool.
[0075] The preset usage threshold may be 2 / 3 or 3 / 2.
[0076] The thread dynamic management device performs thread addition processing on the initial thread pool to obtain a target thread pool. Specifically, the thread dynamic management device determines idle threads according to the total number of threads in the initial thread pool and the number of busy threads; determines the number of newly added threads according to the idle threads and a first preset multiple; and adds threads of the newly added number to the initial thread pool to obtain a target thread pool.
[0077] The thread dynamic management device determines the difference between the total number of threads in the initial thread pool and the number of busy threads as idle threads, determines the first product term between the idle threads and the first preset multiple as the number of newly added threads, creates new threads with the number of newly added threads, and adds the created new threads to the initial thread pool to obtain a target thread pool.
[0078] In one embodiment, the first preset multiple may be 1 / 3, and the number of newly added threads satisfies the following formula:
[0079]
[0080] In the above formula, Indicates the number of newly added threads. Characterizes the total number of threads, The thread number that represents the busy threads.
[0081] The task execution system in the thread dynamic management device includes a main process, and the thread dynamic management device creates new threads with the number of newly added threads through the main process.
[0082] The thread dynamic management device performs thread deletion processing on the initial thread pool to obtain a target thread pool. Specifically, the idle threads are determined according to the total number of threads in the initial thread pool and the number of busy threads; the number of deleted threads is determined according to the idle threads and the second preset multiple; and the threads with the preset number of deleted threads in the initial thread pool are deleted to obtain the target thread pool.
[0083] The thread dynamic management device deletes the threads with a preset number of deletion threads in the initial thread pool to obtain a target thread pool. Specifically, the thread dynamic management device selects idle threads with the number of deletion threads from the initial thread pool to delete and obtain the target thread pool. As an example, the thread dynamic management device arranges the idle threads in the initial thread pool in order from long to short according to the creation time to obtain sorted idle threads, and selects the idle threads with the first number of deletion threads from the sorted idle threads to delete and obtain the target thread pool. For example, if the number of deletion threads is 8, the first 8 idle threads are selected from the sorted idle threads to delete and obtain the target thread pool.
[0084] In one embodiment, the thread dynamic management device determines the difference between the total number of threads in the initial thread pool and the number of busy threads as idle threads, determines the second product term between the idle threads and the second preset multiple as the number of deleted threads, and arbitrarily selects idle threads of the number of deleted threads from the initial thread pool for deletion to obtain a target thread pool.
[0085] In one embodiment, the second preset multiple may be 2 / 5, and the number of deleted threads satisfies the following formula:
[0086]
[0087] In the above formula, Indicates the number of threads to be deleted. Characterizes the total number of threads, The thread number that represents the busy threads.
[0088] Before the thread dynamic management device performs the step of executing the target task to be executed according to the target thread in the target thread pool, the thread dynamic management device method also includes: sorting the threads in the target thread pool to obtain sorted threads; and determining the thread located before the preset sorting position in the sorted threads as the target thread.
[0089] The thread dynamic management device sorts the threads in the target thread pool to obtain sorted threads. As an example, the thread dynamic management method sorts the threads according to the remaining available resources to obtain sorted threads. As another example, the thread dynamic management method sorts the idle threads in the target thread pool in order from short to long creation time to obtain sorted threads.
[0090] The thread dynamic management device determines the thread before the preset sorting position among the threads after sorting as the target thread. Specifically, the thread dynamic management device determines the corresponding target thread number from the preset thread number mapping table according to the target task to be executed, and the preset thread number mapping table includes the corresponding relationship between the preset task to be executed and the preset thread number; determines the target thread number as the preset sorting position, and determines the thread before the preset sorting position among the threads after sorting as the target thread.
[0091] In one embodiment, the application process of the thread dynamic management method is as follows: Figure 2 As shown, the thread dynamic management device receives the YOLO algorithm result sent by the target detection device, and then the main process applies for a memory block, stores the YOLO algorithm result in the memory block, obtains the target task to be executed according to the YOLO algorithm result, activates the management thread module through the task thread module, and the management thread module notifies the task thread module to add the target task to be executed to the task queue and enters the waiting ready state. Among them, the thread dynamic management device pre-creates an initial thread pool through the management thread module, and the initial thread pool includes an idle thread pool and a busy green thread pool. The thread dynamic management device matches the ID (Identity document, identification number) of the task queue with the PID (Proport Identifier, port identifier) in the idle thread pool through the management thread module, and determines whether the match is successful. If so, the target task to be executed is added to the idle thread pool, and then it is determined whether the thread usage rate is greater than the first preset usage rate threshold. If not, it is directly determined whether the thread usage rate is greater than the first preset usage rate threshold. If the judgment result of the thread usage rate being greater than the first preset usage rate threshold is yes, then the monitoring thread module is added The number of threads, the target to-be-executed tasks in the idle thread pool are added to the busy green thread pool through the monitoring thread module. If the judgment result is no, continue to judge whether the thread usage rate is less than the second preset usage rate threshold. If the judgment result of whether the thread usage rate is less than the second preset usage rate threshold is yes, then delete it through the monitoring thread module. The thread monitoring module then adds the target task to be executed in the idle thread pool to the busy green thread pool. If the judgment result is otherwise, the target task to be executed in the idle thread pool is directly added to the busy green thread pool through the monitoring thread module. The thread dynamic management device executes the target task to be executed through the target thread in the busy green thread pool, and reports the result of the task execution to the preset application. In this way, 40% of system resources can be saved, greatly increasing the utilization rate of system resources.
[0092] In one embodiment, the application process of the thread dynamic management method is as follows: Figure 3As shown, the thread dynamic management device creates a task thread module, a management thread module and a monitoring thread module through the main process. The thread dynamic management device creates a task queue through the task thread module, obtains the YOLO serial result package and the YOLO parallel result package, obtains the target task to be executed according to the YOLO serial result package and the YOLO parallel result package, and adds the target task to be executed to the task queue. Among them, the thread dynamic management device can obtain the YOLO serial result and the YOLO parallel result through the YOLO algorithm result processing module, and obtains the YOLO serial result package and the YOLO parallel result package respectively according to the YOLO serial result and the YOLO parallel result. After the thread dynamic management device obtains the result package through the task thread module, it activates the management thread module, calls out the target task to be executed from the task queue through the management thread module, matches the task queue of the target task to be executed with the queue in the initial thread pool, and if the match is successful, adds the target task to be executed to the initial thread pool. The thread dynamic management device monitors the threads in the initial thread pool through the monitoring thread module, updates the initial thread pool according to the thread usage rate, obtains the target thread pool, and adds the target task to be executed to the target thread in the target thread pool, and executes the target task to be executed through the target thread in the target thread pool. Thus, the initial thread pool is updated according to the thread usage rate, and the management of the thread is refined, so that the number of threads can be better controlled and the utilization rate of system resources is increased.
[0093] Figure 4 FIG. 1 is a block diagram of a thread dynamic management device shown in an exemplary embodiment of the present application. Figure 4 As shown, the exemplary thread dynamic management device 400 includes: a task acquisition module 410, a thread usage determination module 420, an update processing module 430 and a task execution module 440. Specifically:
[0094] The task acquisition module 410 is used to acquire the target task to be executed.
[0095] The thread usage rate determination module 420 is used to determine the thread usage rate of the busy thread according to the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool.
[0096] The update processing module 430 is used to update the initial thread pool according to the thread usage rate to obtain a target thread pool.
[0097] The task execution module 440 is used to execute the target task to be executed according to the target thread in the target thread pool.
[0098] In this exemplary thread dynamic management device, by obtaining the target task to be executed, the thread usage rate of the busy thread is determined according to the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool, the initial thread pool is updated according to the thread usage rate to obtain the target thread pool, and the target task to be executed is executed according to the target thread in the target thread pool. Thus, after obtaining the target task to be executed, the thread in the initial thread pool is updated according to the thread usage rate of the busy thread, thereby realizing dynamic management of the thread, which is conducive to improving the stability of thread management, and further improving the reliability of the thread executing the target task to be executed.
[0099] The functions of each module can be found in the embodiment of the thread dynamic management method, which will not be repeated here.
[0100] In order to implement the thread dynamic management method of the above embodiment, the present application proposes another electronic device, which can be specifically referred to as Figure 5 , Figure 5 It is a structural schematic diagram of an embodiment of an electronic device provided by the present application.
[0101] The electronic device 500 includes a memory 501 and a processor 502 , wherein the memory 501 and the processor 502 are coupled.
[0102] The memory 501 is used to store program data, and the processor 502 is used to execute the program data to implement the thread dynamic management method of the above embodiment.
[0103] In this embodiment, the processor 502 may also be referred to as a CPU (Central Processing Unit). The processor 502 may be an integrated circuit chip having signal processing capabilities. The processor 502 may also be a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component. A general-purpose processor may be a microprocessor or the processor 502 may also be any conventional processor, etc.
[0104] The present application also provides a computer-readable storage medium, such as Figure 6 As shown, the computer-readable storage medium 600 is used to store program data 601. When the program data 601 is executed by the processor, it is used to implement the thread dynamic management method in the method embodiment of the present application.
[0105] The method involved in the embodiment of the thread dynamic management method of the present application, when implemented in the form of a software functional unit and sold or used as an independent product, can be stored in a device, such as a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0106] The above description is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly used in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A thread dynamic management method, characterized in that: Applied to a task execution system, the task execution system includes an initial thread pool, and the method includes: Get the target tasks to be executed; Determine the thread usage rate of the busy thread according to the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool; The initial thread pool is updated according to the thread usage rate to obtain a target thread pool; Performing an execution operation on the target task to be executed according to the target thread in the target thread pool; The step of determining the thread usage rate of the busy thread according to the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool comprises: determining the difference between the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool as the thread usage rate of the busy thread; The step of updating the initial thread pool according to the thread usage rate to obtain the target thread pool includes: in response to the thread usage rate being greater than or equal to a preset usage threshold, performing thread addition processing on the initial thread pool to obtain the target thread pool; in response to the thread usage rate being less than the preset usage threshold, performing thread deletion processing on the initial thread pool to obtain the target thread pool; The step of performing thread addition processing on the initial thread pool to obtain the target thread pool includes: determining idle threads based on the total number of threads in the initial thread pool and the number of busy threads; determining the number of newly added threads based on the idle threads and a first preset multiple; and adding threads of the number of newly added threads to the initial thread pool to obtain the target thread pool.
2. The thread dynamic management method according to claim 1, characterized in that: Before the step of determining the current usage rate of the busy thread according to the current running resource amount of the task execution system and the current running resource amount of the busy thread in the initial thread pool, the method further includes: Determine the total resource usage of threads in the task execution system according to the number of busy threads and the current thread resource ratio in the task execution system; Determining the task resource usage of the task execution system according to the resource usage of each currently executed task of the task execution system and a preset resource consumption index; The difference between the total resource usage of threads in the task execution system and the task resource usage is determined as the current running resource amount of the busy threads in the initial thread pool.
3. The thread dynamic management method according to claim 1, characterized in that: The step of performing thread deletion processing on the initial thread pool to obtain the target thread pool includes: Determine an idle thread according to the total number of threads in the initial thread pool and the number of busy threads; Determine the number of threads to be deleted according to the idle threads and the second preset multiple; Delete the threads in the initial thread pool in the number of deleted threads to obtain the target thread pool.
4. The thread dynamic management method according to claim 1, characterized in that: Before the step of executing the target task to be executed according to the target thread in the target thread pool, the method further includes: Sorting the threads in the target thread pool to obtain sorted threads; The thread located before the preset sorting position among the sorted threads is determined as the target thread.
5. The thread dynamic management method according to claim 1, characterized in that: The step of obtaining the target task to be performed includes: In response to receiving the algorithm detection result, determining a corresponding execution task from a preset execution task mapping table according to the algorithm detection result, wherein the preset execution task mapping table stores a correspondence between preset algorithm detection results and preset execution tasks; The corresponding execution task is determined as the target task to be executed.
6. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores program instructions, and the processor retrieves the program instructions from the memory to execute the method according to any one of claims 1 to 5.
7. A computer-readable storage medium, characterized in that: include: Program data is stored, and when the program data is executed by a processor, it is used to implement the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Thread scheduling method, device and equipment and storage medium
CN111367675A