Thread control method, thread control device and storage medium
By monitoring the thread lock status and printing the call stack multiple times, the lag problem caused by thread locking in Android system is solved, and the blockage points are quickly positioned, which improves system stability.
Patent Information
- Application Number
- CN202110954555.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-19
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2041-08-19
AI Technical Summary
In Android systems, synchronous locks between multiple threads cause lock holding time to be too long, resulting in system lag or ANR, and it is difficult for the existing technology to efficiently locate blockage points.
By monitoring the lock-holding status of the thread, when the first thread holds the lock and the second thread fails to apply for the lock, the call stack of the first thread is printed multiple times to obtain its task information during the lock-holding, so as to quickly locate the blocking point.
It improves the positioning efficiency of blockage points, reduces system lag time, and enhances system stability.
Smart Images

Figure CN113778696B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of information processing, and in particular to a thread control method, a thread control device, and a storage medium. Background Art
[0002] Android, the mainstream operating system for mobile terminals, has interdependent relationships between multiple threads in some processes. These interdependent threads are synchronized through mechanisms such as synchronized locks. If one of these interdependent threads becomes blocked due to holding the lock for too long, the entire Android system may become stagnant or even freeze and restart (Application Not Responding, ANR). To resolve these freezes, freezes, and restarts in the Android system, it is necessary to locate the blockage point, understand the cause, and provide a solution. However, how to locate the blockage point is an urgent issue. Summary of the Invention
[0003] In order to overcome the problems existing in the related art, the present disclosure provides a thread control method, a thread control device and a storage medium.
[0004] According to a first aspect of an embodiment of the present disclosure, there is provided a thread control method, comprising:
[0005] Monitor the lock holding status of the threads, and in response to monitoring that the first thread holds the lock and the second thread fails to apply for the lock, print the call stack of the first thread.
[0006] In one embodiment, the thread control method further includes:
[0007] In response to the second thread reapplying for a lock and failing to apply for the lock, the first thread call stack is printed again.
[0008] In one embodiment, before printing the first thread call stack again, the thread control method further includes:
[0009] Determine whether the time interval meets a preset time interval threshold, and / or the number of times the first thread call stack has been printed is less than the print count threshold, where the time interval is the time interval between the time when the current second thread fails to apply for the lock and the time when the first thread call stack was last printed.
[0010] In one embodiment, the thread control method further includes:
[0011] Record and print the timestamp of the first thread call stack; the time interval is determined based on the timestamp and the time when the current second thread fails to apply for a lock.
[0012] In one embodiment, before printing the first thread call stack, the thread control method further includes:
[0013] It is determined that the timeout parameter added to the synchronization function of each thread is monitored to represent the timeout.
[0014] In one embodiment, the second thread includes the same thread, or multiple different threads.
[0015] According to a second aspect of an embodiment of the present disclosure, there is provided a thread control device, comprising:
[0016] The monitoring unit is used to monitor the lock holding status of the thread; the control unit is used to print the call stack of the first thread in response to monitoring that the first thread holds the lock and the second thread fails to apply for the lock.
[0017] In one embodiment, the control unit is configured to:
[0018] In response to the second thread reapplying for a lock and failing to apply for the lock, the first thread call stack is printed again.
[0019] In one embodiment, the control unit is configured to:
[0020] Before printing the first thread call stack again, determine whether the time interval meets the preset time interval threshold, and / or the number of times the first thread call stack has been printed is less than the printing number threshold, and the time interval is the time interval between the time when the current second thread fails to apply for the lock and the time when the first thread call stack was last printed.
[0021] In one embodiment, the thread control device further includes:
[0022] The recording unit is used to record and print the timestamp of the call stack of the first thread; the time interval is determined based on the timestamp and the time when the current second thread fails to apply for the lock.
[0023] In one embodiment, the control unit is configured to:
[0024] Before printing the call stack of the first thread, it is determined that the timeout parameter added in the synchronization function of each thread is monitored to represent a timeout.
[0025] In one embodiment, the second thread includes the same thread, or multiple different threads.
[0026] According to a third aspect of an embodiment of the present disclosure, there is provided a thread control device, comprising:
[0027] A processor; a memory for storing processor-executable instructions; wherein the processor is configured to execute the thread control method described in the first aspect or any one of the embodiments of the first aspect.
[0028] According to the fourth aspect of an embodiment of the present disclosure, a non-temporary computer-readable storage medium is provided. When the instructions in the storage medium are executed by the processor of the mobile terminal, the mobile terminal is enabled to execute the thread control method described in the first aspect or any one of the embodiments of the first aspect.
[0029] The technical solution provided by the embodiments of the present disclosure can achieve the following beneficial effects: monitoring the lock holding status of threads. If it is detected that the first thread holds the lock and the second thread fails to apply for the lock, the call stack of the first thread is printed, and the blocking point is quickly located based on the tasks recorded in the call stack of the first thread. Compared with the solution of waiting for the first thread to release the lock and then printing the timeout information, the call stack of the first thread can be obtained multiple times during the first thread's lock holding process, which improves the efficiency of locating the blocking point.
[0030] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0032] Figure 1 The figure is a schematic diagram showing an Android native solution according to an exemplary embodiment.
[0033] Figure 2 The figure is a flowchart of a thread control method according to an exemplary embodiment.
[0034] Figure 3 The figure is a schematic diagram showing a call stack of a print lock timeout according to an exemplary embodiment.
[0035] Figure 4 The figure is a flowchart of a thread control method according to an exemplary embodiment.
[0036] Figure 5 The figure is a block diagram of a thread control device according to an exemplary embodiment.
[0037] Figure 6 It is a block diagram of a device according to an exemplary embodiment. DETAILED DESCRIPTION
[0038] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all possible embodiments consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.
[0039] Figure 1 FIG is a schematic diagram of an Android native solution according to an exemplary embodiment. Figure 1 As shown, threads A, B, and C compete for the same lock. Thread B first acquires and holds the lock at time B1. Thread A applies for the lock at time A1, but fails to do so because thread B holds the lock. Therefore, thread A waits for thread B to release the lock. Thread C also applies for the lock at time C1, but fails to do so because thread B holds the lock. Therefore, thread C waits for thread B to release the lock. In the above process, time A1 can be later than or equal to time B1. Similarly, time C1 can be later than, earlier than, or equal to time A1 and / or B1. Thread B releases the lock at time B2, and threads A and C can apply for the lock again at any time within thread B's lock holding time. The time interval between times B1 and B2 is defined as thread B's lock holding time.
[0040] The process of thread A and thread C waiting for thread B to release the lock may cause the Android system to freeze or even ANR. In the related art, in order to determine the cause of the Android system freeze or even ANR problem, the relationship between the lock holding time of thread B and the set lock holding time threshold is judged. When the lock holding time of thread B exceeds the lock holding time threshold, the control thread B prints the timeout information after releasing the lock at time B2, that is, prints the log of thread B. However, the log does not record in detail all the task information processed by thread B between time B1 and time B2, so relevant personnel cannot locate the blockage point that causes the Android system to freeze or even ANR based on the log. It should be noted that the embodiment of the present disclosure uses thread A, thread B and thread C as an example to illustrate that multiple threads competing for the same lock will cause the Android system to freeze or even ANR, but it does not mean that the situation of competing for the lock only exists between three threads.
[0041] In summary, the native Android solution in the related art has the following technical problems:
[0042] 1. Native Android prints thread information only after the lock-holding thread releases the lock, but this does not reflect the status of the thread during the lock-holding period.
[0043] 2. Native Android cannot reflect the execution status during blocking through the call stack of the waiting thread.
[0044] In view of this, an embodiment of the present disclosure provides a thread control method. The thread control method monitors the lock holding status of each thread. For the convenience of description, the locked thread is represented by the first thread, and other threads competing with the first thread for the same lock are represented by the second thread. When it is detected that the first thread holds the lock and the second thread fails to apply for the lock, the first thread call stack is printed. Relevant personnel can locate the blockage point through the information of the first thread processing task recorded in the first thread call stack. The second thread can be the same thread or multiple different threads. For example, the first thread is thread B, and the second thread is thread A and / or thread C. The technical solution provided by the embodiment of the present disclosure is applicable to controlling two or more threads.
[0045] Figure 2 FIG. 1 is a flow chart showing a thread control method according to an exemplary embodiment. Figure 2 As shown, the thread control method includes the following steps.
[0046] In step S11 , the locking state of the thread is monitored.
[0047] In the disclosed embodiments, a thread's lock holding status includes both the thread holding the lock and the thread applying for the lock but failing. Based on monitoring each thread holding the lock and / or thread applying for the lock but failing, a determination is made as to whether to print the call stack of the lock-holding thread. This printing of the call stack of the lock-holding thread facilitates locating the blocking point.
[0048] In step S12, in response to monitoring that the first thread holds the lock and the second thread fails to apply for the lock, the call stack of the first thread is printed.
[0049] When it is detected that the first thread holds the lock, and the second thread fails to apply for the lock, the call stack of the first thread is printed for locating the blockage point. In the embodiment of the present disclosure, it is detected that the first thread holds the lock, and at the same time, it is detected that the second thread applies to hold the lock, but the second thread fails to apply for the lock because the first thread already holds the lock. At this time, the second thread waits for the first thread to release the lock, and reapplies for the lock according to the set time interval for reapplying the lock. In the above process, the first thread holds the lock for too long, that is, exceeds the set lock holding time threshold, which will cause the second thread to wait for too long, and then cause the Android system to freeze or even ANR. In order to allow R&D personnel to locate the cause of the Android system freeze or even ANR problem, a solution to the problem is further provided. Therefore, when it is detected that the first thread holds the lock, and the second thread fails to apply for the lock, the call stack of the first thread is printed, so that R&D personnel can find a solution to the problem by analyzing the tasks processed by the first thread during the lock holding period.
[0050] In one embodiment, Figure 3FIG. 1 is a schematic diagram of a call stack for printing lock timeout according to an exemplary embodiment. Figure 3 As shown, based on the relevant technology, it is monitored that thread A applies for a lock at time A1, but the lock is already held by thread B, resulting in thread A's lock application failure, and the call stack of thread B is printed. Thread A is further monitored to apply for a lock at time A2, but the lock is not released by thread B, which again results in thread A's lock application failure, and the call stack of thread B is printed again. Similarly, thread C is monitored to apply for a lock at time C1, but the lock is already held by thread B, resulting in thread C's lock application failure, and the call stack of thread B is printed. Thread C is further monitored to apply for a lock at time C2, but the lock is not released by thread B, which again results in thread C's lock application failure, and the call stack of thread B is printed again. Among them, A1, A2, B1, B2, C1 and C2 are different moments on the same timeline, the time interval between moments B1 and B2 is the lock holding time of thread B, moments A1, A2, C1 and C2 can be any moment of thread B from moment B1 to moment B2, and moment A1 can be equal to moment C1, and moment A2 can also be equal to moment C2.
[0051] In this implementation, if another thread (e.g., thread A and / or thread B) fails to request a lock while thread B is holding the lock, thread B's call stack is printed instead of simply entering a waiting state. For example, if thread A attempts to lock again after a certain interval from time A1 to time A2, and fails again, thread B's call stack is printed again. This facilitates obtaining information about the tasks processed by thread B between time A1 and time A2, providing a basis for personnel to locate the bottleneck.
[0052] In an embodiment of the present disclosure, when it is detected that the second thread applies for the lock again, and the first thread fails to release the lock, the first thread call stack is printed again to obtain a list of tasks performed by the first thread in the process of the second thread reapplying for the lock after a set time interval. Through the technical solution provided by the embodiment of the present disclosure, not only can the first thread call stack be printed when it is detected that the second thread applies for the lock but fails to apply for the lock, but the first thread fails to apply for the lock again when it is detected that the second thread reapplies for the lock, but fails to apply for the lock again because the first thread does not release the lock, the first thread call stack can continue to be printed. In the above two situations, the second thread does not directly enter the waiting state, so the efficiency of relevant personnel in locating blockage points can be improved.
[0053] In an embodiment of the present disclosure, before reprinting the first thread call stack, it is necessary to determine whether the time interval between the time when the current second thread failed to apply for a lock and the time when the first thread call stack was last printed meets a preset time interval threshold, and / or whether the number of times the first thread call stack has been printed meets a print count threshold. The value of the time interval between two prints of the first thread call stack can be set according to user needs as the time interval threshold. In one embodiment, the first thread call stack can be printed again if the time interval between the time when the second thread failed to apply for a lock and the time when the first thread call stack was last printed meets a preset time interval threshold. The first thread call stack can also be printed again if the number of times the first thread call stack has been printed is less than the print count threshold. The first thread call stack can also be printed again if the time interval between the time when the current first thread call stack is printed and the time when the first thread call stack was last printed meets a preset time interval threshold, and the number of times the first thread call stack has been printed is less than the print count threshold.
[0054] It should be noted that the time when the second thread currently fails to apply for a lock can be the time when the first thread's call stack is printed. That is, if the time interval between the time when the second thread fails to apply for a lock and the time when the first thread's call stack was last printed meets the time interval threshold, the first thread's call stack is printed at the time when the second thread currently fails to apply for a lock. In other words, the time when the second thread currently fails to apply for a lock is used as the time when the first thread's call stack is printed, and the time when the second thread currently fails to apply for a lock is used as the starting time for the next printing of the first thread's call stack.
[0055] Each time the first thread's call stack is printed, a timestamp is recorded. An interval is determined based on the timestamp of the last time the first thread's call stack was printed and the time when the second thread's lock application failed. If a second thread is detected reapplying for a lock and failing, the time of the last time the first thread's call stack was printed is obtained, and a determination is made as to whether the time interval between the second thread's current lock application failure and the last time the first thread's call stack was printed meets a preset time interval threshold. If the time interval between the second thread's current lock application failure and the last time the first thread's call stack was printed meets the time interval threshold, the first thread's call stack is printed; otherwise, the first thread's call stack is not printed. A predefined time interval threshold is set between two prints of the first thread's call stack. By determining whether the time interval between the time the first thread's call stack is about to be printed and the last time the first thread's call stack was printed meets the time interval threshold, resource waste caused by frequent printing of the first thread's call stack is avoided. In other words, if the first thread holds a lock, but multiple second threads simultaneously apply for the lock within a short period of time and fail, if a time interval threshold for printing the first thread's call stack is not set, the first thread's call stack will be printed as many times as the number of second threads. Frequent printing of the first thread's call stack within a short period of time may cause the first thread to hold the lock for a longer period of time. In order to avoid the defect of repeatedly printing the first thread call stack in a short period of time, before printing the first thread call stack again, the relationship between the time interval and the preset time interval threshold is determined. If it is determined that the time interval meets the preset time interval threshold, the first thread call stack is printed again until the second thread successfully applies for the lock.
[0056] In the disclosed embodiment, a print count threshold can also be set for the first thread call stack. If the number of prints on the first thread call stack is less than the print count threshold, the first thread call stack is printed again until the number of prints on the first thread call stack is greater than or equal to the print count threshold or the second thread successfully applies for a lock. This improves resource utilization.
[0057] In this embodiment, a timeout parameter is added to the synchronization function of each thread, so that the second thread exits the waiting state after waiting for a set time. During the monitoring process, if the timeout parameter added to the synchronization function of each thread indicates a timeout, the Android system prints the call stack of the first thread.
[0058] Figure 4 FIG. 1 is a flow chart showing a thread control method according to an exemplary embodiment. Figure 4 As shown, in one embodiment, the thread control method includes the following steps.
[0059] In step S21, a timeout parameter is added to the synchronization futex() function of each thread applying for a lock.
[0060] In step S22, if the return value of futex() is connection timeout ETIMEDOUT and does not exceed the maximum number of print times, the first thread is requested to print the call stack.
[0061] Determine the content of the futex() return value. If the return value of futex() is connection timeout ETIMEDOUT instead of EINTR or EAGAIN, print the call stack of the first thread.
[0062] In step S23, printing the first thread call stack requires holding the thread_list_lock lock, and releasing the thread_list_lock lock in time when the call stack printing is completed or an exception occurs.
[0063] In step S24, the first thread records the timestamp of the print call through the TLSDate data structure of the Thread object so as to compare it when printing the call stack next time. If the time interval is too close, the first thread call stack will not be printed this time.
[0064] In step S25 , to print the call stack of the first thread, it is necessary to first find the Thread object pointer of the first thread in the ThreadList of the application according to tid.
[0065] In step S26, to print the call stack of the first thread, it is necessary to first suspend the execution of the first thread through ScopedObjectAccess.
[0066] In step S27, the first thread call stack is printed through the DumpJavaStack() function of the first thread Thread object.
[0067] The thread control method of this embodiment monitors the second thread's lock application after a set interval. If it fails again, the method determines that the interval between the current lock application failure and the last time the first thread's call stack was printed meets the interval threshold, and then prints the first thread's call stack again. The method continues monitoring the lock holding status of each thread until the second thread successfully applies for the lock or the number of times the first thread's call stack is printed exceeds the print count threshold.
[0068] Based on the same concept, an embodiment of the present disclosure also provides a thread control device.
[0069] It is understandable that the thread control device provided by the embodiment of the present disclosure includes hardware structures and / or software modules corresponding to the execution of each function in order to realize the above functions. In combination with the units and algorithm steps of each example disclosed in the embodiment of the present disclosure, the embodiment of the present disclosure can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to realize the described functions for each specific application, but such implementation should not be considered to exceed the scope of the technical solution of the embodiment of the present disclosure.
[0070] Figure 5 FIG. 1 is a block diagram of a thread control device according to an exemplary embodiment. Figure 5 The thread control device 100 includes a monitoring unit 101 and a control unit 102 .
[0071] The monitoring unit 101 is used to monitor the lock holding status of the thread; the control unit 102 is used to print the call stack of the first thread in response to monitoring that the first thread holds the lock and the second thread fails to apply for the lock.
[0072] In one embodiment, the control unit 102 is configured to:
[0073] In response to the second thread reapplying for the lock and failing to apply for the lock, the first thread call stack is printed again.
[0074] In one embodiment, the control unit 102 is configured to:
[0075] Before printing the first thread call stack again, determine whether the time interval meets the preset time interval threshold, and / or the number of times the first thread call stack has been printed is less than the printing number threshold, and the time interval is the time interval between the time when the current second thread fails to apply for the lock and the time when the first thread call stack was last printed.
[0076] In one embodiment, the thread control device further includes:
[0077] The recording unit 103 is configured to record and print the timestamp of the call stack of the first thread; the time interval is determined based on the timestamp and the time when the current second thread fails to apply for a lock.
[0078] In one embodiment, the control unit 102 is configured to:
[0079] Before printing the call stack of the first thread, it is determined that the timeout parameter added in the synchronization function of each thread is monitored to represent a timeout.
[0080] In one embodiment, the second thread includes the same thread, or multiple different threads.
[0081] Regarding the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0082] Figure 6 FIG2 is a block diagram of an apparatus 200 for thread control according to an exemplary embodiment. For example, the apparatus 200 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0083] Reference Figure 6 , apparatus 200 may include one or more of the following components: a processing component 202 , a memory 204 , a power component 206 , a multimedia component 208 , an audio component 210 , an input / output (I / O) interface 212 , a sensor component 214 , and a communication component 216 .
[0084] The processing component 202 generally controls the overall operation of the device 200, such as operations associated with display, phone calls, data communications, camera operation, and recording operations. The processing component 202 may include one or more processors 220 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 202 may include one or more modules to facilitate interaction between the processing component 202 and other components. For example, the processing component 202 may include a multimedia module to facilitate interaction between the multimedia component 208 and the processing component 202.
[0085] The memory 204 is configured to store various types of data to support operations on the device 200. Examples of such data include instructions for any application or method operating on the device 200, contact data, phone book data, messages, pictures, videos, etc. The memory 204 can be implemented by any type of volatile or non-volatile storage device, or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk, or optical disk.
[0086] The power component 206 provides power to the various components of the device 200. The power component 206 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device 200.
[0087] The multimedia component 208 includes a screen that provides an output interface between the device 200 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, slides, and gestures on the touch panel. The touch sensor can not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 208 includes a front camera and / or a rear camera. When the device 200 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each front camera and rear camera can be a fixed optical lens system or have a focal length and optical zoom capability.
[0088] The audio component 210 is configured to output and / or input audio signals. For example, the audio component 210 includes a microphone (MIC) that is configured to receive external audio signals when the device 200 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may be further stored in the memory 204 or transmitted via the communication component 216. In some embodiments, the audio component 210 further includes a speaker for outputting audio signals.
[0089] I / O interface 212 provides an interface between processing component 202 and peripheral interface modules, such as a keyboard, click wheel, buttons, etc. These buttons may include but are not limited to: a home button, volume buttons, a start button, and a lock button.
[0090] The sensor assembly 214 includes one or more sensors for providing various aspects of the status assessment of the device 200. For example, the sensor assembly 214 can detect the open / closed state of the device 200, the relative positioning of components, such as the display and keypad of the device 200. The sensor assembly 214 can also detect changes in the position of the device 200 or a component of the device 200, the presence or absence of user contact with the device 200, the orientation or acceleration / deceleration of the device 200, and temperature changes of the device 200. The sensor assembly 214 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 214 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 214 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0091] The communication component 216 is configured to facilitate wired or wireless communication between the device 200 and other devices. The device 200 can access a wireless network based on a communication standard, such as WiFi, 4G or 5G, or a combination thereof. In an exemplary embodiment, the communication component 216 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 216 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0092] In an exemplary embodiment, the apparatus 200 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above-described method.
[0093] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as the memory 204 including instructions, which can be executed by the processor 220 of the apparatus 200 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0094] It is understood that in this disclosure, "plurality" refers to two or more than two, and other quantifiers are similar. "And / or" describes the association relationship of related objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects before and after are in an "or" relationship. The singular forms "a", "the" and "the" are also intended to include the plural forms, unless the context clearly indicates otherwise.
[0095] It will be further understood that the terms "first," "second," and the like are used to describe various types of information, but such information should not be limited to these terms. These terms are used solely to distinguish information of the same type from one another and do not indicate a particular order or level of importance. In fact, the terms "first," "second," and the like are fully interchangeable. For example, first information could be referred to as second information, and similarly, second information could be referred to as first information without departing from the scope of this disclosure.
[0096] It is further understood that, unless otherwise specified, “connection” includes a direct connection where there are no other components between the two elements, and also includes an indirect connection where there are other elements between the two elements.
[0097] It is further understood that although operations are described in a particular order in the drawings in the embodiments of the present disclosure, this should not be construed as requiring that the operations be performed in the particular order shown or in a serial order, or that all of the operations shown be performed to obtain the desired results. In certain circumstances, multitasking and parallel processing may be advantageous.
[0098] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered merely as exemplary, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0099] It should be understood that the present disclosure is not limited to the exact structures described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the scope of the appended claims.
Claims
1. A thread control method, characterized in that: include: Monitor the thread's lock status; In response to detecting that the first thread holds a lock and the second thread fails to apply for the lock, printing a call stack of the first thread, where the first thread call stack is used to locate a blocking point; The thread control method further includes: In response to the second thread reapplying for a lock and failing to apply for the lock, printing the first thread call stack again; Before printing the first thread call stack again, the thread control method further includes: Determine whether the time interval meets a preset time interval threshold, and / or the number of times the first thread call stack has been printed is less than the print count threshold, where the time interval is the time interval between the time when the current second thread fails to apply for the lock and the time when the first thread call stack was last printed.
2. The thread control method according to claim 1, characterized in that: The thread control method further includes: Record and print the timestamp of the first thread call stack; The time interval is determined based on the timestamp and the time when the current second thread fails to apply for the lock.
3. The thread control method according to any one of claims 1 to 2, characterized in that: Before printing the first thread call stack, the thread control method further includes: It is determined that the timeout parameter added to the synchronization function of each thread is monitored to represent the timeout.
4. The thread control method according to claim 1, wherein: The second thread includes the same thread, or multiple different threads.
5. A thread control device, characterized in that: include: Monitoring unit, used to monitor the lock status of the thread; A control unit, configured to, in response to detecting that the first thread holds a lock and the second thread fails to apply for the lock, print a call stack of the first thread, wherein the first thread call stack is used to locate a blocking point; In response to the second thread reapplying for the lock and failing to apply for the lock, the first thread call stack is printed again; before printing the first thread call stack again, it is determined that the time interval meets the preset time interval threshold, and / or the number of times the first thread call stack has been printed is less than the printing number threshold, and the time interval is the time interval between the current time when the second thread fails to apply for the lock and the time when the first thread call stack was last printed.
6. The thread control device according to claim 5, characterized in that: The thread control device also includes: A recording unit, configured to record and print the timestamp of the call stack of the first thread; The time interval is determined based on the timestamp and the time when the current second thread fails to apply for the lock.
7. The thread control device according to any one of claims 5 to 6, characterized in that: The control unit is used to: Before printing the call stack of the first thread, it is determined that the timeout parameter added in the synchronization function of each thread is monitored to represent a timeout.
8. The thread control device according to claim 7, characterized in that: The second thread includes the same thread, or multiple different threads.
9. A thread control device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to execute the thread control method according to any one of claims 1 to 4.
10. A storage medium, characterized in that: The storage medium stores instructions. When the instructions in the storage medium are executed by a processor of the mobile terminal, the mobile terminal is enabled to execute the thread control method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Application program lag detection method and device, medium and electronic equipment
CN111045926A
Database lock implementation method, device and equipment and readable storage medium
CN112231131A