Thread deadlock monitoring method, system, client terminal device and vehicle-mounted system
By using the preset monitoring thread in the vehicle system to monitor the message execution status of the monitored thread, and obtaining and reporting thread deadlock information, the deficiencies in thread deadlock monitoring and analysis in the vehicle system are solved, and the system stability and security are improved. .
Patent Information
- Application Number
- CN202410379690.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-29
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-03-29
AI Technical Summary
The vehicle system lacks thread deadlock monitoring methods and key information reporting methods, resulting in the inability to analyze and handle thread deadlock problems in a timely manner, affecting system stability and security.
Monitor the message execution of the monitored thread through the preset monitoring thread. When it is determined that the message execution is abnormal, obtain the thread deadlock information and report it to the target end, including the blocking lock information held and waiting for the deadlock thread, so that The target side performs analysis and processing.
It realizes real-time monitoring of monitored threads and automatic deadlock information reporting, improves system stability and security, reduces maintenance costs and manual intervention, handles thread deadlock issues in a timely manner, and avoids system crashes and freezes.
Smart Images

Figure CN118193323B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a thread deadlock monitoring method, system, client terminal device and vehicle-mounted system. Background Art
[0002] In-vehicle systems usually use multiple threads to implement various functions, such as engine control, vehicle safety, and entertainment systems. Due to the interdependence and resource competition between threads, when thread deadlock occurs, it often causes the in-vehicle system to crash or malfunction, reducing vehicle performance and posing potential risks to vehicle safety.
[0003] At present, there is a lack of monitoring methods for thread deadlocks in vehicle systems, and there is a lack of reporting methods for key information of thread deadlocks, which makes it impossible to analyze and handle the causes of thread deadlocks in a timely manner. Summary of the invention
[0004] The present application provides a thread deadlock monitoring method, system, client terminal device and vehicle-mounted system to solve the technical problems in the prior art of lacking a monitoring method for the thread deadlock situation of the vehicle-mounted system, and lacking a reporting method for key information of the thread deadlock, resulting in the inability to analyze and handle the causes of the thread deadlock in a relatively timely manner.
[0005] The present application provides a thread deadlock monitoring method, the method comprising:
[0006] Using the preset monitoring thread, monitor the message execution status of the preset monitored thread;
[0007] When it is determined that the message execution is abnormal, the thread deadlock information is obtained and reported to the target end. The thread deadlock information includes: blocking lock information held and waited for by the deadlock thread. The deadlock thread refers to the monitored thread where the message execution exception occurs. The thread deadlock information is used to instruct the target end to perform thread deadlock analysis and processing.
[0008] In one embodiment of the present application, the steps of monitoring the message execution status of the preset monitored thread by using the preset monitoring thread include:
[0009] Utilizing the preset message circulator in the monitored thread, taking out the message in the message queue of the monitored thread, and sending the taken out message to the monitoring thread and the preset message processor at the same time;
[0010] The message sent to the monitoring thread is used to indicate that the monitoring thread sleeps for a preset time; when the cumulative sleep time reaches the preset time, the message execution status of the corresponding message is obtained from the message processor; when the message execution status is that the message has not been executed, it is determined that the message execution is abnormal.
[0011] In one embodiment of the present application, when it is determined that the message execution is abnormal, the step of obtaining thread deadlock information includes:
[0012] When it is determined that the message execution is abnormal, the monitoring thread is used to send a termination signal to the preset controller. The termination signal is used to trigger the generation of a trace file. The trace file is one of the data sources for obtaining the thread deadlock information. The trace file includes: synchronized blocking lock information, thread information holding and waiting for synchronized blocking locks, LockSupport blocking lock information, first thread information waiting for LockSupport blocking lock, Object blocking lock information, and thread information waiting for Object blocking lock.
[0013] In one embodiment of the present application, when it is determined that the message execution is abnormal, the step of obtaining thread deadlock information further includes:
[0014] Using a preset LockSupport blocking lock recording program, the threads waiting to obtain the LockSupport blocking lock are recorded in a preset waiting list. When it is determined that any of the threads obtains the LockSupport blocking lock, the corresponding thread is removed from the waiting list, and the corresponding thread is recorded as the holding thread of the LockSupport blocking lock; the LockSupport blocking lock recording program is set in the program of the monitored thread executing the database transaction;
[0015] Based on the waiting list, obtain the second thread information waiting for the LockSupport;
[0016] Based on the thread holding the LockSupport blocking lock recorded in the LockSupport blocking lock recording program, obtain thread information holding the LockSupport blocking lock;
[0017] The second thread information and the thread information holding the LockSupport blocking lock are added to the trace file to obtain the thread deadlock information.
[0018] In one embodiment of the present application, the step of adding the second thread information and the thread information holding the LockSupport blocking lock to the trace file to obtain the thread deadlock information includes:
[0019] Add the second thread information and the thread information holding the LockSupport blocking lock to the last line of the trace file;
[0020] The trace file to which the completion information is added is determined as the file where the thread deadlock information is located.
[0021] In one embodiment of the present application, after the step of adding the second thread information and the thread information holding the LockSupport blocking lock to the last line of the trace file, the method further includes:
[0022] The name of the deadlock thread, the system version number, and the deadlock occurrence time are added to the last line of the trace file to complete the information addition of the trace file.
[0023] In one embodiment of the present application, the step of reporting the thread deadlock information to the target end includes:
[0024] The trace file to which the completion information is added is reported to the target end, and the trace file to which the completion information is added is used to instruct the target end to perform thread deadlock analysis and processing.
[0025] The present application also provides a thread deadlock monitoring system, including:
[0026] A first monitoring module is used to monitor the message execution status of a preset monitored thread using a preset monitoring thread;
[0027] The second monitoring module is used to obtain thread deadlock information when it is determined that the message execution is abnormal, and report the thread deadlock information to the target end. The thread deadlock information includes: blocking lock information held and waited for by the deadlock thread. The deadlock thread refers to the monitored thread where the message execution exception occurs. The thread deadlock information is used to instruct the target end to perform thread deadlock analysis and processing.
[0028] The present application also provides a client terminal device, including: the thread deadlock monitoring system as described above.
[0029] The present application also provides a vehicle-mounted system, comprising: the client terminal device as described above.
[0030] Beneficial effects of the present application: The present application proposes a thread deadlock monitoring method, system, client terminal device and vehicle-mounted system. The method monitors the message execution of a preset monitored thread by using a preset monitoring thread; when it is determined that the message execution is abnormal, the thread deadlock information is obtained, and the thread deadlock information is reported to the target end. The thread deadlock information includes: blocking lock information held and waited for by the deadlock thread. The deadlock thread refers to the monitored thread with message execution abnormality. The thread deadlock information is used to instruct the target end to perform thread deadlock analysis and processing. The real-time monitoring of the monitored thread is well achieved. In the event of message execution abnormality, the thread deadlock information is automatically obtained and sent to the target end, and the thread deadlock information is analyzed and processed by the target end. The automation is high and the cost is low. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 A flowchart of a thread deadlock monitoring method provided in one embodiment of the present application;
[0032] Figure 2 A schematic diagram of the structure of a thread deadlock monitoring system provided in one embodiment of the present application;
[0033] Figure 3 A schematic diagram of a thread deadlock monitoring logic of a client terminal device provided in an embodiment of the present application;
[0034] Figure 4 It is a structural schematic diagram of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0035] The following describes the embodiments of the present application through specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. The present application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.
[0036] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present application, and thus the drawings only show components related to the present application rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed at will, and the component layout may also be more complicated.
[0037] In the following description, a large number of details are discussed to provide a more thorough explanation of the embodiments of the present application. However, it is obvious to those skilled in the art that the embodiments of the present application can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present application difficult to understand.
[0038] With the gradual upgrade of the vehicle-mounted system, the smart cockpit is taking on more and more business, which leads to many parallel operations in the software layer. At present, when releasing the vehicle-mounted system version, the system or application often gets stuck, and the root cause of this kind of problem is thread deadlock. At present, there is a lack of monitoring methods for thread deadlocks and reporting methods for key information of thread deadlocks, which makes it impossible to identify thread deadlocks in a timely manner, and it is impossible to analyze and process the causes of thread deadlocks in a timely manner. Therefore, the present application proposes a thread deadlock monitoring method, system, client terminal device and vehicle-mounted system to solve the above problems.
[0039] In order to facilitate understanding of the thread deadlock monitoring method, system, client terminal device and vehicle-mounted system provided by the present application, some technical terms involved in the present application are explained below.
[0040] Lock: A lock is a mechanism used to control access to a shared resource to ensure that only one thread can access the resource at a time. The purpose of a lock is to prevent multiple threads from modifying a shared resource at the same time, causing data inconsistencies or other problems.
[0041] Holding a lock: In a multi-threaded application scenario, when a thread successfully acquires a lock and holds it, other threads cannot acquire the lock until the thread holding the lock releases it. The thread holding the lock can access the protected shared resources or execute the critical section code that requires mutual exclusive access.
[0042] Waiting for a lock: In a multi-threaded application scenario, when a thread tries to acquire a lock but the lock is already held by another thread, the thread will enter a waiting state until the lock is released and the thread successfully acquires the lock. During the waiting process, the thread will temporarily stop executing and will not occupy CPU resources until the required lock is acquired before it can continue to execute.
[0043] Deadlock: Deadlock refers to a situation in which two or more threads in a multi-threaded application scenario hold resources that the other thread needs, causing them to be unable to continue executing and thus falling into a state of permanent blocking. In simple terms, it means that each thread is waiting for the other thread to release resources, but it does not release resources itself, resulting in a situation in which it cannot continue executing.
[0044] See also Figure 1, Figure 1 A flowchart of a thread deadlock monitoring method provided in an embodiment of the present application is shown in FIG. Figure 1 As shown, the thread deadlock monitoring method provided in this embodiment includes:
[0045] S110: Using a preset monitoring thread, monitoring the message execution status of a preset monitored thread.
[0046] S120: When it is determined that the message execution is abnormal, the thread deadlock information is obtained and reported to the target end, the thread deadlock information includes: blocking lock information held and waited for by the deadlock thread, the deadlock thread refers to the monitored thread where the message execution exception occurs, and the thread deadlock information is used to instruct the target end to perform thread deadlock analysis and processing.
[0047] It should be noted that the above step S120 is executed by the monitoring thread, that is, when the monitoring thread determines that the message execution of the monitored thread is abnormal, the thread deadlock information is obtained and the thread deadlock information is reported to the target end. The monitoring thread in this embodiment is equivalent to a monitoring probe. By using the monitoring probe, real-time monitoring of the message execution of the monitored thread can be better achieved. This embodiment reports the thread deadlock information to the target end, which facilitates the target end to perform corresponding analysis and processing after receiving the thread deadlock information.
[0048] It should also be noted that the locks in Java (a widely used computer programming language) are classified into spin locks, reentrant locks, and blocking locks. Among them, the only lock that can cause thread deadlock is the blocking lock. There are three types of blocking locks: synchronized blocking locks, LockSupport blocking locks, and Object blocking locks. By obtaining the blocking lock information held and waited by the deadlocked thread and reporting it to the target end, it can help the target end to analyze the cause of the blocking.
[0049] In addition, the number of the monitored threads is one or more. In a specific embodiment, the monitoring thread can be used to monitor one or more monitored threads, that is, to monitor the message execution status of one or more monitored threads.
[0050] In some embodiments, the step of monitoring the message execution status of a preset monitored thread using a preset monitoring thread includes:
[0051] The message in the message queue of the monitored thread is taken out by using the message circulator (Looper) preset in the monitored thread, and the taken out message is sent to the monitoring thread and the preset message handler (Handler) at the same time.
[0052] It should be noted that by using the thread's Looper method, messages can be continuously taken out from the message queue of the monitored thread. In addition, by using the Looper method, the taken out messages are sent to the monitoring thread and the message processor at the same time, which makes it easier for the monitoring thread to monitor the execution of the messages taken out by the monitored thread, thereby determining whether the monitored thread is deadlocked.
[0053] It should also be noted that the message sent to the monitoring thread is used to instruct the monitoring thread to sleep for a preset duration; when the cumulative sleep duration reaches the preset duration, the message execution status of the corresponding message is obtained from the message processor; when the message execution status is that the message has not been executed, it is determined that the message execution is abnormal.
[0054] Specifically, when the monitoring thread receives a message taken out from the message queue of the monitored thread, it sleeps for a preset time, which can be set according to actual conditions, such as 3 minutes, etc., with high flexibility. When the sleep duration reaches the preset time, the message execution status of the message is obtained from the message processor. If the message execution status is that the message has not been executed, it is determined that the message execution is abnormal, that is, the corresponding monitored thread has a deadlock. Through the above method, real-time monitoring of the monitored thread can be better achieved with low cost.
[0055] In the above embodiment, the real-time monitoring of the deadlock situation of the monitored thread is completed. Next, the reporting of the key information of the thread deadlock is explained. Regarding the key information of the thread deadlock, in this embodiment, the blocking lock information held and waited by the deadlock thread is determined as the key information of the thread deadlock. In order to further enrich and improve the key information of the thread deadlock, in this embodiment, the key information of the thread deadlock is determined to also include the thread information.
[0056] In order to facilitate the target end to analyze the cause of thread deadlock, the following information needs to be obtained for the three types of blocking locks: synchronized blocking lock, LockSupport blocking lock, and Object blocking lock:
[0057] 1. For synchronized blocking locks, it is necessary to obtain thread information that holds and waits for synchronized blocking locks, as well as the corresponding lock information;
[0058] 2. For the LockSupport blocking lock, it is necessary to obtain the thread information holding and waiting for the LockSupport blocking lock, as well as the corresponding lock information;
[0059] 3. For the Object blocking lock, you need to obtain the thread information waiting for the Object blocking lock and the corresponding lock information. For details, please refer to the following Table 1:
[0060] Table 1 Example of thread information corresponding to blocking locks
[0061]
[0062] The "holding thread + waiting thread" in the above Table 1 refers to the need to obtain information about the thread holding and waiting for the corresponding blocking lock, as well as the lock information corresponding to the thread, and the "waiting thread" refers to the need to obtain information about the thread waiting for the corresponding blocking lock, as well as the lock information corresponding to the thread.
[0063] In order to obtain the above information, this embodiment uses the system mechanism to capture thread deadlock information. Specifically, in some embodiments, when it is determined that the message execution is abnormal, the step of obtaining thread deadlock information includes:
[0064] When it is determined that the message execution is abnormal, the monitoring thread is used to send a termination signal to the preset controller. The termination signal is used to trigger the generation of a trace file. The trace file is one of the data sources for obtaining the thread deadlock information. The trace file includes: synchronized blocking lock information, thread information holding and waiting for synchronized blocking locks, LockSupport blocking lock information, first thread information waiting for LockSupport blocking lock, Object blocking lock information, and thread information waiting for Object blocking lock.
[0065] It should be noted that for the vehicle-mounted system, when an Android application has an ANR (Application Not Responding), the system will send a SIGQUIT (termination) signal to the process where the ANR occurs, and automatically capture the corresponding deadlocked thread in the process, and output a trace file. In the above embodiment, in order to obtain blocking lock information, etc., when it is determined that the message execution is abnormal, the monitoring thread is used to send a termination signal to a preset controller to trigger the system mechanism, generate a trace file, and capture the blocking lock information, etc., which is more convenient to implement. The controller refers to the controller of the vehicle-mounted system. By obtaining the trace file, it can help the target end to analyze the cause of the thread deadlock.
[0066] The above trace file has basically covered most of the key information, however, the file lacks the information of the holder of the LockSupport lock, that is, the information of the thread holding the LockSupport lock. In order to further improve the trace file and obtain complete thread deadlock information, in some embodiments, when it is determined that the message execution is abnormal, the step of obtaining thread deadlock information also includes:
[0067] 1. Using the preset LockSupport blocking lock recording program, the threads waiting to obtain the LockSupport blocking lock are recorded in the preset waiting list. When it is determined that any of the threads obtains the LockSupport blocking lock, the corresponding thread is removed from the waiting list, and the corresponding thread is recorded as the holding thread of the LockSupport blocking lock; the LockSupport blocking lock recording program is set in the program of the monitored thread executing database transactions.
[0068] It should be noted that, through cluster analysis of deadlock problems, it is found that all the problems of LockSupport blocking locks in the deadlock stack are database problems, and it is found that the entries of LockSupport locks of database transactions are unified. Therefore, this embodiment sets a LockSupport blocking lock recording program in the program in which the monitored thread executes database transactions, and uses the LockSupport blocking lock recording program to record the threads waiting to obtain the LockSupport blocking lock into a preset waiting list. When it is determined that any thread obtains the LockSupport blocking lock, the corresponding thread is removed from the waiting list, and the corresponding thread is recorded as the holding thread of the LockSupport blocking lock. Through the above steps, it is possible to better achieve the acquisition of information on the thread holding the LockSupport blocking lock.
[0069] 2. Based on the waiting list, obtain the second thread information waiting for the LockSupport.
[0070] 3. Based on the thread holding the LockSupport blocking lock recorded in the LockSupport blocking lock recording program, obtain the thread information holding the LockSupport blocking lock.
[0071] 4. Add the second thread information and the thread information holding the LockSupport blocking lock to the trace file to obtain the thread deadlock information.
[0072] It should be noted that by adding the second thread information and the thread information holding the LockSupport blocking lock to the trace file, the trace file can be improved, which is helpful for the target end to analyze the cause of the deadlock.
[0073] In some embodiments, the step of adding the second thread information and the thread information holding the LockSupport blocking lock to the trace file to obtain the thread deadlock information includes:
[0074] 1. Add the second thread information and the thread information holding the LockSupport blocking lock to the last line in the trace file.
[0075] It should be noted that by adding the second thread information and the thread information holding the LockSupport blocking lock to the last line in the trace file, it is convenient for the subsequent target end to extract information during parsing.
[0076] 2. Determine the trace file to which the completion information is added as the file where the thread deadlock information is located.
[0077] In some embodiments, after the step of adding the second thread information and the thread information holding the LockSupport blocking lock to the last line of the trace file, the method further includes:
[0078] The name of the deadlock thread, the system version number, and the deadlock occurrence time are added to the last line of the trace file to complete the information addition of the trace file.
[0079] It should be noted that by adding the name of the deadlock thread, the system version number, and the deadlock occurrence time to the last line of the trace file, the trace file can be further enriched and improved. In the specific implementation process, other information can also be added to the trace file, such as the thread identifier of the deadlock thread.
[0080] In some embodiments, the step of reporting the thread deadlock information to the target end includes:
[0081] The trace file with the completion information added is reported to the target end, and the trace file with the completion information added is used to instruct the target end to perform thread deadlock analysis and processing. It should be noted that by reporting the trace file with the completion information added to the target end, the problem of incomplete information reported after thread deadlock (stuck) is better solved, and the feasibility is relatively high.
[0082] It should be mentioned that the thread deadlock monitoring method in the above embodiment can detect thread deadlock problems in a timely manner, which helps to improve system stability and reliability and effectively reduce the risk of system crashes and functional failures. In addition, it helps to reduce maintenance costs and reduce manual intervention. Furthermore, the target end can analyze and handle the causes of thread deadlocks in a timely manner based on the trace file added to the received completion information, that is, the thread deadlock information, thereby avoiding system freezes or crashes caused by thread deadlocks, which helps to improve user experience. Finally, the method can ensure driving safety as much as possible, that is, by improving the stability and safety of the vehicle-mounted system during driving, it can provide protection for driving safety.
[0083] Please refer to Figure 2 This embodiment also provides a thread deadlock monitoring system, including:
[0084] The first monitoring module 210 is used to monitor the message execution status of the preset monitored thread by using the preset monitoring thread;
[0085] The second monitoring module 220 is used to obtain thread deadlock information when determining that the message execution is abnormal, and report the thread deadlock information to the target end, the thread deadlock information includes: blocking lock information held and waited for by the deadlock thread, the deadlock thread refers to the monitored thread where the message execution is abnormal, and the thread deadlock information is used to instruct the target end to perform thread deadlock analysis and processing. The thread deadlock monitoring system in this embodiment better realizes real-time monitoring of the monitored threads and timely reporting of thread deadlock information, with a high degree of automation and low cost.
[0086] In some embodiments, the first monitoring module 210 is specifically used to use the message circulator preset in the monitored thread to take out the message in the message queue of the monitored thread, and send the taken out message to the monitoring thread and the preset message processor at the same time;
[0087] The message sent to the monitoring thread is used to indicate that the monitoring thread sleeps for a preset time; when the cumulative sleep time reaches the preset time, the message execution status of the corresponding message is obtained from the message processor; when the message execution status is that the message has not been executed, it is determined that the message execution is abnormal.
[0088] In some embodiments, the second monitoring module 220 is specifically used to use the monitoring thread to send a termination signal to a preset controller when it is determined that the message execution is abnormal. The termination signal is used to trigger the generation of a trace file. The trace file is one of the data sources for obtaining the thread deadlock information. The trace file includes: synchronized blocking lock information, thread information holding and waiting for synchronized blocking locks, LockSupport blocking lock information, first thread information waiting for LockSupport blocking lock, Object blocking lock information, and thread information waiting for Object blocking lock.
[0089] In some embodiments, the second monitoring module 220 is further specifically used to use a preset LockSupport blocking lock recording program to record threads waiting to obtain the LockSupport blocking lock into a preset waiting list, and when it is determined that any of the threads has obtained the LockSupport blocking lock, remove the corresponding thread from the waiting list, and record the corresponding thread as the holding thread of the LockSupport blocking lock; the LockSupport blocking lock recording program is set in the program of the monitored thread executing the database transaction;
[0090] Based on the waiting list, obtain the second thread information waiting for the LockSupport;
[0091] Based on the thread holding the LockSupport blocking lock recorded in the LockSupport blocking lock recording program, obtain thread information holding the LockSupport blocking lock;
[0092] The second thread information and the thread information holding the LockSupport blocking lock are added to the trace file to obtain the thread deadlock information.
[0093] In some embodiments, the second monitoring module 220 is further specifically configured to add the second thread information and the thread information holding the LockSupport blocking lock to the last line of the trace file;
[0094] The trace file to which the completion information is added is determined as the file where the thread deadlock information is located.
[0095] In some embodiments, the second monitoring module 220 is further specifically configured to add the name of the deadlock thread, the system version number, and the deadlock occurrence time to the last line of the trace file to complete the information addition of the trace file.
[0096] In some embodiments, the second monitoring module 220 is further specifically used to report the trace file with completion information added to the target end, and the trace file with completion information added is used to instruct the target end to perform thread deadlock analysis and processing.
[0097] Figure 3 A schematic diagram of thread deadlock monitoring logic of a client terminal device provided in an embodiment of the present application. Figure 3 The client terminal device includes: a monitoring thread (Watch Thread) and a monitored thread (Thread). The monitored thread is provided with a message circulator (Looper), which takes out the message in the message queue of the monitoring thread (see Figure 3 Event (event) in the queue), and send the taken out message to the monitoring thread and the message processor (Handler) at the same time. When the monitoring thread receives the message taken out by the message circulator, it sleeps (Sleep) for a preset time. When the cumulative sleep time reaches the preset time, it obtains the message execution status of the corresponding message from the message processor; when the message execution status is that the message has not been executed, it is determined that the message execution is abnormal. When it is determined that the message execution is abnormal, the thread deadlock information is obtained (the thread deadlock information includes: the blocking lock information held and waiting by the deadlock thread), and the thread deadlock information is reported to the target end. The target end can be a background device end. After receiving the reported thread deadlock information, the target end automatically analyzes the cause of the thread deadlock (stuck). After the analysis is completed, it can make a bill of lading, and then follow up on the resolution of each deadlock problem. In addition, Figure 3 Event entry in the message queue refers to inputting the message into the message queue. The Handler can also send the message to the message queue. Moreover, according to actual needs, the Handler can be controlled to send the relevant information of the message execution to the monitoring thread to further improve the thread deadlock information.
[0098] In some embodiments, an electronic device is also provided, which may be a server, and its internal structure is shown in FIG. Figure 4 As shown. The electronic device includes a processor, a memory, a network interface and a database connected via a system bus. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external client via a network connection. When the computer program is executed by the processor, the functions or steps on the server side of the above method are implemented.
[0099] In some embodiments, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented: using a preset monitoring thread, monitoring the message execution status of a preset monitored thread; when it is determined that the message execution is abnormal, obtaining thread deadlock information, and reporting the thread deadlock information to a target end, the thread deadlock information includes: blocking lock information held and waited for by the deadlock thread, the deadlock thread refers to the monitored thread in which the message execution exception occurs, and the thread deadlock information is used to instruct the target end to perform thread deadlock analysis and processing.
[0100] In some embodiments, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented: using a preset monitoring thread, the message execution status of a preset monitored thread is monitored; when it is determined that the message execution is abnormal, thread deadlock information is obtained, and the thread deadlock information is reported to the target end, the thread deadlock information includes: blocking lock information held and waited for by the deadlock thread, the deadlock thread refers to the monitored thread where the message execution exception occurs, and the thread deadlock information is used to instruct the target end to perform thread deadlock analysis and processing.
[0101] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or electronic device can refer to the relevant descriptions on the server side and the client side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0102] The flow chart and block diagram in the accompanying drawings illustrate the possible implementation architecture, function and operation of the method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0103] The above embodiments are merely illustrative of the principles and effects of the present application and are not intended to limit the present application. Anyone familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present application. Therefore, all equivalent modifications or changes made by a person of ordinary skill in the art without departing from the spirit and technical ideas disclosed in the present application shall still be covered by the claims of the present application.
Claims
1. A thread deadlock monitoring method, characterized in that: include: Using the preset monitoring thread, monitor the message execution status of the preset monitored thread; When it is determined that the message execution is abnormal, thread deadlock information is obtained and reported to the target end, the thread deadlock information includes: blocking lock information held and waited for by the deadlock thread, the deadlock thread refers to the monitored thread where the message execution exception occurs, and the thread deadlock information is used to instruct the target end to perform thread deadlock analysis and processing; When it is determined that the message execution is abnormal, the steps of obtaining thread deadlock information include: When it is determined that the message execution is abnormal, the monitoring thread is used to send a termination signal to a preset controller, and the termination signal is used to trigger the generation of a trace file, and the trace file is one of the data sources for obtaining the thread deadlock information, and the trace file includes: LockSupport blocking lock information and the first thread information waiting for LockSupport blocking lock; When it is determined that the message execution is abnormal, the step of obtaining thread deadlock information further includes: Using a preset LockSupport blocking lock recording program, the threads waiting to obtain the LockSupport blocking lock are recorded in a preset waiting list. When it is determined that any of the threads obtains the LockSupport blocking lock, the corresponding thread is removed from the waiting list, and the corresponding thread is recorded as the holding thread of the LockSupport blocking lock; the LockSupport blocking lock recording program is set in the program of the monitored thread executing the database transaction; Based on the waiting list, obtain the second thread information waiting for the LockSupport; Based on the thread holding the LockSupport blocking lock recorded in the LockSupport blocking lock recording program, obtain thread information holding the LockSupport blocking lock; The second thread information and the thread information holding the LockSupport blocking lock are added to the trace file to obtain the thread deadlock information.
2. The thread deadlock monitoring method according to claim 1, characterized in that: The steps of monitoring the message execution status of the preset monitored thread by using the preset monitoring thread include: Utilizing the preset message circulator in the monitored thread, taking out the message in the message queue of the monitored thread, and sending the taken out message to the monitoring thread and the preset message processor at the same time; The message sent to the monitoring thread is used to indicate that the monitoring thread sleeps for a preset time; when the cumulative sleep time reaches the preset time, the message execution status of the corresponding message is obtained from the message processor; when the message execution status is that the message has not been executed, it is determined that the message execution is abnormal.
3. The thread deadlock monitoring method according to claim 1, characterized in that: The trace file also includes: synchronized blocking lock information, thread information holding and waiting for synchronized blocking locks, Object blocking lock information, and thread information waiting for Object blocking locks.
4. The thread deadlock monitoring method according to claim 1, characterized in that: The step of adding the second thread information and the thread information holding the LockSupport blocking lock to the trace file to obtain the thread deadlock information includes: Add the second thread information and the thread information holding the LockSupport blocking lock to the last line of the trace file; The trace file to which the completion information is added is determined as the file where the thread deadlock information is located.
5. The thread deadlock monitoring method according to claim 4, characterized in that: After the step of adding the second thread information and the thread information holding the LockSupport blocking lock to the last line of the trace file, the method further includes: The name of the deadlock thread, the system version number, and the deadlock occurrence time are added to the last line of the trace file to complete the information addition of the trace file.
6. The thread deadlock monitoring method according to claim 4 or 5, characterized in that: The step of reporting the thread deadlock information to the target end includes: The trace file to which the completion information is added is reported to the target end, and the trace file to which the completion information is added is used to instruct the target end to perform thread deadlock analysis and processing.
7. A thread deadlock monitoring system, characterized in that: include: A first monitoring module is used to monitor the message execution status of a preset monitored thread using a preset monitoring thread; A second monitoring module is used to obtain thread deadlock information when determining that the message execution is abnormal, and report the thread deadlock information to the target end, the thread deadlock information includes: blocking lock information held and waiting by the deadlock thread, the deadlock thread refers to the monitored thread where the message execution exception occurs, and the thread deadlock information is used to instruct the target end to perform thread deadlock analysis and processing; The second monitoring module is specifically used to use the monitoring thread to send a termination signal to a preset controller when determining that the message execution is abnormal, and the termination signal is used to trigger the generation of a trace file, and the trace file is one of the data sources for obtaining the thread deadlock information, and the trace file includes: LockSupport blocking lock information and the first thread information waiting for LockSupport blocking lock; The second monitoring module is further specifically used to use a preset LockSupport blocking lock recording program to record threads waiting to obtain the LockSupport blocking lock into a preset waiting list, and when it is determined that any of the threads has obtained the LockSupport blocking lock, remove the corresponding thread from the waiting list, and record the corresponding thread as the holding thread of the LockSupport blocking lock; the LockSupport blocking lock recording program is set in the program for the monitored thread to execute database transactions; Based on the waiting list, obtain the second thread information waiting for the LockSupport; Based on the thread holding the LockSupport blocking lock recorded in the LockSupport blocking lock recording program, obtain thread information holding the LockSupport blocking lock; The second thread information and the thread information holding the LockSupport blocking lock are added to the trace file to obtain the thread deadlock information.
8. A client terminal device, characterized in that: include: The thread deadlock monitoring system as claimed in claim 7.
9. A vehicle-mounted system, characterized in that: include: The client terminal device as claimed in claim 8.
Citation Information
Patent Citations
Function execution timeout and deadlock detection method based on dynamic tracking of operating period
CN104636259A
Software endless loop or blockage monitoring method and system
CN111045832A
Process monitoring method, device, electronic equipment and readable storage medium
CN113535512A
Method and device for monitoring system deadlock and medium
CN115934371A
Deadlock processing method, electronic equipment and storage medium
CN117687806A
