A method, apparatus, device, storage medium and program product for thread processing

By acquiring thread information and optimizing thread names, abnormal threads can be identified and handled, solving the problem of difficult thread state determination and improving processing efficiency and resource utilization.

CN122309201APending Publication Date: 2026-06-30TENCENT TECHNOLOGY (SHENZHEN) CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
TENCENT TECHNOLOGY (SHENZHEN) CO LTD
Filing Date
2024-12-31
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

In existing technologies, it is difficult to determine the current state of a thread based solely on its name, which leads to the inability to handle abnormal threads in a timely manner, resulting in poor processing efficiency and an inability to improve resource utilization efficiency.

Method used

By acquiring thread information, we can determine the source information and detection results of the thread, identify and handle abnormal threads, including acquiring the thread creation time, stack information and thread type, optimizing the thread name using hook functions and bytecode modification techniques, merging threads into the target thread pool, and releasing idle core thread resources.

Benefits of technology

It improves the efficiency of thread processing and resource utilization, can handle abnormal threads in a timely manner, reduces thread creation overhead, and controls the number of threads.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122309201A_ABST
    Figure CN122309201A_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, device, storage medium, and program product for thread processing, improving processing efficiency and resource utilization efficiency. The method includes: acquiring thread information for each of a plurality of pending threads, wherein each pending thread is in a live state; determining source information for the corresponding pending thread based on the thread information of each pending thread, the source information indicating the thread creation status of the corresponding pending thread; determining a thread detection result for the corresponding pending thread based on the source information of each pending thread, the thread detection result indicating whether the corresponding pending thread is an abnormal thread; and processing the abnormal threads among the plurality of pending threads based on the thread detection result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, specifically to a method, apparatus, device, storage medium, and program product for thread processing. Background Technology

[0002] As the performance of mobile devices and other terminals continues to improve, applications are becoming increasingly complex, making thread management crucial for application performance and stability.

[0003] In existing thread management schemes, thread names are typically used to locate whether a thread has encountered an exception. However, the state and tasks of a thread may change as the application runs. Therefore, relying solely on the thread name makes it difficult to determine the current state of a thread, leading to delays in identifying thread exceptions, hindering rapid handling of abnormal threads, resulting in poor processing efficiency and hindering resource utilization. Summary of the Invention

[0004] This application provides a method, apparatus, device, storage medium, and program product for thread processing, which improves processing efficiency and resource utilization efficiency.

[0005] This application provides a method for thread processing. The method includes: acquiring thread information for each of a plurality of pending threads, wherein each pending thread is in a live state; determining source information for the corresponding pending thread based on the thread information of each pending thread, the source information indicating the thread creation status of the corresponding pending thread; determining a thread detection result for the corresponding pending thread based on the source information of each pending thread, the thread detection result indicating whether the corresponding pending thread is an abnormal thread; and processing the abnormal threads among the plurality of pending threads based on the thread detection result.

[0006] This application also provides a thread processing apparatus. The thread processing apparatus includes:

[0007] The acquisition unit is used to acquire thread information for each of the multiple pending threads, and the status of each pending thread is alive.

[0008] The determining unit is used to determine the source information of the corresponding thread to be processed based on the thread information of each thread to be processed. The source information is used to indicate the thread creation status of the corresponding thread to be processed.

[0009] The determining unit is used to determine the thread detection result of the corresponding thread based on the source information of each thread to be processed. The thread detection result is used to indicate whether the corresponding thread to be processed is an abnormal thread.

[0010] The processing unit is used to process abnormal threads among multiple pending threads based on thread detection results.

[0011] In one possible design, in another implementation of another aspect of the embodiments of this application, the thread information includes a thread identifier; the determining unit is specifically used for:

[0012] Based on the thread identifier of the first thread, obtain the thread creation time and thread stack information of the first thread. The first thread is one of multiple threads to be processed.

[0013] Based on the thread creation time and thread stack information of the first thread, the source information of the first thread is obtained.

[0014] In one possible design, in another implementation of another aspect of the embodiments of this application, the determining unit is specifically used for:

[0015] Based on the thread identifier of the first thread, the hook function is called to extract information from the thread creation interface of the first thread, and obtain the thread creation time and thread stack information of the first thread.

[0016] In one possible design, in another implementation of another aspect of the embodiments of this application, the determining unit is specifically used for:

[0017] The first detection result is determined based on the time difference between the thread creation time of the first thread and the application startup time. The first thread is used to execute the application.

[0018] Based on the thread stack information of the first thread, determine the thread type and code location of the first thread;

[0019] The second detection result is determined based on the comparison result between the thread type of the first thread and the preset thread type, or based on the comparison result between the code position of the first thread and the preset code position.

[0020] Based on the first and second detection results, the thread detection result of the first thread is obtained.

[0021] In one possible design, in another implementation of another aspect of the embodiments of this application, the thread information includes a thread identifier; the determining unit is specifically used for:

[0022] Based on the thread identifier of the second thread, obtain the creation code information and the thread name information of the second thread. The second thread is one of multiple threads to be processed.

[0023] The class name information of the class called by the second thread is determined based on the thread identifier of the second thread;

[0024] The initial class constructor is updated based on the creation code information to determine the target class constructor.

[0025] The target class constructor is called to process the thread name information of the second thread and the class name information of the class called by the second thread, so as to obtain the source information of the second thread.

[0026] In one possible design, in another implementation of another aspect of the embodiments of this application,

[0027] The acquisition unit is specifically used to, after acquiring the thread information of each of the multiple pending threads,

[0028] Obtain the first thread class information configured during compilation. The first thread class information is used to indicate the thread class being created.

[0029] The processing unit is also specifically used for:

[0030] Replace the first thread class information with the second thread class information to obtain the target thread class. The second thread class information is used to indicate the custom thread class.

[0031] In the target thread class, override the thread startup method, and based on the thread startup method, bind multiple threads to be processed to the target thread pool;

[0032] Run multiple pending threads in the target thread pool.

[0033] In one possible design, in another implementation of another aspect of the embodiments of this application, the processing unit is specifically further used for:

[0034] After obtaining the thread information of each of the multiple pending threads, the target core thread is determined from the multiple pending threads based on the running information of each pending thread.

[0035] If the target core thread is not running a task and has not received a task within a preset time period, the resources occupied by the target core thread are released based on the first information, which is used to indicate that the state of each core thread in the candidate thread pool is a releaseable state.

[0036] In one possible design, in another implementation of another aspect of the embodiments of this application, the processing unit is specifically further used for:

[0037] Before releasing the resources occupied by the target core thread based on the first information, the initial constructor of the candidate thread pool class is extracted during compilation. The initial constructor includes the initial call method of the constructor and the inherited object of the initial call method.

[0038] Replace the initial call method with a custom call method, and replace the inherited object of the initial call method with the inherited object of the custom call method, in order to obtain the target constructor of the candidate thread pool class;

[0039] The target constructor of the class based on the candidate thread pool configures initial information for each core thread.

[0040] In another aspect, this application provides a computer device including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the methods described above.

[0041] Another aspect of this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the methods described above.

[0042] Another aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the methods described above.

[0043] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:

[0044] In this embodiment, after obtaining the thread information of each of the multiple pending threads in a live state, the source information of the corresponding pending thread is determined based on the thread information of each pending thread. The source information indicates the thread creation status of the corresponding pending thread. Then, the thread detection result of the corresponding pending thread is determined based on the source information of each pending thread. The thread detection result indicates whether the corresponding pending thread is an abnormal thread. Therefore, based on the determined thread detection result, abnormal threads among the multiple pending threads can be processed. Through the above method, this application reflects the thread creation status through the source information of each pending thread, making it easier to identify thread-related code segments and logic, thereby enabling quick and efficient determination of whether a thread is abnormal, and timely handling of abnormal threads in abnormal situations. This not only improves processing efficiency but also improves resource utilization efficiency. Attached Figure Description

[0045] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0046] Figure 1A schematic diagram of an implementation environment for the thread processing method provided in this application is shown;

[0047] Figure 2 A flowchart illustrating the thread processing method provided in this application is shown.

[0048] Figure 3 A schematic diagram of the framework for obtaining threads to be processed provided in this application is shown;

[0049] Figure 4 A schematic diagram of the target thread tree structure provided in this application is shown;

[0050] Figure 5 This application provides a schematic diagram illustrating the number of reported threads.

[0051] Figure 6 This illustration shows a diagram of the reported thread details provided in this application;

[0052] Figure 7 An optional schematic diagram is shown illustrating how this application determines the source information of a thread;

[0053] Figure 8 Another optional schematic diagram is shown for determining the source information of the thread in this application;

[0054] Figure 9 A schematic diagram of another embodiment of the thread processing method provided in this application is shown;

[0055] Figure 10 A schematic diagram of another embodiment of the thread processing method provided in this application is shown;

[0056] Figure 11 A schematic diagram of the thread processing apparatus provided in this application is shown;

[0057] Figure 12 A schematic diagram of the computer device provided in this application is shown. Detailed Implementation

[0058] This application provides a method, apparatus, device, storage medium, and program product for thread processing, which improves processing efficiency and resource utilization efficiency.

[0059] It is understood that in the specific implementation of this application, data such as user information are involved. When the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0060] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0061] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that implementations of the application described herein can be implemented, for example, in sequences other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0062] In computer science, threads are a fundamental yet crucial type of program that allows a program to execute multiple tasks concurrently within a single execution process. As the performance of mobile devices and other terminals continues to improve, applications are becoming increasingly complex. Thread management is vital for the performance and stability of applications. For example, by rationally allocating threads and execution time, resource idleness can be avoided, thereby improving overall performance. Furthermore, thread management needs to handle various exceptional situations, such as thread crashes and infinite loops, preventing abnormal threads from threatening the stability and security of the program.

[0063] In existing solutions, thread names are typically used to locate whether a thread has encountered an exception. For example, thread names such as Thread-991(main), Thread-990(main), Thread-973(main), and Thread-955(main) are used to determine if an exception exists. However, the state and tasks of a thread may change as the application runs. Therefore, relying solely on the thread name makes it difficult to determine the current state of a thread, leading to delays in identifying and handling exceptions, poor processing efficiency, and a failure to improve resource utilization.

[0064] Therefore, to address the aforementioned technical problems, this application provides a thread processing method. This thread processing method can be applied to various thread management and optimization scenarios. For example, applicable scenarios include, but are not limited to, I / O-intensive task scenarios, graphical user interface (GUI) applications, asynchronous programming, parallel computing, server-side programs, e-commerce projects, and background task processing; no specific limitations are imposed in this application.

[0065] For example, the thread processing method provided in this application can be applied to Figure 1 The implementation environment shown. Figure 1 As shown, this implementation environment includes at least a terminal and a server. The terminal and server can communicate via a communication network. This communication network uses standard communication technologies and / or protocols, typically the Internet, but can also be any network, including but not limited to Bluetooth, a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), mobile, private networks, or any combination of virtual private networks. In some embodiments, customized or dedicated data communication technologies may be used to replace or supplement the aforementioned data communication technologies.

[0066] The terminals involved in this application include, but are not limited to, mobile phones, tablets, laptops, desktop computers, smart voice interaction devices, smart home appliances, vehicle terminals, aircraft, and wearable devices. The client is deployed on the terminal and can run on the terminal via a browser or as a standalone application (APP).

[0067] The server involved in this application can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence (AI) platforms.

[0068] In combination with the above Figure 1In the implementation environment shown, in step A1, the object obtains multiple threads to be processed through the terminal and sends the thread information of these multiple threads to the server. In step A2, the server determines the source information of the corresponding thread based on the thread information of each thread to be processed. It should be noted that the source information is used to indicate the thread creation status of the corresponding thread to be processed. In step A3, the server determines the thread detection result of the corresponding thread to be processed based on the source information of each thread to be processed. The thread detection result is used to indicate whether the corresponding thread to be processed is an abnormal thread. In step A4, the server further processes the abnormal threads among the multiple threads to be processed based on the thread detection result.

[0069] In other examples, such as step A5, the terminal can also send thread information, such as thread details and thread count, to the server. The server can then perform analysis based on the thread details and thread count.

[0070] Based on the above introduction, the thread handling method in this application will be described below. Figure 2 A flowchart illustrating the thread processing method provided in this application is shown. Figure 2 As shown, the thread processing method of this application includes at least the following steps:

[0071] 201. The terminal obtains multiple pending threads, and the status of each pending thread is alive.

[0072] In one or more embodiments, when it is necessary to manage and optimize individual threads, multiple threads can be acquired first. For example, after acquiring multiple threads, the terminal can send the thread information of each thread to the server. Thus, the server can obtain the thread information of each thread.

[0073] As an illustrative example, regarding how the terminal obtains these multiple pending threads, please refer to... Figure 3 Use the illustrated framework diagram to understand it. Figure 3 As shown, firstly, the current thread is obtained. After obtaining the current thread, its thread group is determined based on its thread identifier. This thread group contains multiple threads, each uniquely identified by its thread identifier. Further, after determining the current thread group, the root thread group is determined level by level based on the thread group identifier, thus obtaining the target thread tree structure. This target thread tree structure includes multiple sub-thread groups. Therefore, by traversing these sub-thread groups, multiple threads to be processed can be obtained.

[0074] For example, Figure 4 A schematic diagram of the target thread tree structure provided in this application is shown. Figure 4 As shown, taking thread 1 as an example, its thread group can be identified as thread group A11 by its thread identifier. Then, using the identifier of thread group A11, its parent thread group B11 is determined level by level upwards. This process continues until the root thread group is found. Thus, within the determined target thread tree structure, all related thread groups (i.e., child thread groups), including the current thread, can be identified, such as thread group A11, parent thread group B11, parent thread group C11, and the root thread group. In this way, by dynamically expanding the array, the threads in thread group A11, parent thread group B11, parent thread group C11, and the root thread group can be counted.

[0075] Furthermore, after identifying the threads in each sub-thread group, a liveness check is performed on each thread within that group. For example, the liveness attribute value of each thread can be checked; if the liveness attribute value is "alive," then the corresponding thread is considered alive. This allows for the identification of multiple threads awaiting processing. In other words, each of these multiple threads awaiting processing is considered alive.

[0076] In other examples, combined Figure 3 After counting the number of threads in each sub-thread group, the thread data from all sub-thread groups can be summed to obtain the total number of threads. Then, by checking if the total number of threads exceeds a preset threshold, an alert mechanism is triggered if the total number of threads exceeds the preset threshold, sending the thread count information and thread details to the server. For example, Figure 5 This illustration shows a diagram illustrating the reported thread count information provided in this application. For example... Figure 5 As shown, threads running version "4.126.29265" at different times can be reported to the server. For example, thread 1 can be reported at time "yyyy-mm-01 14:00", thread 2 can be reported at time "yyyy-mm-01 13:00", and so on.

[0077] Or perhaps, Figure 6 This diagram illustrates the reporting thread details provided in this application. For example... Figure 6 As shown, combined with Figure 5The thread count information can be used to report the thread details of thread 1 (version 4.126.29265) reported at the time of "yyyy-mm-01 14:00" to the server. For example, the thread details include "...WM.task-4#apm_androidex / work / Configuration$1-76(main);...".

[0078] In other examples, after iterating through each pending thread, the thread information of each pending thread can be encapsulated into a ThreadInfo object to enable state management of the relevant pending threads.

[0079] 202. The terminal sends thread information of each of the multiple pending threads to the server.

[0080] In one or more embodiments, after obtaining the plurality of threads to be processed in step 201, the terminal can send the thread information of each of these threads to the server. Thus, the server can receive the thread information of each thread to be processed. It should be noted that the described thread information may include the thread identifier, thread execution information, etc.

[0081] 203. The server determines the source information of the corresponding pending thread based on the thread information of each pending thread. The source information is used to indicate the thread creation status of the corresponding pending thread.

[0082] In one or more embodiments, since it is not possible to effectively locate abnormal threads based solely on thread names, while the source of a thread can reflect its creation process, this application's server, after obtaining the thread information of each thread to be processed, can determine the source information of the corresponding thread based on that information. For example, the source information of thread 1 can be determined based on its thread information, reflecting the thread creation status of thread 1. Similarly, the source information of thread 2 can be determined based on its thread information, reflecting the thread creation status of thread 2.

[0083] In some optional embodiments, regarding step 203, determining the source information of the thread to be processed based on its thread information can be done not only from the perspective of stack information and creation time, but also from the perspective of optimizing the thread name. Specifically, this can be understood as follows:

[0084] Method (1) Obtaining information through creation timing and stack information

[0085] For example, the thread information for each thread to be processed includes a thread identifier corresponding to the thread to be processed. This thread identifier can uniquely identify the thread to be processed. For example, the thread identifier includes, but is not limited to, a thread ID.

[0086] Since the processing of each pending thread is basically similar, this application will only use any one pending thread (e.g., the first thread) as an example for illustration. Figure 7 An optional schematic diagram illustrating how this application determines the source information of a thread is shown. For example... Figure 7 As shown, the thread information of the first thread includes the thread identifier of the first thread.

[0087] Combination Figure 7 As shown, the server can obtain the thread creation time and thread stack information of the first thread based on its thread identifier. As an illustrative example, the server can use the first thread's thread identifier to call a hook function to extract information from the first thread's thread creation interface, thus obtaining the thread creation time and thread stack information. For example, the hook function could be a `hook` function, and the first thread's thread creation interface could be the native layer's `pthread_create` interface.

[0088] In this way, after obtaining the thread creation time and thread stack information of the first thread, the source information of the first thread can be obtained based on the thread creation time and thread stack information. For example, the thread creation time and thread stack information of the first thread can be directly used as the source information of the first thread.

[0089] It should be noted that the above explanation uses only one pending thread (i.e., the first thread) as an example. The process of determining the source information for other pending threads can be understood by referring to the process of processing the source information of the first thread, and is not limited in this application.

[0090] Method (2) Optimize thread name

[0091] For example, since the processing of each thread to be processed is basically similar, this application will only use any one thread to be processed (e.g., the second thread) as an example for illustration. Figure 8 Another optional schematic diagram is shown for determining the source information of the thread in this application.

[0092] like Figure 8 As shown, the thread information of the second thread includes its thread identifier. After obtaining the thread identifier of the second thread, the server can obtain the creation code information and the thread name information of the second thread based on the thread identifier.

[0093] In this way, the server determines the class name information of the class called by the second thread based on the thread identifier of the second thread. As an illustrative description, the server can view the stack information of the second thread based on the thread identifier of the second thread, and determine the location of the code currently being executed by the second thread through the stack information, thereby determining the class called by the second thread, and thus obtaining the class name information of the class called by the second thread.

[0094] Furthermore, the server also needs to update the initial class constructor based on the creation code information to determine the target class constructor. For example, if the initial class constructor is the `Thread()` function, the `Thread()` function can be updated using the creation code information to obtain the target class constructor, such as the `new Thread()` function.

[0095] In this way, the server obtains the source information of the second thread by calling the target class constructor and processing the thread name information and the class name information of the class called by the second thread. For example, the source information of the second thread can be represented as new Thread(“class name / threadName”), where classname represents the class name information of the class called by the second thread, and threadName represents the thread name information of the second thread.

[0096] In other words, by using the bytecode modification technique described above, all code and code in third-party libraries are scanned during compilation, and then a specified interface (i.e., the target class constructor mentioned above) is constructed based on the thread creation code information. In this way, through the target class constructor, the class name of the currently called class can be appended to the thread name according to different scenarios, which can more intuitively reflect the source of the thread.

[0097] It should be noted that the first thread mentioned above may be the same as or different from the second thread; this application does not impose any limitations on this. In practical applications, other methods for determining the source information of the thread may also be included; this application does not impose any specific limitations on these methods either.

[0098] 204. The server determines the thread detection result of the corresponding thread based on the source information of each thread to be processed. The thread detection result is used to indicate whether the corresponding thread to be processed is an abnormal thread.

[0099] In one or more embodiments, after determining the source information of each thread to be processed, the server can also determine the thread detection result of the corresponding thread based on the source information of each thread to be processed. For example, the thread detection result of thread 1 is determined based on the source information of thread 1, so as to indicate whether thread 1 is an abnormal thread. Similarly, the thread detection result of thread 2 is determined based on the source information of thread 2, so as to indicate whether thread 2 is an abnormal thread.

[0100] In some alternative embodiments, the server's determination of the thread detection result based on the source information determined in the aforementioned manner (1) can be understood in the following manner:

[0101] The server determines the first detection result based on the time difference between the thread creation time of the first thread and the application startup time. It should be noted that the first thread is used to execute the application. For example, if the time difference is greater than a certain time threshold, the first detection result is that the first thread is an abnormal thread. Conversely, if the time difference is less than or equal to a certain time threshold, the first detection result is that the first thread is not an abnormal thread.

[0102] In addition, the server needs to determine the thread type and code location of the first thread based on its thread stack information. Then, the server determines the second detection result based on a comparison between the first thread's thread type and a preset thread type, or a comparison between the first thread's code location and a preset code location. For example, if the first thread's thread type or code location does not match the preset thread type, the second detection result can be determined as the first thread being an abnormal thread. Conversely, if the first thread's thread type matches the preset thread type, and its code location matches the preset code location, the second detection result can be determined as the first thread not being an abnormal thread.

[0103] In this way, after determining the first detection result and the second detection result, the server obtains the thread detection result of the first thread based on the first detection result and the second detection result.

[0104] For example, if both the first and second detection results indicate that the first thread is not an abnormal thread, then the thread detection result for the first thread will also be "not an abnormal thread". Conversely, if either the first or second detection result indicates that the first thread is an abnormal thread, then the thread detection result for the first thread will also be "abnormal thread".

[0105] It should be noted that the process of determining the thread detection results of other pending threads can be understood by referring to the process of determining the thread detection results of the first thread, and will not be elaborated upon in this application.

[0106] In some alternative embodiments, based on the source information described in method (2) above, this application can also search the code library for code segments that create threads or submit tasks to the thread pool, based on the thread name information of the second thread and the class name information of the called class, and then locate the task information of the task executed by the second thread through the code segment. For example, the task information includes, but is not limited to, the specific logic of the task, input parameters, etc. In this way, the server then searches for exception handling code in the task information to determine the thread detection result of the second code.

[0107] It should be noted that the process of determining the thread detection results of other pending threads can be understood by referring to the process of the thread detection results of the second thread, and will not be elaborated in this application.

[0108] 205. The server processes abnormal threads among multiple pending threads based on thread detection results.

[0109] In one or more embodiments, after determining the thread detection result of each pending thread, the server can handle abnormal threads among these multiple pending threads based on the thread detection results. For example, the handling methods include, but are not limited to: ① recording the exception information, thread name, etc., in the error log for subsequent analysis and processing; ② determining whether to terminate or restart the abnormal thread based on the nature and severity of the thread exception; ③ analyzing the cause of the abnormal thread's occurrence to determine the handling strategy based on the cause, such as modifying code, optimizing system configuration, or updating dependent libraries, etc., which are not specifically limited in this application.

[0110] By using the above method, this application reflects the thread creation status through the source information of each pending thread, making it easier to identify thread-related code segments and logic. This allows for quick and efficient determination of whether a thread is experiencing anomalies based on the source information, enabling timely handling of abnormal threads in case of exceptions. This not only improves processing efficiency but also enhances resource utilization.

[0111] In some alternative embodiments, in the above... Figure 2 Based on the described embodiments, Figure 9 A schematic diagram of another embodiment of the thread processing method provided in this application is shown. For example... Figure 9As shown, after obtaining the thread information of each of the multiple pending threads, the server can also obtain the first thread class information configured during compilation. This first thread class information indicates the created thread class. The server then replaces the first thread class information with second thread class information to obtain the target thread class. This second thread class information indicates the custom thread class. In other words, the target thread class can be understood as a custom thread class.

[0112] In this way, the server overrides the thread startup method in the target thread class. For example, the thread startup method could be the `start()` method. After calling this thread startup method, the server can bind multiple pending threads to the target thread pool based on the thread startup method. Thus, the server can run these multiple pending threads in the target thread pool, thereby realizing the execution of tasks according to each pending thread within the target thread pool.

[0113] By merging these multiple pending threads into a unified target thread pool for execution in the above manner, thread utilization can be effectively improved, the number of threads created each time can be reduced, and the number of threads running at the same time can also be effectively controlled.

[0114] In some alternative embodiments, for cases where the core threads in thread pools with a large number of other business functions in the code are constantly resident, the total number of threads in all thread pools may increase the minimum number of threads required to run the application.

[0115] Therefore, in the above Figure 2 Based on the described embodiments, this application can also configure first information for each core thread in the candidate thread pool via code. This first information can indicate that the state of each core thread in the candidate thread pool is a releaseable state.

[0116] In this way, after obtaining the thread information of each of the multiple pending threads, the server first determines the target core thread from the multiple pending threads based on the running information of each pending thread.

[0117] Furthermore, after identifying the target core thread, the server can determine whether the target core thread is idle. In other words, if the server determines that the target core thread is not running a task and has not received a task within a preset time period, it will release the resources occupied by the target core thread based on the first piece of information.

[0118] As an illustrative example, before releasing the resources occupied by the target core thread based on the first information, the server can first configure the first information, as shown in the following example. Figure 10The diagram shown is for reference. Since various thread pools exist within the code, and similar thread pools exist in third-party libraries, a unified approach is needed: configuring the initial information through compile-time modifications.

[0119] like Figure 10 As shown, during the configuration process, the initial constructor of the candidate thread pool class can be extracted during compilation. The initial constructor includes the initial call method of the constructor and the object that inherits from the initial call method. For example, the initial call method could be `new ThreadPoolExecutor()`, and the object that inherits from the initial call method could be `ThreadPoolExecutor`.

[0120] After extracting the initial constructor, the initial call method in that constructor is replaced with a custom call method. Similarly, the inherited object of the initial call method is replaced with the inherited object of the custom call method. This yields the target constructor of the candidate thread pool class. For example, the custom call method could be `newShadowThreadPoolExecutor()`, and the inherited object of the custom call method could be `ShadowThreadPoolExecutor`.

[0121] In this way, the server then configures the initial information for each core thread based on the target constructor of the candidate thread pool class. For example, it sets allowCoreThreadTimeOut to true for each core thread in the target constructor.

[0122] It should be noted that the candidate thread pools mentioned above can be various thread pools existing in the code, or thread pools existing in the code of third-party libraries. This application does not make any specific restrictions.

[0123] By overriding the constructor as described above, a release configuration can be added to the core thread. This allows for the timely and effective release of resources held by the core thread when it has no tasks and a timeout occurs, reducing the number of resident threads and preventing threads from remaining resident in the inactive thread pool.

[0124] The foregoing primarily describes the solutions provided by the embodiments of this application from a methodological perspective. It is understood that to achieve the above functions, corresponding hardware structures and / or software modules are included to execute each function. Those skilled in the art should readily recognize that, based on the modules and algorithm steps described in conjunction with the embodiments disclosed in this application, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by 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 implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0125] The thread processing device in this application is described in detail below. Please refer to [link / reference]. Figure 11 , Figure 11 A schematic diagram of the thread processing apparatus provided in this application is shown. Figure 11 As shown, the thread processing device includes:

[0126] The acquisition unit 1101 is used to acquire the thread information of each of the multiple pending threads, and the status of each pending thread is alive.

[0127] The determining unit 1102 is used to determine the source information of the corresponding thread to be processed based on the thread information of each thread to be processed. The source information is used to indicate the thread creation status of the corresponding thread to be processed.

[0128] The determining unit 1102 is used to determine the thread detection result of the corresponding thread based on the source information of each thread to be processed. The thread detection result is used to indicate whether the corresponding thread to be processed is an abnormal thread.

[0129] The processing unit 1103 is used to process abnormal threads among multiple threads to be processed based on the thread detection results.

[0130] Optionally, in the above Figure 11 Based on one or more corresponding embodiments, in another embodiment of the thread processing apparatus provided in this application, the thread information includes a thread identifier. The determining unit 1102 is specifically used for:

[0131] Based on the thread identifier of the first thread, obtain the thread creation time and thread stack information of the first thread. The first thread is one of multiple threads to be processed.

[0132] Based on the thread creation time and thread stack information of the first thread, the source information of the first thread is obtained.

[0133] Optionally, in the above Figure 11Based on one or more corresponding embodiments, in another embodiment of the thread processing apparatus provided in this application, the determining unit 1102 is specifically used for:

[0134] Based on the thread identifier of the first thread, the hook function is called to extract information from the thread creation interface of the first thread, and obtain the thread creation time and thread stack information of the first thread.

[0135] Optionally, in the above Figure 11 Based on one or more corresponding embodiments, in another embodiment of the thread processing apparatus provided in this application, the determining unit 1102 is specifically used for:

[0136] The first detection result is determined based on the time difference between the thread creation time of the first thread and the application startup time. The first thread is used to execute the application.

[0137] Based on the thread stack information of the first thread, determine the thread type and code location of the first thread;

[0138] The second detection result is determined based on the comparison result between the thread type of the first thread and the preset thread type, or based on the comparison result between the code position of the first thread and the preset code position.

[0139] Based on the first and second detection results, the thread detection result of the first thread is obtained.

[0140] Optionally, in the above Figure 11 Based on one or more corresponding embodiments, in another embodiment of the thread processing apparatus provided in this application, the thread information includes a thread identifier. The determining unit 1102 is specifically used for:

[0141] Based on the thread identifier of the second thread, obtain the creation code information and the thread name information of the second thread. The second thread is one of multiple threads to be processed.

[0142] The class name information of the class called by the second thread is determined based on the thread identifier of the second thread;

[0143] The initial class constructor is updated based on the creation code information to determine the target class constructor.

[0144] The target class constructor is called to process the thread name information of the second thread and the class name information of the class called by the second thread, so as to obtain the source information of the second thread.

[0145] Optionally, in the above Figure 11 Based on one or more corresponding embodiments, in another embodiment of the thread processing apparatus provided in this application,

[0146] The acquisition unit 1101 is further used to acquire the first thread class information configured during compilation after acquiring the thread information of each of the multiple threads to be processed. The first thread class information is used to indicate the thread class created.

[0147] Processing unit 1103 is also specifically used for:

[0148] Replace the first thread class information with the second thread class information to obtain the target thread class. The second thread class information is used to indicate the custom thread class.

[0149] In the target thread class, override the thread startup method, and based on the thread startup method, bind multiple threads to be processed to the target thread pool;

[0150] Run multiple pending threads in the target thread pool.

[0151] Optionally, in the above Figure 11 Based on one or more corresponding embodiments, in another embodiment of the thread processing device provided in this application, the processing unit 1103 is further used for:

[0152] After obtaining the thread information of each of the multiple pending threads, the target core thread is determined from the multiple pending threads based on the running information of each pending thread.

[0153] If the target core thread is not running a task and has not received a task within a preset time period, the resources occupied by the target core thread are released based on the first information, which is used to indicate that the state of each core thread in the candidate thread pool is a releaseable state.

[0154] Optionally, in the above Figure 11 Based on one or more corresponding embodiments, in another embodiment of the thread processing device provided in this application, the processing unit 1103 is further used for:

[0155] Before releasing the resources occupied by the target core thread based on the first information, the initial constructor of the candidate thread pool class is extracted during compilation. The initial constructor includes the initial call method of the constructor and the inherited object of the initial call method.

[0156] Replace the initial call method with a custom call method, and replace the inherited object of the initial call method with the inherited object of the custom call method, in order to obtain the target constructor of the candidate thread pool class;

[0157] The target constructor of the class based on the candidate thread pool configures initial information for each core thread.

[0158] The thread processing device in the embodiments of this application has been described above from the perspective of modular functional entities. The computer device in the embodiments of this application is described below from the perspective of hardware processing.

[0159] Figure 12 A schematic diagram of the computer device provided in this application is shown. This computer device can vary considerably due to differences in configuration or performance, and may include, but is not limited to, the aforementioned... Figure 11 The described thread processing device, etc. For example... Figure 12 As shown, the computer device may include one or more central processing units (CPUs) 1222 (e.g., one or more processors) and a memory 1232, and one or more storage media 1230 (e.g., one or more mass storage devices) for storing application programs 1242 or data 1244. The memory 1232 and storage media 1230 may be temporary or persistent storage. The program stored in the storage media 1230 may include one or more modules (not shown in the figure), each module including a series of instruction operations on the computer device. Furthermore, the CPU 1222 may be configured to communicate with the storage media 1230 and execute the series of instruction operations in the storage media 1230 on the computer device. Exemplarily, the CPU 1222 is used to execute the application program 1242 stored in the storage media 1230, thereby implementing the thread processing method provided in the above embodiments of this application.

[0160] The computer device may also include one or more power supplies 1226, one or more wired or wireless network interfaces 1250, one or more input / output interfaces 1258, and / or one or more operating systems 1241, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.

[0161] For example, Figure 12 The central processing unit 1222 can call computer execution instructions stored in memory 1232 to cause the computer device to perform actions such as... Figures 2 to 10 The method in the corresponding method embodiment.

[0162] Specifically, Figure 11 The functions / implementation processes of the determining unit 1102 and the processing unit 1103 can be achieved through... Figure 12 The central processing unit 1222 in the memory calls the computer execution instructions stored in the memory 1232 to achieve this. Figure 11 The function / implementation process of the acquisition unit 101 can be achieved through... Figure 12It is implemented using the input / output interface 1258.

[0163] The steps performed by the computer device in the above embodiments can be based on this Figure 12 The computer device structure shown.

[0164] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the methods described in the foregoing embodiments.

[0165] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the methods described in the foregoing embodiments.

[0166] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0167] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.

[0168] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated units described above can be implemented in hardware or as software functional units.

[0169] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a server or terminal device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing computer programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0170] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A method for thread processing, characterized in that, include: Obtain the thread information of each of the multiple pending threads, and the state of each pending thread is alive; Based on the thread information of each thread to be processed, the source information of the corresponding thread to be processed is determined, and the source information is used to indicate the thread creation status of the corresponding thread to be processed; Based on the source information of each thread to be processed, a thread detection result is determined for the corresponding thread to be processed. The thread detection result is used to indicate whether the corresponding thread to be processed is an abnormal thread. Based on the thread detection results, abnormal threads among the multiple threads to be processed are handled.

2. The method according to claim 1, characterized in that, The thread information includes a thread identifier; Determining the source information of each thread to be processed based on its thread information includes: Based on the thread identifier of the first thread, the thread creation time and thread stack information of the first thread are obtained, wherein the first thread is one of the plurality of threads to be processed; Based on the thread creation time and thread stack information of the first thread, the source information of the first thread is obtained.

3. The method according to claim 2, characterized in that, Based on the thread identifier of the first thread, obtain the thread creation time and thread stack information of the first thread, including: Based on the thread identifier of the first thread, the hook function is called to extract information from the thread creation interface of the first thread, and the thread creation time and thread stack information of the first thread are obtained.

4. The method according to any one of claims 2 to 3, characterized in that, Determining the thread detection result corresponding to each thread to be processed based on the source information of each thread to be processed includes: Based on the time difference between the thread creation time of the first thread and the startup time of the application, a first detection result is determined, wherein the first thread is used to execute the application; Based on the thread stack information of the first thread, the thread type and code location of the first thread are determined. The second detection result is determined based on the comparison result between the thread type of the first thread and the preset thread type, or based on the comparison result between the code position of the first thread and the preset code position. Based on the first detection result and the second detection result, the thread detection result of the first thread is obtained.

5. The method according to claim 1, characterized in that, The thread information includes a thread identifier; Determining the source information of each thread to be processed based on its thread information includes: Based on the thread identifier of the second thread, the creation code information and thread name information of the second thread are obtained, and the second thread is one of the multiple threads to be processed; The class name information of the class called by the second thread is determined based on the thread identifier of the second thread; The initial class constructor is updated based on the creation code information to determine the target class constructor; The constructor of the target class is invoked to process the thread name information of the second thread and the class name information of the class called by the second thread, so as to obtain the source information of the second thread.

6. The method according to claim 1, characterized in that, After obtaining the thread information of each of the multiple pending threads, the process further includes: Obtain the first thread class information configured during compilation, which is used to indicate the thread class being created; The first thread class information is replaced with the second thread class information to obtain the target thread class, where the second thread class information is used to indicate the custom thread class; In the target thread class, override the thread startup method, and based on the thread startup method, bind multiple threads to be processed to the target thread pool; Multiple threads to be processed are run in the target thread pool.

7. The method according to claim 1, characterized in that, After obtaining the thread information of each of the multiple pending threads, the method further includes: Based on the running information of each of the threads to be processed, the target core thread is determined from the plurality of threads to be processed; When the target core thread is not running a task and has not received the task within a preset time period, the resources occupied by the target core thread are released based on the first information, which is used to indicate that the state of each core thread in the candidate thread pool is a releaseable state.

8. The method according to claim 7, characterized in that, Before releasing the resources occupied by the target core thread based on the first information, the method further includes: During compilation, the initial constructor of the candidate thread pool class is extracted, the initial constructor including the initial call method of the constructor and the inherited object of the initial call method; The initial invocation method is replaced with a custom invocation method, and the inherited object of the initial invocation method is replaced with the inherited object of the custom invocation method, so as to obtain the target constructor of the candidate thread pool class; Based on the target constructor of the candidate thread pool class, configure the first information for each core thread.

9. A thread processing device, characterized in that, include: The acquisition unit is used to acquire thread information of each of the multiple pending threads, wherein the state of each pending thread is a live state; The determining unit is configured to determine the source information corresponding to the thread to be processed based on the thread information of each thread to be processed, wherein the source information is used to indicate the thread creation status of the thread to be processed. The determining unit is used to determine the thread detection result corresponding to the thread to be processed based on the source information of each thread to be processed, and the thread detection result is used to indicate whether the corresponding thread to be processed is an abnormal thread; The processing unit is used to process abnormal threads among the multiple threads to be processed based on the thread detection results.

10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the thread processing method according to any one of claims 1 to 8.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the thread processing method according to any one of claims 1 to 8.

12. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the steps of the thread processing method according to any one of claims 1 to 8.