Thread pool deadlock detection method and device, computer equipment and storage medium
By constructing a dependency graph of thread pool task result objects, the problem of incomplete thread deadlock detection is solved, enabling real-time deadlock detection of the thread pool and improving the accuracy and reliability of detection.
Patent Information
- Application Number
- CN202511086345.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-04
- Publication Date
- 2025-11-21
AI Technical Summary
In existing technologies, thread deadlock detection is not comprehensive enough, cannot identify deadlocks involving shared limited resources, and cannot detect and prevent deadlocks in real time, resulting in limited detection accuracy and reliability.
By capturing and parsing the dependency chains and thread resource information of task result objects in the thread pool, a dependency graph is constructed to detect circular dependencies and resource usage in the thread pool, thereby achieving real-time deadlock detection.
It achieves comprehensive detection of thread pool deadlocks, and can identify circular dependencies and resource consumption exceeding thresholds in real time, thus improving the accuracy and reliability of deadlock detection.
Smart Images

Figure CN120994415A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of deadlock detection technology, specifically to thread pool deadlock detection methods, devices, computer equipment, and storage media. Background Technology
[0002] Deadlock occurs when two or more threads hold resources that each other needs, and are all waiting for the other to finish executing before they can continue, resulting in a deadlock situation where all threads are stuck in a waiting state. Current deadlock detection technologies typically rely on the `synchronized` keyword or explicit locks, which cannot identify deadlocks involving shared, limited resources, leading to incomplete detection. Furthermore, current deadlock detection methods are mostly post-hoc, using thread dumps to determine if a deadlock has occurred, which lacks the ability to detect and prevent deadlocks in real time. Summary of the Invention
[0003] In view of this, the present invention provides a thread pool deadlock detection method, apparatus, computer device and storage medium to solve the problems of incomplete and non-real-time deadlock detection in current methods.
[0004] In a first aspect, the present invention provides a thread pool deadlock detection method, applied in a target operating system, the target operating system including multiple thread pools, each thread pool including threads associated with task result objects; the method includes:
[0005] Based on the capture and parsing of task result objects associated in multiple thread pools, the dependency links of each task result object in multiple thread pools and the thread resource information corresponding to the dependency links are determined. The dependency links are used to characterize the node connection paths between the task result object and the corresponding upstream node object and / or downstream node object.
[0006] Based on the dependency links of each task result object and the thread resource information corresponding to the dependency links, a dependency graph is constructed. The dependency graph is used to represent the node connection between each task result object in multiple thread pools, as well as the resource usage of the thread pool by the task result objects.
[0007] Based on the dependency graph, the node connection status of task result objects in multiple thread pools and the resource usage of multiple thread pools are detected to determine deadlock risk information.
[0008] The thread pool deadlock detection method provided in this invention captures and parses task result objects associated with multiple thread pools to determine the dependency chains of each task result object in multiple thread pools and the thread resource information corresponding to the dependency chains. This enables dynamic parsing of task result objects associated with thread pools, achieving real-time deadlock detection of thread pools. Simultaneously, a dependency graph is constructed based on the dependency chains of each task result object and the corresponding thread resource information. This dependency graph represents the node connections between task result objects in multiple thread pools, as well as the resource usage of thread pools by task result objects. This allows for simultaneous detection of circular dependencies within thread pools and whether thread pool resource usage exceeds thresholds, thus achieving comprehensive deadlock detection of thread pools.
[0009] In one optional implementation, the dependency chain of each task result object in multiple thread pools is determined based on the capture and parsing of task result objects associated in multiple thread pools, including:
[0010] For the first task result object contained in the first code segment in the target operating system, create corresponding proxy objects and replace the corresponding first task result objects with proxy objects, so as to rewrite the operation methods of the corresponding first task result objects based on the proxy objects;
[0011] Based on the operation methods of the rewritten first task result object, obtain the downstream node object corresponding to the first task result object;
[0012] Based on the downstream node object corresponding to the first task result object, construct the dependency chain of the first task result object.
[0013] The thread pool deadlock detection method provided in this embodiment of the invention enhances the first task result object in the first code segment with modification permission using a proxy object. Based on the rewriting of the operation methods of the corresponding first task result object by the proxy object, the downstream node object corresponding to the first task result object is obtained, thereby enabling the automatic acquisition of the downstream node object corresponding to the first task result object during task execution. Based on the downstream node object corresponding to the first task result object, the dependency chain of the first task result object is constructed, thereby realizing the real-time and automatic construction of the dependency chain of the task result object.
[0014] In one optional implementation, the dependency chain of each task result object in multiple thread pools is determined based on the capture and parsing of task result objects associated in multiple thread pools, including:
[0015] Identify and parse the second task result object contained in the second code segment of the target operating system to obtain the dependency storage field in the second task result object;
[0016] Parse the dependency relationship storage field to obtain the upstream node object and downstream node object corresponding to the second task result object;
[0017] Based on the upstream and downstream node objects corresponding to the second task result object, construct the dependency chain of the second task result object.
[0018] The thread pool deadlock detection method provided in this embodiment of the invention identifies and parses the second task result object in the second code segment that does not have modification permission, obtains the dependency relationship storage field in the second task result object, and parses the dependency relationship storage field to obtain the upstream node object and downstream node object corresponding to the second task result object, thereby achieving a comprehensive parsing of the task result object and ensuring the integrity and reliability of the constructed dependency chain.
[0019] In one optional implementation, the dependency chain of each task result object in multiple thread pools is determined based on the capture and parsing of task result objects associated in multiple thread pools, including:
[0020] If cross-thread pool task blocking is detected, the target method of the task result object class is intercepted and parsed to obtain the third task result object.
[0021] The fourth task result object is obtained by searching the task result object that called the target method;
[0022] The fourth task result object is used as the downstream node object corresponding to the third task result object to build the dependency chain of the third task result object.
[0023] The thread pool deadlock detection method provided in this embodiment of the invention intercepts and parses the target method of the task result object class when cross-thread pool task blocking occurs, obtains the third task result object, determines the target method that calls the third task result object, and finds the task result object of the target method to obtain the fourth task result object, thereby capturing the task result objects involved in implicit dependencies and determining the dependency chain.
[0024] In one optional implementation, the thread resource information includes thread pool information corresponding to the node connection path in the dependency link and the amount of resources occupied.
[0025] Based on the dependency chains of each task result object and the thread resource information corresponding to the dependency chains, a dependency graph is constructed, including:
[0026] The thread pool information and resource quantity information corresponding to the node connection path are used as the attribute information of the node connection path;
[0027] Connect the nodes along the path according to the corresponding task result objects to obtain the dependency graph.
[0028] The thread pool deadlock detection method provided in this embodiment of the invention uses the thread pool information and resource quantity information corresponding to the node connection path as the attribute information of the node connection path, and connects the node connection paths according to the corresponding task result objects to obtain a dependency graph. This allows the dependency graph to reflect the thread pool corresponding to each node connection path and the number of thread resources it occupies. When performing deadlock detection based on the dependency graph, the resource usage of the thread pool can be detected based on the attribute information of the node connection paths, thus achieving comprehensive detection of thread pool deadlock.
[0029] In one optional implementation, based on a dependency graph, the node connections of task result objects in multiple thread pools and the resource usage of multiple thread pools are detected to determine deadlock risk information, including:
[0030] Detect node connections in the dependency graph to determine the node connection subgraph in the dependency graph;
[0031] If a closed-loop node connection subgraph exists in the dependency graph, then the deadlock risk information is determined to be present.
[0032] The thread pool deadlock detection method provided in this embodiment of the invention detects node connections in the dependency graph, determines the node connection subgraph in the dependency graph, and determines the deadlock risk information when there is a closed loop node connection subgraph in the dependency graph, thereby detecting deadlock caused by circular dependencies in the thread pool.
[0033] In one optional implementation, based on a dependency graph, the node connections of task result objects in multiple thread pools and the resource usage of multiple thread pools are detected to determine deadlock risk information, including:
[0034] Obtain the maximum number of threads for each thread pool, and determine the resource consumption threshold for each thread pool based on the maximum number of threads.
[0035] Based on the dependency graph, the resource quantity information of the corresponding node connection paths is added together according to the thread pool information of the node connection paths corresponding to each task result object to obtain the resource consumption of each task result object. The attribute information of the node connection path includes the thread pool information and the resource consumption information of the node connection path.
[0036] If the number of associated task result objects in a thread pool exceeds the corresponding resource usage threshold, then the deadlock risk information of the first thread pool is determined to be deadlock risk, and a first warning message associated with the resource usage threshold is issued.
[0037] The thread pool deadlock detection method provided in this embodiment of the invention weights the attribute information of the node connection path corresponding to each task result object based on the dependency relationship graph to obtain the resource usage of each task result object. When there is a first thread pool in the thread pool where the resource usage of associated task result objects exceeds the corresponding resource usage threshold, the deadlock risk information of the first thread pool is determined to be deadlock risk, thereby detecting deadlock caused by the thread pool's resource usage exceeding the threshold.
[0038] In one optional implementation, based on a dependency graph, the node connections of task result objects in multiple thread pools and the resource usage of multiple thread pools are detected to determine deadlock risk information, and the method further includes:
[0039] Based on the resource consumption of each task result object and the maximum number of threads in the corresponding thread pool, determine the asynchronous execution threshold for each thread pool.
[0040] Get the number of concurrent tasks for each thread pool;
[0041] If there is a second thread pool in the thread pool whose number of concurrent tasks exceeds the corresponding asynchronous execution threshold, then the deadlock risk information of the second thread pool is determined to be deadlock risk, and a second warning information associated with the asynchronous execution threshold is issued.
[0042] The thread pool deadlock detection method provided in this embodiment of the invention determines the asynchronous execution threshold for each thread pool based on the resource usage of each task result object and the maximum number of threads in the corresponding thread pool. When there is a second thread pool in the thread pool whose number of concurrent tasks exceeds the corresponding asynchronous execution threshold, the deadlock risk information of the second thread pool is determined to be deadlock risk, thereby detecting deadlock caused by the thread pool's resource usage exceeding the threshold.
[0043] Secondly, the present invention provides a thread pool deadlock detection device, applied in a target operating system, the target operating system including multiple thread pools, each thread pool including threads associated with task result objects; the device includes:
[0044] The task result object parsing module is used to determine the dependency links of each task result object in multiple thread pools and the corresponding thread resource information based on the capture and parsing of task result objects associated in multiple thread pools. The dependency links are used to characterize the node connection paths between the task result object and the corresponding upstream node object and / or downstream node object.
[0045] The dependency graph construction module is used to construct a dependency graph based on the dependency links of each task result object and the thread resource information corresponding to the dependency links. The dependency graph is used to represent the node connection between each task result object in multiple thread pools, as well as the resource usage of the thread pool by the task result objects.
[0046] The deadlock risk monitoring module is used to detect the node connection status of task result objects in multiple thread pools and the resource usage of multiple thread pools based on the dependency graph, and to determine deadlock risk information.
[0047] Thirdly, the present invention provides a computer device, including: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the thread pool deadlock detection method of the first aspect or any corresponding embodiment described above.
[0048] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to execute the thread pool deadlock detection method of the first aspect or any corresponding embodiment described above.
[0049] Fifthly, the present invention provides a computer program product, including computer instructions, which are used to cause a computer to execute the thread pool deadlock detection method described in the first aspect or any corresponding embodiment thereof. Attached Figure Description
[0050] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0051] Figure 1 This is a flowchart illustrating a thread pool deadlock detection method provided in an embodiment of the present invention;
[0052] Figure 2This is a flowchart illustrating a method for capturing and parsing task result objects in a thread pool deadlock detection method provided in an embodiment of the present invention.
[0053] Figure 3 This is a flowchart illustrating another process for capturing and parsing task result objects in a thread pool deadlock detection method provided in this embodiment of the invention.
[0054] Figure 4 This is a flowchart illustrating another process for capturing and parsing task result objects in a thread pool deadlock detection method provided in this embodiment of the invention.
[0055] Figure 5 This is a schematic diagram of another specific implementation of a thread pool deadlock detection method provided in this embodiment of the invention, which captures and parses task result objects.
[0056] Figure 6 This is a schematic diagram of the process of constructing a dependency graph in a thread pool deadlock detection method provided in an embodiment of the present invention;
[0057] Figure 7 This is a schematic diagram of the dependency graph in a thread pool deadlock detection method provided in an embodiment of the present invention;
[0058] Figure 8 This is a schematic diagram of the process of detecting circular dependencies based on a dependency graph in a thread pool deadlock detection method provided in an embodiment of the present invention;
[0059] Figure 9 This is a schematic diagram of a process for detecting resource exhaustion deadlock based on a dependency graph in a thread pool deadlock detection method provided in an embodiment of the present invention;
[0060] Figure 10 This is a schematic diagram of another process for detecting resource exhaustion deadlock based on dependency graph in a thread pool deadlock detection method provided in an embodiment of the present invention;
[0061] Figure 11 This is a structural block diagram of a thread pool deadlock detection device provided in an embodiment of the present invention;
[0062] Figure 12 This is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. Detailed Implementation
[0063] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0064] Deadlock occurs when two or more threads hold resources that each other needs, and are waiting for the other to finish executing before they can continue, resulting in all threads being stuck in a waiting state. Current deadlock detection technologies typically rely on the `synchronized` keyword or explicit locks, which cannot identify deadlocks involving shared, limited resources, handle dynamic dependencies between asynchronous tasks, or identify resource exhaustion deadlocks caused by thread pool capacity limitations. This makes deadlock detection incomplete. Furthermore, current deadlock detection methods are mostly post-hoc, using thread dumps to determine if a deadlock has occurred. This approach cannot detect or prevent deadlocks in real time, and because thread dumps are snapshots at a specific moment, they may capture brief periods of blocking, such as lock contention, and misidentify them as deadlocks, resulting in limited accuracy and reliability of deadlock detection.
[0065] Based on this, the present invention provides a thread pool deadlock detection method, applied in a target operating system, the target operating system including multiple thread pools, each thread pool including threads associated with task result objects; the method includes: based on capturing and parsing the associated task result objects in multiple thread pools, determining the dependency links of each task result object in multiple thread pools and the thread resource information corresponding to the dependency links, wherein the dependency links are used to characterize the node connection paths between the task result objects and their corresponding upstream and / or downstream node objects; based on the dependency links of each task result object and the thread resource information corresponding to the dependency links, constructing a dependency graph, wherein the dependency graph is used to characterize the node connection status between each task result object in multiple thread pools, and the resource usage of the thread pools by the task result objects; based on the dependency graph, detecting the node connection status of the task result objects in multiple thread pools and the resource usage of the multiple thread pools to determine deadlock risk information. This invention captures and parses task result objects associated with multiple thread pools to determine the dependency chains of each task result object in the multiple thread pools and the corresponding thread resource information. This enables dynamic parsing of task result objects associated with thread pools, achieving real-time deadlock detection of thread pools. Simultaneously, a dependency graph is constructed based on the dependency chains of each task result object and the corresponding thread resource information. This dependency graph represents the node connections between task result objects in multiple thread pools, as well as the resource usage of thread pools by task result objects. It can simultaneously detect whether there are circular dependencies in the thread pools and whether the resource usage of the thread pools exceeds the threshold, thereby achieving comprehensive deadlock detection of thread pools.
[0066] The thread pool deadlock detection method provided in this invention can be applied to a target operating system, wherein the target operating system includes multiple thread pools, and each thread pool includes threads associated with task result objects. It should be noted that the target operating system can be any operating system capable of supporting multiple processes simultaneously, such as a multi-user time-sharing operating system, a real-time operating system, and a distributed system, etc.
[0067] The thread pool deadlock detection method provided in this embodiment of the invention can also be applied to various servers, cloud computing platforms and control systems, without any specific limitations.
[0068] According to an embodiment of the present invention, a method for detecting deadlock in a thread pool is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0069] This embodiment provides a thread pool deadlock detection method, which can be used in the target operating system described above. The target operating system includes multiple thread pools, and each thread pool includes threads associated with task result objects. Figure 1 This is a flowchart illustrating a thread pool deadlock detection method provided in an embodiment of the present invention, as shown below. Figure 1 As shown, the process includes the following steps:
[0070] Step S101: Based on the capture and parsing of task result objects associated in multiple thread pools, determine the dependency chain of each task result object in multiple thread pools and the thread resource information corresponding to the dependency chain.
[0071] In this embodiment of the invention, the dependency chain is used to characterize the node connection path between a task result object (CompletableFuture) and its corresponding upstream and / or downstream node objects; wherein, the upstream node object corresponding to the task result object refers to the task result object of the parent task corresponding to the task result object, and the downstream node object corresponding to the task result object refers to the task result object of the child task corresponding to the task result object. The thread resource information corresponding to the dependency chain is used to characterize the thread pool occupied when executing the task according to the dependency chain and the resource usage of the thread pool.
[0072] In this embodiment of the invention, task result objects associated with multiple thread pools are captured, task result objects associated with multiple thread pools are determined, the captured task result objects are parsed, and the upstream node objects and / or downstream node objects corresponding to the task result objects are obtained. Based on the upstream node objects and / or downstream node objects corresponding to the task result objects, a dependency link is constructed, and the thread resource occupancy of the thread pool by the task result objects is parsed to obtain the thread resource information corresponding to the dependency link.
[0073] Step S102: Construct a dependency graph based on the dependency links of each task result object and the thread resource information corresponding to the dependency links.
[0074] In this embodiment of the invention, the dependency graph is used to characterize the node connections between various task result objects in multiple thread pools, as well as the resource usage of the thread pool by the task result objects. The node connections between various task result objects can be constructed through the dependency links of each task result object, and the resource usage of the thread pool by the task result objects can be constructed through the thread resource information corresponding to the dependency links.
[0075] Step S103: Based on the dependency graph, detect the node connection status of task result objects in multiple thread pools and the resource usage of multiple thread pools to determine deadlock risk information.
[0076] In this embodiment of the invention, since the dependency graph can simultaneously reflect the node connections between task result objects in multiple thread pools and the resource usage of the task result objects in the thread pools, detection based on the dependency graph can simultaneously detect circular dependencies and resource consumption in the current thread pools. Specifically, based on the dependency graph, the node connections of task result objects in multiple thread pools are detected to determine whether circular dependencies exist, and if circular dependencies exist, a deadlock risk is identified; based on the dependency graph, the resource usage of multiple thread pools is detected to determine whether the resource consumption of the thread pools exceeds a threshold, thereby determining whether a resource exhaustion deadlock exists, and if the resource consumption of the thread pools exceeds the threshold, a deadlock risk is identified.
[0077] The thread pool deadlock detection method provided in this invention captures and parses task result objects associated with multiple thread pools to determine the dependency chains of each task result object in multiple thread pools and the thread resource information corresponding to the dependency chains. This enables dynamic parsing of task result objects associated with thread pools, achieving real-time deadlock detection of thread pools. Simultaneously, a dependency graph is constructed based on the dependency chains of each task result object and the corresponding thread resource information. This dependency graph represents the node connections between task result objects in multiple thread pools, as well as the resource usage of thread pools by task result objects. This allows for simultaneous detection of circular dependencies within thread pools and whether thread pool resource usage exceeds thresholds, thus achieving comprehensive deadlock detection of thread pools.
[0078] In an optional implementation, the capture and parsing of task result objects in step S101 above is divided into explicit dependency capture and implicit dependency capture. Explicit dependency capture captures task result objects with direct and explicit dependencies. Task result objects with explicit dependencies are typically task result objects with parent-child node relationships, where the task result object corresponding to the parent node (upstream node) corresponds to the parent task, and the task result object corresponding to the child node (downstream node) corresponds to the child task. Explicit dependencies can be directly reflected in the code, so the capture and parsing of task result objects can be completed by parsing the code. Implicit dependency capture captures task result objects with dependencies formed indirectly, such as shared state, execution order, environment variables, etc. When a task result object calls the `get()` or `join()` method and blocks while waiting for a task result object in another thread pool, an implicit dependency exists between them. Therefore, interception and parsing can be performed during cross-thread pool blocking to complete the capture and parsing of task result objects. Furthermore, for explicit dependency capture, depending on whether the code segment can be modified, it can be further divided into two capture and parsing methods: proxy enhancement and data structure parsing. Therefore, step S101 above can specifically include the following three capture and parsing methods:
[0079] The first type, such as Figure 2 As shown, for explicit dependencies and code segments with modification permissions, the capture and parsing method can include the following steps:
[0080] Step S201: For the first task result object contained in the first code segment in the target operating system, create corresponding proxy objects respectively, and replace the corresponding first task result object with the proxy objects to rewrite the operation methods of the corresponding first task result object based on the proxy objects.
[0081] In this embodiment of the invention, the task result object involved in the first code segment in the target operating system is taken as the first task result object. Corresponding proxy objects (TrackableCompletableFuture) are created for each first task result object, and the proxy objects replace the corresponding first task result objects to enhance them. The chained operation methods related to the corresponding first task result object are rewritten through the proxy objects, such as rewriting the thenApplyAsync method, thereby automatically recording the parent-child node relationship when the task is submitted. The first code segment is a code segment in the target operating system that has modification permissions; therefore, dependency capture is achieved using proxy enhancement.
[0082] Step S202: Based on the operation method of the rewritten first task result object, obtain the downstream node object corresponding to the first task result object.
[0083] In this embodiment of the invention, by using the operation method of the rewritten first task result object, the parent-child node relationship recorded when the task is submitted is used to obtain the downstream node object corresponding to the first task result object; at the same time, a set of child nodes, namely the children set, is maintained for each first task result object, with the first task result object of its corresponding subtask as the parent node and the first task result objects of its subtasks as the child nodes, and these child nodes are maintained in the children set, thereby obtaining the downstream node object corresponding to the first task result object.
[0084] Step S203: Based on the downstream node object corresponding to the first task result object, construct the dependency link of the first task result object.
[0085] In this embodiment of the invention, based on the downstream node object corresponding to the first task result object, the node connection relationship between the first task result object and the downstream node object is determined, thereby constructing the dependency link corresponding to the first task result. It should be noted that a task result object can correspond to multiple downstream node objects at the same time, so the dependency link can contain multiple node connection relationships between task result objects and downstream node objects.
[0086] In addition, backtracking can be performed based on the children set corresponding to the first task result object to determine the upstream node object of the first task result object, thereby determining the node connection relationship between the first task result object and the upstream node object, and further constructing the dependency link corresponding to the first task result. It should be noted that if a task result object is the root node, then the task result object does not have a corresponding upstream node object, and the dependency link starts from the task result object.
[0087] Using the above method, for the first code segment with modification permissions, a proxy object is used to enhance the first task result object. Based on the overriding of the operation methods of the corresponding first task result object by the proxy object, the downstream node object corresponding to the first task result object is obtained. Thus, the downstream node object corresponding to the first task result object can be automatically obtained when the task is executed. Based on the downstream node object corresponding to the first task result object, the dependency chain of the first task result object is constructed, thereby realizing the real-time and automatic construction of the dependency chain of the task result object.
[0088] The second type, such as Figure 3 As shown, for explicit dependencies where the code segment does not have modification permissions, the capture and resolution method can include the following steps:
[0089] Step S301: Identify and parse the second task result object contained in the second code segment of the target operating system to obtain the dependency storage field in the second task result object.
[0090] In this embodiment of the invention, the task result object involved in the second code segment in the target operating system is used as the second task result object. The JVMTI (JVM Tool Interface) Heap iterator is used to traverse all instances of the second task result object in the second code segment, and the internal results of the second task result object are parsed to obtain the dependency relationship storage field, i.e., the stack field, in the second task result object. The dependency relationship storage field stores the dependencies of the second task result object. Parsing the dependency relationship storage field yields the dependencies of the second task result object. The second code segment is a code segment in the target operating system that does not have modification permissions; optionally, a code segment with modification permissions can also be used as the second code segment, and its dependencies can be captured using a capture and parsing method. The selection of the second code segment can be adjusted according to the relevant settings of the target operating system and the user's needs, and no specific restrictions are imposed here.
[0091] Step S302: Parse the dependency relationship storage field to obtain the upstream node object and downstream node object corresponding to the second task result object.
[0092] In this embodiment of the invention, the dependency relationship storage field is parsed to obtain the memory addresses of src (parent task pointer) and snd (child task pointer), thereby obtaining the upstream node object and downstream node object corresponding to the second task result object.
[0093] Step S304: Based on the upstream node object and downstream node object corresponding to the second task result object, construct the dependency link of the second task result object.
[0094] In this embodiment of the invention, based on the upstream node object corresponding to the second task result object, the node connection relationship between the second task result object and the upstream node object is determined, and based on the downstream node object corresponding to the second task result object, the node connection relationship between the second task result object and the downstream node object is determined, thereby constructing the dependency link of the second task result object.
[0095] Using the above method, for the second code segment that does not have modification permissions, the second task result object is identified and parsed to obtain the dependency relationship storage field in the second task result object. The upstream node object and downstream node object corresponding to the second task result object are then parsed to obtain the dependency relationship storage field. This achieves a comprehensive parsing of the task result object and ensures the integrity and reliability of the constructed dependency chain.
[0096] The third type, such as Figure 4 As shown, the method for capturing and resolving implicit dependencies can include the following steps:
[0097] Step S401: If cross-thread pool task blocking is detected, the target method of the task result object class is intercepted and parsed to obtain the third task result object.
[0098] In this embodiment of the invention, key methods are redefined during the class loading phase using a Java Agent, and probe code is inserted at the get() or join() call using ASM code editing. When cross-thread pool task blocking is detected, implicit dependencies can be automatically established.
[0099] In this embodiment of the invention, when cross-thread pool task blocking is detected, the target method of the task result object class is intercepted. By inserting probe code, the capture code is called to obtain the third task result object corresponding to the target method; the target method is either the get() or join() method.
[0100] Step S402: Search for the task result object that calls the target method to obtain the fourth task result object.
[0101] In this embodiment of the invention, the context of the current thread stack is checked to determine whether the current thread is in the execution context of another task result object. If so, it can be determined that the other task result object, namely the fourth task result object, has called the target method of the third task result object.
[0102] Step S403: Use the fourth task result object as the downstream node object corresponding to the third task result object to build the dependency link of the third task result object.
[0103] In this embodiment of the invention, the fourth task result object is used as the downstream node object corresponding to the third task result object, and the node connection relationship between the third task result object and the fourth task result object is determined, thereby constructing the dependency link of the third task result object.
[0104] In a specific embodiment, such as Figure 5As shown, the Java Agent bytecode enhancement tool is mounted into the user's Java program via the Attach mechanism. It uses the Method Visitor of the ASM framework for interception and redefines the `get` and `join` methods of the `CompletableFuture` class to insert probe code at the call points of `get()` or `join()`. When cross-thread pool task blocking is detected, the capture code is invoked to obtain the task result object A that called the `get()` or `join()` method. Then, the current thread stack is obtained, and its context is checked to determine if the current thread is in the context of another task result object. If so, the task result object B is obtained, and task result object A is set as the parent task of task result object B, meaning task result object B is the downstream node object of task result object A.
[0105] Using the above method, when a task blocking occurs across thread pools, the target method of the task result object class is intercepted and parsed to obtain the third task result object, the target method of the third task result object is determined, and the task result object of the target method is searched to obtain the fourth task result object. In this way, the task result objects involved in the implicit dependency are captured, and the dependency chain is determined.
[0106] In one optional implementation, the thread resource information includes thread pool information corresponding to the node connection path in the dependency chain and the amount of resources occupied; correspondingly, Figure 6 This is a schematic diagram illustrating the process of constructing a dependency graph in a thread pool deadlock detection method provided in an embodiment of the present invention, as shown below. Figure 6 As shown, step S102 above may include the following steps:
[0107] Step S601: Use the thread pool information and resource quantity information corresponding to the node connection path as the attribute information of the node connection path.
[0108] In this embodiment of the invention, for each node connection path in each dependent link, its corresponding thread pool information and resource quantity information are used as its corresponding attribute information to characterize the thread resources occupied by the node connection path.
[0109] Step S602: Connect the nodes along the path according to the corresponding task result objects to obtain the dependency graph.
[0110] In this embodiment of the invention, the task result object is used as a connection node, and the connection paths of each node are connected to the corresponding task result object to obtain a dependency graph.
[0111] For example, Figure 7This is a schematic diagram of the dependency graph in a thread pool deadlock detection method provided in an embodiment of the present invention, such as... Figure 7 As shown, the dependency graph contains seven task result objects, CF1-CF2, and involves three thread pools, threadpool1-3. The path connections between nodes in the dependency graph represent the points from upstream to downstream nodes. The thread pool identifier on the node connection path represents the thread pool information corresponding to that connection path, and the number on the connection path represents the amount of resources occupied by that connection path. Taking the node connection path from CF1 to CF2 as an example, the attribute information of this connection path is threadpool2:10, indicating that this connection path corresponds to threadpool2 and occupies 10 resources from threadpool2.
[0112] Using the above method, the thread pool information and resource quantity information corresponding to the node connection path are used as the attribute information of the node connection path. The node connection paths are then connected according to the corresponding task result objects to obtain a dependency graph. This allows the dependency graph to reflect the thread pool and the number of thread resources occupied by each node connection path. When performing deadlock detection based on the dependency graph, the resource usage of the thread pool can be detected based on the attribute information of the node connection paths, thus achieving comprehensive detection of thread pool deadlock.
[0113] In an optional implementation, in step S103 above, the existence of circular dependencies can be determined based on the detection of node connections among task result objects in multiple thread pools. Specifically, Figure 8 This is a flowchart illustrating the process of detecting circular dependencies based on a dependency graph in a thread pool deadlock detection method provided by an embodiment of the present invention. Figure 8 As shown, step S103 above may include the following steps:
[0114] Step S801: Detect the node connections in the dependency graph to determine the node connection subgraph in the dependency graph.
[0115] In this embodiment of the invention, an improved Kahn algorithm is employed. Based on the dependency graph, an in-degree table and a multi-dimensional adjacency matrix are constructed to detect node connections in the dependency graph, thereby detecting node connection subgraphs within the dependency graph. The in-degree table records the in-degree of each task result object in the dependency graph, i.e., the number of upstream node objects corresponding to each task result object. Figure 6For example, for CF1, its upstream node object is CF4, and the number is 1, so the in-degree of CF1 is 1; the multidimensional adjacency matrix is used to record whether there is a dependency relationship between each task result object, that is, whether there is a node connection path, as well as related information for recording the node connection path, such as attribute information, etc.
[0116] In this embodiment of the invention, when using the improved Kahn algorithm to detect node connections in the dependency graph based on the in-degree table and the multidimensional adjacency matrix, task result objects with an in-degree of 0 are added to a queue and removed from the dependency graph and the in-degree table to mark them as processed. The node connection subgraph formed by the remaining nodes is then checked. Simultaneously, the downstream node objects pointed to by each downstream node are traversed according to the multidimensional adjacency matrix, and the in-degree of each downstream node object is decremented by 1. If the in-degree of a task result object decreases to 0 during processing, the task result object is added to the queue. This process is repeated until the queue is empty, completing the detection of node connections in the dependency graph.
[0117] Step S802: If there is a closed-loop node connection subgraph in the dependency graph, then the deadlock risk information is determined to be deadlock risk.
[0118] In this embodiment of the invention, when the queue is empty, there are still unprocessed task result objects in the in-degree table, and the in-degree of these unprocessed task result objects is not 0. This indicates that there is a closed-loop node connection subgraph in the dependency graph. At this time, it can be determined that there is a circular dependency in the thread pool, so the deadlock risk information is determined to be deadlock risk.
[0119] Correspondingly, when the queue is empty, all task result objects in the in-degree table have been processed, indicating that there is no closed-loop node connection subgraph in the dependency graph. At this time, it can be determined that there is no circular dependency in the thread pool, and therefore the deadlock risk information is determined to be that there is no deadlock risk.
[0120] Using the above method, node connections in the dependency graph are detected, node connection subgraphs in the dependency graph are identified, and deadlock risk information is identified when there is a closed-loop node connection subgraph in the dependency graph, thereby detecting deadlock caused by circular dependencies in the thread pool.
[0121] In an optional implementation, in step S103 above, it can be determined whether a resource exhaustion deadlock exists based on the detection of resource usage in multiple thread pools. Specifically, Figure 9 This is a schematic diagram of a process for detecting resource exhaustion deadlock based on a dependency graph in a thread pool deadlock detection method provided by an embodiment of the present invention. Figure 9As shown, step S103 above may include the following steps:
[0122] Step S901: Obtain the maximum number of threads corresponding to each thread pool, and determine the resource consumption threshold corresponding to each thread pool based on the maximum number of threads.
[0123] In this embodiment of the invention, the maximum number of threads corresponding to each thread pool is obtained, and resource usage thresholds are calculated based on the maximum number of threads to determine the resource usage thresholds for each thread pool. The resource usage thresholds are then used to detect the resource usage of each task result object on the thread pool. These resource usage thresholds are associated with a first warning message. Each thread pool can have multiple resource usage thresholds, each corresponding to a different first warning message, thus achieving tiered warnings. For example, resource usage thresholds can be set to 1 * maximum number of threads and 0.8 * maximum number of threads, with the first warning message corresponding to 0.8 * maximum number of threads being a level three warning and the first warning message corresponding to 1 * maximum number of threads being a level two warning.
[0124] Step S902: Based on the dependency graph, according to the thread pool information of the node connection path corresponding to each task result object, add up the resource quantity information of the corresponding node connection path to obtain the resource usage of each task result object.
[0125] In this embodiment of the invention, the attribute information of the node connection path includes the thread pool information corresponding to the node connection path and the resource quantity information occupied. Based on the dependency graph, the resource quantity information of each thread pool on the node connection path corresponding to each task result object is weighted; specifically, for each task result object, according to the thread pool information of the node connection path connected by its parent node, the resource quantity information of the node connection paths with the same thread pool information is added together to obtain the resource quantity occupied by each task result object for each thread pool. Figure 7 For example, for CF1, the node connection paths it connects to as its parent node include CF1-CF2 and CF1-CF3. The thread pool information involved in these node connection paths includes threadpool2 and threadpool1. By adding the resource quantity information of the node connection paths of the corresponding threadpool2 and threadpool1 thread pools, we can obtain the resource usage of CF1 as follows: it occupies 10 resources of threadpool2 thread pool and 1 resource of threadpool1 thread pool.
[0126] Step S903: If the number of resource occupancy objects associated with a task in the thread pool exceeds the corresponding resource occupancy threshold, then the deadlock risk information of the first thread pool is determined to be deadlock risk, and a first warning message associated with the resource occupancy threshold is issued.
[0127] In this embodiment of the invention, if a thread pool contains a first thread pool where the resource consumption of associated task result objects exceeds the corresponding resource consumption threshold, then the deadlock risk information of the first thread pool is determined to be deadlock risk. Simultaneously, based on the exceeded resource consumption threshold, a corresponding first warning message is determined and issued. Still using... Figure 7 Taking CF1 as an example, if the resource usage thresholds for threadpool2 are 5 and 8, then if CF1 occupies 10 resources from threadpool2, which exceeds 8, then it is determined that threadpool2 is at risk of deadlock and a first warning message corresponding to the resource usage threshold of 9 is issued.
[0128] Using the above method, the attribute information of the node connection path corresponding to each task result object is weighted based on the dependency graph to obtain the resource consumption of each task result object. When the resource consumption of the associated task result objects in the thread pool exceeds the corresponding resource consumption threshold, the deadlock risk information of the first thread pool is determined to be deadlock risk, thereby detecting deadlock caused by the thread pool's resource usage exceeding the threshold.
[0129] In one alternative implementation, Figure 10 This is a schematic diagram of another process for detecting resource exhaustion deadlock based on dependency graphs in a thread pool deadlock detection method provided in this embodiment of the invention, as shown below. Figure 10 As shown, step S103 above may include the following steps:
[0130] Step S1001: Based on the resource consumption of each task result object and the maximum number of threads in the corresponding thread pool, determine the asynchronous execution threshold for each thread pool.
[0131] In this embodiment of the invention, the maximum number of threads in the thread pool is divided by the resource usage of the associated task result objects, and then multiplied by a preset coefficient to obtain the asynchronous execution threshold corresponding to the thread pool. The asynchronous execution threshold is used to detect the resource usage of asynchronously executed tasks in each thread pool. The asynchronous execution threshold is associated with a second warning message. Each thread pool can have multiple asynchronous execution thresholds, each corresponding to a different second warning message, thus achieving tiered warnings. For example, asynchronous execution thresholds can be set to 1*(maximum number of threads / resource usage) and 2*(maximum number of threads / resource usage). The second warning message corresponding to 1*(maximum number of threads / resource usage) is a level three warning, and the second warning message corresponding to 2*(maximum number of threads / resource usage) is a level one warning.
[0132] In one alternative implementation, a thread pool may have multiple associated task result objects. For each associated task result object, the thread pool has a corresponding asynchronous execution threshold. When the thread pool executes a task corresponding to one of the task result objects, it determines whether the number of concurrent tasks in the thread pool exceeds the threshold based on the corresponding asynchronous execution threshold.
[0133] Step S1002: Obtain the number of concurrent tasks for each thread pool.
[0134] Step S1003: If there is a second thread pool in the thread pool whose number of concurrent tasks exceeds the corresponding asynchronous execution threshold, then the deadlock risk information of the second thread pool is determined to be deadlock risk, and a second warning information associated with the asynchronous execution threshold is issued.
[0135] In this embodiment of the invention, if there is a second thread pool in the thread pool whose number of concurrent tasks exceeds the corresponding asynchronous execution threshold, then the deadlock risk information of the second thread pool is determined to be deadlock risk. At the same time, based on the asynchronous execution threshold it exceeds, the corresponding second warning information is determined and issued.
[0136] Using the above method, based on the resource usage of each task result object and the maximum number of threads in the corresponding thread pool, the asynchronous execution threshold for each thread pool is determined. When there is a second thread pool in the thread pool where the number of concurrent tasks exceeds the corresponding asynchronous execution threshold, the deadlock risk information of the second thread pool is determined to be deadlock risk, thereby detecting deadlocks caused by thread pool resource usage exceeding the threshold.
[0137] This embodiment also provides a thread pool deadlock detection device, which is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0138] This embodiment provides a thread pool deadlock detection device that can be applied to a target operating system. The target operating system includes multiple thread pools, and each thread pool includes threads associated with task result objects, such as... Figure 11 As shown, the device includes:
[0139] The task result object parsing module 1101 is used to determine the dependency links of each task result object in multiple thread pools and the thread resource information corresponding to the dependency links based on the capture and parsing of the task result objects associated in multiple thread pools. The dependency links are used to characterize the node connection path between the task result object and the corresponding upstream node object and / or downstream node object.
[0140] The dependency graph construction module 1102 is used to construct a dependency graph based on the dependency links of each task result object and the thread resource information corresponding to the dependency links. The dependency graph is used to represent the node connection between each task result object in multiple thread pools, as well as the resource usage of the thread pool by the task result object.
[0141] The deadlock risk monitoring module 1103 is used to detect the node connection status of task result objects in multiple thread pools and the resource usage status of multiple thread pools based on the dependency graph, and to determine deadlock risk information.
[0142] In one optional implementation, the task result object parsing module 1101 includes:
[0143] The proxy object creation unit is used to create corresponding proxy objects for the first task result object contained in the first code segment in the target operating system, and replace the corresponding first task result object with the proxy object so as to rewrite the operation method of the corresponding first task result object based on the proxy object.
[0144] The downstream node object acquisition unit is used to obtain the downstream node object corresponding to the first task result object based on the operation method of the rewritten first task result object.
[0145] The dependency link building unit is used to build the dependency link of the first task result object based on the downstream node object corresponding to the first task result object.
[0146] In one optional implementation, the task result object parsing module 1101 includes:
[0147] The second task result object parsing unit is used to identify and parse the second task result object contained in the second code segment of the target operating system, and obtain the dependency storage field in the second task result object.
[0148] The dependency relationship storage field parsing unit is used to parse the dependency relationship storage fields to obtain the upstream node object and downstream node object corresponding to the second task result object;
[0149] The dependency link building unit is used to build the dependency link of the second task result object based on the upstream node object and downstream node object corresponding to the second task result object.
[0150] In one optional implementation, the task result object parsing module 1101 includes:
[0151] The target method parsing unit is used to intercept and parse the target method of the task result object class when cross-thread pool task blocking is detected, so as to obtain the third task result object.
[0152] The task result object lookup unit is used to look up the task result object of the call to the target method and obtain the fourth task result object;
[0153] The dependency link building unit is used to construct the dependency link of the third task result object by using the fourth task result object as the downstream node object corresponding to the third task result object.
[0154] In one optional implementation, the thread resource information includes thread pool information corresponding to the node connection path in the dependency link and the amount of resources occupied.
[0155] Dependency graph construction module 1102 includes:
[0156] The attribute information determination unit is used to use the thread pool information and resource quantity information corresponding to the node connection path as the attribute information of the node connection path.
[0157] The node connection path connection unit is used to connect node connection paths according to the corresponding task result objects to obtain a dependency graph.
[0158] In one optional implementation, the deadlock risk monitoring module 1103 includes:
[0159] The node connection detection unit is used to detect node connections in the dependency graph and determine the node connection subgraph in the dependency graph.
[0160] The deadlock risk information determination unit is used to determine that there is a deadlock risk if there is a closed-loop node connection subgraph in the dependency graph.
[0161] In one optional implementation, the deadlock risk monitoring module 1103 includes:
[0162] The resource usage threshold determination unit is used to obtain the maximum number of threads corresponding to each thread pool, and determine the resource usage threshold corresponding to each thread pool based on the maximum number of threads.
[0163] The resource consumption quantity determination unit is used to add up the resource consumption quantity of each task result object based on the dependency graph and the thread pool information of the node connection path corresponding to each task result object. The attribute information of the node connection path includes the thread pool information and the resource consumption quantity information of the node connection path.
[0164] The deadlock risk information determination unit is used to determine that the deadlock risk information of the first thread pool is present if the number of resource occupancy of associated task result objects in the thread pool exceeds the corresponding resource occupancy threshold, and to issue a first warning message associated with the resource occupancy threshold.
[0165] In one optional implementation, the deadlock risk monitoring module 1103 further includes:
[0166] The asynchronous execution threshold determination unit is used to determine the asynchronous execution threshold for each thread pool based on the resource consumption of each task result object and the maximum number of threads in the corresponding thread pool.
[0167] The concurrent task count acquisition unit is used to obtain the concurrent task count of each thread pool.
[0168] The deadlock risk information determination unit is used to determine that there is a deadlock risk in the second thread pool if there is a second thread pool in the thread pool whose number of concurrent tasks exceeds the corresponding asynchronous execution threshold, and to issue a second warning message associated with the asynchronous execution threshold.
[0169] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0170] In this embodiment, the thread pool deadlock detection device is presented in the form of a functional unit. Here, a unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0171] This invention also provides a computer device having the above-described features. Figure 11 The thread pool deadlock detection device shown.
[0172] Please see Figure 12 , Figure 12 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of the present invention, such as... Figure 12 As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 12 Take a processor 10 as an example.
[0173] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The programmable logic device may be a complex programmable logic device (CAMP), a field-programmable gate array (FPGA), a general-purpose array logic (GPA), or any combination thereof.
[0174] The memory 20 stores instructions executable by at least one processor 10 to cause the at least one processor 10 to perform the method shown in the above embodiments.
[0175] The memory 20 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the computer device. Furthermore, the memory 20 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some alternative embodiments, the memory 20 may optionally include memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0176] The memory 20 may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as flash memory, hard disk or solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0177] The computer device also includes a communication interface 30 for communicating with other devices or communication networks.
[0178] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code, which, when accessed and executed by the computer, processor, or hardware, implements the methods shown in the above embodiments.
[0179] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0180] Although embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations all fall within the scope defined by the present invention.
Claims
1. A thread pool deadlock detection method, characterized in that, Applied to a target operating system, the target operating system includes multiple thread pools, each thread pool including threads associated with task result objects; the method includes: Based on the capture and parsing of the task result objects associated in the multiple thread pools, the dependency links of each task result object in the multiple thread pools and the thread resource information corresponding to the dependency links are determined. The dependency links are used to characterize the node connection path between the task result object and the corresponding upstream node object and / or downstream node object. Based on the dependency links of each task result object and the thread resource information corresponding to the dependency links, a dependency graph is constructed. The dependency graph is used to represent the node connection between each task result object in multiple thread pools, as well as the resource usage of the thread pool by the task result object. Based on the dependency graph, the node connection status of the task result objects in multiple thread pools and the resource usage of multiple thread pools are detected to determine deadlock risk information.
2. The method according to claim 1, characterized in that, The step of determining the dependency chain of each task result object in the multiple thread pools based on the capture and parsing of task result objects associated in the multiple thread pools includes: For each first task result object contained in the first code segment of the target operating system, a corresponding proxy object is created, and the corresponding first task result object is replaced with the proxy object, so as to rewrite the operation method of the corresponding first task result object based on the proxy object; Based on the operation methods of the rewritten first task result object, obtain the downstream node object corresponding to the first task result object; Based on the downstream node object corresponding to the first task result object, construct the dependency chain of the first task result object.
3. The method according to claim 1, characterized in that, The step of determining the dependency chain of each task result object in the multiple thread pools based on the capture and parsing of task result objects associated in the multiple thread pools includes: The second task result object contained in the second code segment of the target operating system is identified and parsed to obtain the dependency storage field in the second task result object; The dependency relationship storage field is parsed to obtain the upstream node object and downstream node object corresponding to the second task result object; Based on the upstream and downstream node objects corresponding to the second task result object, construct the dependency chain of the second task result object.
4. The method according to claim 1, characterized in that, The step of determining the dependency chain of each task result object in the multiple thread pools based on the capture and parsing of task result objects associated in the multiple thread pools includes: If cross-thread pool task blocking is detected, the target method of the task result object class is intercepted and parsed to obtain the third task result object. The fourth task result object is obtained by searching the task result object that calls the target method; The fourth task result object is used as the downstream node object corresponding to the third task result object to construct the dependency link of the third task result object.
5. The method according to claim 1, characterized in that, The thread resource information includes the thread pool information and the amount of resources occupied by the node connection path in the dependency link; The construction of a dependency graph based on the dependency links of each task result object and the thread resource information corresponding to the dependency links includes: The thread pool information and resource quantity information corresponding to the node connection path are used as the attribute information of the node connection path; The node connection paths are connected according to the corresponding task result objects to obtain the dependency graph.
6. The method according to claim 1, characterized in that, Based on the dependency graph, the node connection status of the task result objects in multiple thread pools and the resource usage of multiple thread pools are detected to determine deadlock risk information, including: Detect the node connections in the dependency graph to determine the node connection subgraph in the dependency graph; If a closed-loop node connection subgraph exists in the dependency graph, then the deadlock risk information is determined to indicate that there is a deadlock risk.
7. The method according to claim 1, characterized in that, Based on the dependency graph, the node connection status of the task result objects in multiple thread pools and the resource usage of multiple thread pools are detected to determine deadlock risk information, including: Obtain the maximum number of threads corresponding to each thread pool, and determine the resource consumption threshold corresponding to each thread pool based on the maximum number of threads; Based on the dependency graph, according to the thread pool information of the node connection path corresponding to each task result object, the resource quantity information of the corresponding node connection path is added together to obtain the resource usage of each task result object. The attribute information of the node connection path includes the thread pool information corresponding to the node connection path and the resource usage information. If a thread pool contains a first thread pool whose resource usage of associated task result objects exceeds the corresponding resource usage threshold, then the deadlock risk information of the first thread pool is determined to be deadlock risk, and a first warning message associated with the resource usage threshold is issued.
8. The method according to claim 7, characterized in that, The step of detecting the node connections of the task result objects in multiple thread pools and the resource usage of multiple thread pools based on the dependency graph to determine deadlock risk information also includes: Based on the resource consumption of each task result object and the maximum number of threads in the corresponding thread pool, the asynchronous execution threshold for each thread pool is determined. Get the number of concurrent tasks for each thread pool; If there is a second thread pool in the thread pool whose number of concurrent tasks exceeds the corresponding asynchronous execution threshold, then the deadlock risk information of the second thread pool is determined to be deadlock risk, and a second warning message associated with the asynchronous execution threshold is issued.
9. A thread pool deadlock detection device, characterized in that, Applied in a target operating system, the target operating system includes multiple thread pools, each thread pool including threads associated with task result objects; the device includes: The task result object parsing module is used to determine the dependency link of each task result object in the multiple thread pools and the thread resource information corresponding to the dependency link based on the capture and parsing of the task result objects associated in the multiple thread pools. The dependency link is used to characterize the node connection path between the task result object and the corresponding upstream node object and / or downstream node object. The dependency graph construction module is used to construct a dependency graph based on the dependency links of each task result object and the thread resource information corresponding to the dependency links. The dependency graph is used to represent the node connection between each task result object in multiple thread pools, as well as the resource usage of the thread pool by the task result object. The deadlock risk monitoring module is used to detect the node connection status of the task result objects in multiple thread pools and the resource usage status of multiple thread pools based on the dependency graph, and to determine deadlock risk information.
10. A computer device, characterized in that, include: A memory and a processor are interconnected, the memory stores computer instructions, and the processor executes the computer instructions to perform the thread pool deadlock detection method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to execute the thread pool deadlock detection method according to any one of claims 1 to 8.