Thread information acquisition method and device, electronic equipment and program product
By dynamically replacing class files in JVM, asynchronous threads can non-invasively obtain thread information of the parent thread, solving the problem of high code maintenance costs, and achieving efficient asynchronous thread information transfer and stability improvement of distributed systems.
Patent Information
- Application Number
- CN202411929397.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-04-01
AI Technical Summary
When using the link tracing framework to track the call information of data processing requests, the source code needs to be modified so that the asynchronous thread obtains the thread information of the parent thread, resulting in high code maintenance costs.
By adding the object code file to the preset code project and configuring specific JVM parameter information to dynamically replace the class file when the JVM starts, asynchronous threads can non-invasively obtain thread information of the parent thread.
It reduces the cost of code maintenance, realizes dynamic and non-invasive asynchronous thread information transfer, enhances the tracking ability of asynchronous threads, helps developers trace cross-service request links, locates and diagnoses delays and failures, and improves the stability of distributed systems.
Smart Images

Figure CN119739421A_ABST
Abstract
Description
Technical Field
[0001] The present application is applied to the field of financial technology, and specifically, relates to a method, device, electronic device and program product for obtaining thread information. Background Art
[0002] In modern distributed applications, business logic is decomposed into multiple microservices. In a system composed of multiple services such as microservices, a request is processed across multiple services, which makes it difficult to trace the entire request processing process. When failures and request delays are exacerbated by reduced traceability, it also makes it more difficult to locate the problematic service. The distributed tracing system can help developers collect, store and analyze requests across multiple services, and visually display the tracing links of cross-service requests to help developers debug and optimize performance issues. At the same time, there are also some problems. During the asynchronous execution process, the asynchronous thread will lose the Traceid of the parent thread, making it impossible to aggregate the Span id of the asynchronous thread into the Traceid of the parent thread, resulting in the inability to effectively obtain the request information of the asynchronous thread.
[0003] When a link tracking framework is used in related technologies to track the call information of data processing requests, the source code needs to be modified so that the asynchronous thread obtains the thread information of the parent thread, resulting in high code maintenance costs. No effective solution has been proposed yet. Summary of the invention
[0004] The main purpose of the present application is to provide a method, device, electronic device and program product for obtaining thread information, so as to solve the problem in the related technology that when a link tracking framework is used to track the call information of a data processing request, the source code needs to be modified so that the asynchronous thread obtains the thread information of the parent thread, resulting in high code maintenance costs.
[0005] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a method for obtaining thread information is provided, the method comprising: adding a target code file to a preset code project, wherein the target code file is used to obtain thread information of a target thread, and the target thread represents a thread that calls an asynchronous thread of the preset code project; configuring parameter information, wherein the parameter information comprises at least: a first instruction and a target parameter, wherein the first instruction is used to start a preset tool, and the target parameter is used to use the target code file as an input parameter of a preset function; running the first instruction, reading and loading the target code file through the target parameter; and obtaining the thread information of the target thread by running the target code file.
[0006] Furthermore, the method is applied to a target system, and when the target system receives a data processing request, the target system calls the target thread through the preset code project to process the data processing request, and the target thread asynchronously calls other threads. After obtaining the thread information of the target thread by running the target code file, the method also includes: passing the thread information of the target thread to the other threads, wherein the other threads continue to run by inheriting the thread information of the target thread to complete the data processing request; the target system determines the calling link of the data processing request based on the thread information of the target thread and the thread information of the other threads.
[0007] Furthermore, running the first instruction and reading and loading the target code file through the target parameters include: starting the preset tool by running the first instruction, wherein the preset tool is configured with an interceptor mechanism; reading the code file included in the preset code project through the interceptor mechanism; and loading the target code file by reading the target parameters when it is detected that the preset code project adds the target code file.
[0008] Furthermore, the target code file is loaded by reading the target parameters, including: parsing the parameters contained in the target parameters to obtain a parameter set; when the parameter set contains the class name contained in the target code file, and the parameter set contains a preset string, and the parameter set contains a storage path, generating a target storage path according to the parameter set; reading the target code file according to the target storage path, and loading the target code file into the memory.
[0009] Furthermore, before adding the target code file to the preset code project, the method also includes: obtaining the target code and determining the class name contained in the target code, wherein the target code is used to obtain thread information of the target thread; compiling the target code to obtain a compiled code file; determining a storage path of the compiled code file; and determining the target code file based on the class name, the storage path and the compiled code file.
[0010] Furthermore, the target code includes at least: a first code, a second code, and a third code; wherein the first code is used to obtain a first category, and the first category is used to filter and process tracking thread information; the second code is used to submit an asynchronous thread so that the asynchronous thread carries and adopts the thread information of the target thread during runtime; the third code is used to obtain the thread information of the target thread based on the first code and the second code.
[0011] Furthermore, configuring parameter information includes: determining the first code file of the preset tool, and determining the file name of the first code file; generating the first instruction according to the preset instruction and the file name of the first code file; configuring the target parameter according to the input parameter information of the preset function and the code information of the target code; determining the parameter information according to the first instruction and the target parameter.
[0012] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a device for obtaining thread information is provided, which includes: an adding unit, used to add a target code file to a preset code project, wherein the target code file is used to obtain thread information of a target thread, and the target thread represents a thread that calls an asynchronous thread of the preset code project; a configuration unit, used to configure parameter information, wherein the parameter information includes at least: a first instruction and a target parameter, wherein the first instruction is used to start a preset tool, and the target parameter is used to use the target code file as an input parameter of a preset function; a loading unit, used to run the first instruction, read and load the target code file through the target parameter; and an obtaining unit, used to obtain the thread information of the target thread by running the target code file.
[0013] Furthermore, the device deploys a target system. When receiving a data processing request, the target system calls the target thread through the preset code project to process the data processing request. The target thread asynchronously calls other threads. The device also includes: a transmission unit, which is used to transmit the thread information of the target thread to the other threads after obtaining the thread information of the target thread by running the target code file, wherein the other threads continue to run by inheriting the thread information of the target thread to complete the data processing request; a first determination unit, which is used for the target system to determine the call link of the data processing request based on the thread information of the target thread and the thread information of the other threads.
[0014] Furthermore, the loading unit includes: a startup subunit, used to start the preset tool by running the first instruction, wherein the preset tool is configured with an interceptor mechanism; a reading subunit, used to read the code file contained in the preset code project through the interceptor mechanism; and a loading subunit, used to load the target code file by reading the target parameters when it is detected that the preset code project adds the target code file.
[0015] Furthermore, the loading sub-unit includes: a parsing module, used to parse the parameters contained in the target parameters to obtain a parameter set; a generating module, used to generate a target storage path according to the parameter set when the parameter set contains the class name contained in the target code file, and the parameter set contains a preset string, and the parameter set contains a storage path; a loading module, used to read the target code file according to the target storage path, and load the target code file into the memory.
[0016] Furthermore, the device also includes: a second determination unit, used to obtain the target code and determine the class name contained in the target code before adding the target code file to the preset code project, wherein the target code is used to obtain the thread information of the target thread; a compilation unit, used to compile the target code to obtain a compiled code file; a third determination unit, used to determine the storage path of the compiled code file; and a fourth determination unit, used to determine the target code file based on the class name, the storage path and the compiled code file.
[0017] Furthermore, the target code includes at least: a first code, a second code, and a third code; wherein the first code is used to obtain a first category, and the first category is used to filter and process tracking thread information; the second code is used to submit an asynchronous thread so that the asynchronous thread carries and adopts the thread information of the target thread during runtime; the third code is used to obtain the thread information of the target thread based on the first code and the second code.
[0018] Furthermore, the configuration unit includes: a first determination subunit, used to determine the first code file of the preset tool and determine the file name of the first code file; a generation subunit, used to generate the first instruction based on the preset instruction and the file name of the first code file; a configuration subunit, used to configure the target parameter based on the input parameter information of the preset function and the code information of the target code; a second determination subunit, used to determine the parameter information based on the first instruction and the target parameter.
[0019] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a computer program product is provided, including a computer program, which, when executed by a processor, implements any one of the methods for obtaining thread information described above, and which, when executed by a processor, implements the steps of the method for obtaining thread information described in each embodiment of the present application.
[0020] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes stored computer instructions, wherein when the computer instructions are executed by a processor, any one of the above-mentioned methods for obtaining thread information is implemented.
[0021] In order to achieve the above-mentioned purpose, according to one aspect of the present application, an electronic device is provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by one or more processors, the one or more processors implement any one of the above-mentioned methods for obtaining thread information.
[0022] In an embodiment of the present application, a target code file is added to a preset code project, wherein the target code file is used to obtain thread information of a target thread, wherein the target thread represents a thread of the preset code project calling an asynchronous thread; parameter information is configured, wherein the parameter information includes at least: a first instruction, a target parameter, wherein the first instruction is used to start a preset tool, and the target parameter is used to use the target code file as an input parameter of a preset function; the first instruction is run, and the target code file is read and loaded through the target parameter; the thread information of the target thread is obtained by running the target code file, thereby solving the technical problem that when a link tracking framework is used to track the call information of a data processing request, the source code needs to be modified so that the asynchronous thread obtains the thread information of the parent thread, resulting in high code maintenance costs.
[0023] By adding the modified target code file to the preset code project and configuring specific JVM parameter information, the class file can be dynamically replaced when the JVM is started, so that developers do not need to directly modify the source code, that is, pass thread information to asynchronous threads, reducing maintenance costs and achieving dynamic and non-intrusive asynchronous thread information transmission. At the same time, the tracking ability of asynchronous threads is enhanced, allowing developers to fully trace the request chain across services, which helps to locate and diagnose delays and faults, and improve the stability of distributed systems. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0025] Figure 1 It is a hardware structure block diagram of a computer terminal (or mobile device) for implementing a method for obtaining thread information according to the first embodiment of the present application;
[0026] Figure 2is a flowchart of an optional method for obtaining thread information provided according to Embodiment 1 of the present application;
[0027] Figure 3 This is a schematic diagram of an optional process for obtaining thread information provided in accordance with Embodiment 1 of the present application;
[0028] Figure 4 is a schematic diagram of a device for acquiring thread information provided in Embodiment 2 of the present application;
[0029] Figure 5 It is a schematic diagram of an electronic device for acquiring thread information provided in Embodiment 5 of the present application. DETAILED DESCRIPTION
[0030] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0031] It should be noted that the processing methods, devices, storage media and electronic devices of the present application documents can be used in the process of asynchronous threads obtaining thread information of parent threads in the financial technology field, reducing code maintenance costs, and can also be used in any field other than the financial technology field. The application fields of the processing methods, devices, storage media and electronic devices of the present application documents are not limited.
[0032] It should be noted that the collected information (including but not limited to user device information, user personal information, collected data, used data, generated data, processed data, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, collected information, used information, generated information, processed information, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data are in compliance with the relevant laws, regulations and standards of relevant countries and regions, necessary confidentiality measures are taken, and public order and good customs are not violated, and corresponding operation entrances are provided for users to choose to authorize or refuse. For example, an interface is set up between this system and relevant users or institutions to provide users with corresponding operation entrances for users to choose to agree or refuse the results of automated decision-making; if the user chooses to refuse, the expert decision-making process will be entered.
[0033] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following explanations:
[0034] The main function of the data tracking project is to aggregate and collect the tracking data of the request links on each server, so as to promptly discover the problems of increased latency and the root causes of performance bottlenecks in the system. It also provides UI components to help develop intuitive search tracking information and analyze request link details.
[0035] Span: The basic working unit. A link call (which can be RPC, DB, etc. without specific restrictions) creates a Span and identifies it with a 64-bit ID. Span also has other data, such as description information, timestamp, parent-id, etc., where parent-id can indicate the source of the Span call link. In layman's terms, Span is a request information.
[0036] Trace: A Span collection similar to a tree structure, representing a call link, with a unique identifier, namely TraceId. The data tracking project uses the Trace structure to represent the tracking of a request. A request may be processed by several backend services. The processing of each service is a Span, and there are dependencies between spans. Trace is a Span collection with a tree structure.
[0037] JavaAgent is an advanced feature provided by the Java virtual machine, literally translated as Java agent, also known as Java probe technology. This technology allows developers to dynamically modify bytecode and operate Java applications while the program is running, so that agents can be performed non-invasively. It is often used in various online diagnosis, performance analysis, hot deployment and other scenarios.
[0038] Example 1
[0039] According to an embodiment of the present application, a method embodiment for obtaining thread information is also provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0040] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 FIG. 1 shows a hardware structure block diagram of a computer terminal (or mobile device) for implementing a method for obtaining thread information. Figure 1As shown, the computer terminal 10 (or mobile device) may include one or more (102a, 102 thread information acquisition, ..., 102n are used to illustrate in the figure) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (US thread information acquisition) port (which may be included as one of the ports of the US bus for thread information acquisition), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0041] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0042] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the method for obtaining thread information in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, the method for obtaining thread information described above is realized. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0043] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0044] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 (or mobile device).
[0045] Under the above operating environment, this application provides Figure 2 The method for obtaining thread information is shown. Figure 2 It is a flowchart of a method for obtaining thread information according to Example 1 of the present application.
[0046] Step S101, adding a target code file to a preset code project, wherein the target code file is used to obtain thread information of a target thread, and the target thread represents a thread that the preset code project calls an asynchronous thread.
[0047] In the first embodiment, the target code file is a code file created or modified by the developer to obtain and transmit the tracking information (such as TraceID) in the asynchronous thread. The target code file may contain the code based on the Java reflection mechanism and the enhanced code for the asynchronous task submission method. These modifications allow the developer to dynamically capture and transmit the context information of the asynchronous thread without directly intruding the original code logic.
[0048] The preset code project refers to an existing Java application or project. The project may already use the Spring framework and include asynchronous task calls and processing, but the original design will lose the parent thread tracking information during asynchronous calls. By adding the target code file to this project, you can achieve improvements to the asynchronous thread tracking information.
[0049] The target thread is the main thread that calls the asynchronous thread, that is, the parent thread. Through the logic in the target code file, the tracing context information of the parent thread, such as TraceID, can be obtained. This is achieved by calling the getCurrentTraceContext method (or similar methods) in the parent thread, which is called using the reflection mechanism, thus avoiding the need to modify the source code directly.
[0050] By adding the target code file to the preset code project, Java Agent technology can be used to dynamically enhance or modify its execution behavior without changing the original application source code, so that it can more effectively pass and associate tracking information in asynchronous thread calls. This approach can solve the problem of asynchronous thread information transmission without disrupting the existing system structure and logic.
[0051] Step S102, configuring parameter information, wherein the parameter information at least includes: a first instruction and a target parameter, the first instruction is used to start a preset tool, and the target parameter is used to use the target code file as an input parameter of a preset function.
[0052] In the first embodiment, when a Java application is started, a JavaAgent is configured and specified through JVM parameters, and specific parameters are passed to the Java Agent to achieve dynamic replacement and enhancement of the target code file.
[0053] The first instruction is used to load the Java Agent when starting the Java application. The Java Agent is a tool that can modify or enhance the bytecode before the application runs. The target parameter is the parameter information passed to the Java Agent, which is used to specify the target code file and specific method to be replaced or enhanced.
[0054] By configuring parameter information, the application can dynamically enhance its ability to handle asynchronous thread information transmission in a non-invasive manner. This not only avoids the risks and complexities that may be caused by directly modifying the source code, but also improves the maintainability and flexibility of the system, so that the problem of asynchronous thread information transmission can be effectively solved without changing the existing code structure.
[0055] Step S103, executing the first instruction, reading and loading the target code file through the target parameter.
[0056] In the first embodiment of the present invention, when the Java application is started, the first instruction can be executed to specify the jar package of the JavaAgent. Java Agent is a tool that can dynamically modify the bytecode when the application is running, and interacts with the JVM through the JVMTI interface. The target parameter (for example, agentArgs) carries the class name information that needs to be replaced. In the premain method of the Java Agent, this target parameter is parsed to find the class name that needs to be replaced, and the bytecode file (new_class_name.class) of the new class is read before the class is loaded, and its content is loaded into the memory, thereby realizing the dynamic replacement of the class without changing the source code. In this way, the modified class (i.e., the new class file) can be recognized and executed by the JVM when the application is running, thereby solving the problem of asynchronous thread information transmission and realizing non-invasive Spring asynchronous thread information transmission.
[0057] Step S104, obtaining thread information of the target thread by running the target code file.
[0058] In the first embodiment of the present invention, by dynamically replacing and running the modified class file (target code file), the tracing information of the main thread can be obtained when the asynchronous thread is executed. In the specific implementation, the modified class file contains the logic of asynchronous thread information transmission, for example, the getCurrentTraceContext method is called by the reflection mechanism to read the Trace context of the current thread, which usually contains key tracing information such as Trace ID and Span ID. In addition, when the asynchronous thread is created, the original task can be wrapped (wrapped) by a preset code function, and the context information of the main thread is passed during the wrapping. Therefore, when the asynchronous thread is executed, the tracing information of the main thread can be accessed through the preset context acquisition method, so that in the distributed tracing system, the call links of the main thread and the asynchronous thread can be correctly associated to achieve complete tracing of the asynchronous request. This method avoids direct modification of the source code, reduces maintenance costs and code coupling, and achieves efficient and low-intrusive asynchronous thread information transmission.
[0059] Through the above steps, not only the problem of asynchronous thread tracking information transmission is solved, but also a dynamic and non-intrusive solution is implemented, which is conducive to tracking the call chain of data processing requests, avoiding the complexity and risk of directly modifying the source code, and ensuring the continuity of the request chain tracking of the entire system, thereby improving the system's monitoring and debugging capabilities.
[0060] Optionally, in the method for obtaining thread information provided in Example 1 of the present application, the above method is applied to the target system. When the target system receives a data processing request, the target system calls the target thread to process the data processing request through a preset code project, and the target thread asynchronously calls other threads. After obtaining the thread information of the target thread by running the target code file, the above method also includes: passing the thread information of the target thread to other threads, wherein the other threads continue to run by inheriting the thread information of the target thread to complete the data processing request; the target system determines the calling link of the data processing request based on the thread information of the target thread and the thread information of other threads.
[0061] In the first embodiment, the target system refers to a distributed application system using the Spring framework or other architectures. Such systems are usually composed of multiple microservices, and often use asynchronous threads to improve performance and response speed when processing data. Data processing requests refer to requests initiated from the outside or inside the system that require one or more services in the target system to process. These requests may involve interactions between multiple services and calls to asynchronous threads to complete specific tasks.
[0062] After capturing the target thread's tracing information (including but not limited to TraceID and SpanID) based on the target code file (enhanced class), the thread information is encapsulated and passed to other threads called by the target thread. Exemplarily, this transfer can be to attach the tracing information to the asynchronous task through a task wrapper (such as the wrap method), ensuring that when other threads execute the asynchronous task, they can inherit and use this information, thereby maintaining the continuity of the tracing information even in the asynchronous thread.
[0063] Then, the target system can build a complete call link of the data processing request by analyzing and integrating the tracking information of different threads (including asynchronous threads). By collecting and parsing the span information of each service, a visual request tracking chart can be generated to show the link of the entire data processing request between different services and threads.
[0064] Through the above steps, not only the problem of being unable to pass tracing information when calling asynchronous threads is solved, but also the efficiency of debugging and performance analysis in distributed systems is improved, allowing development and operation and maintenance teams to more accurately track and understand the execution path of requests.
[0065] Optionally, in the thread information acquisition method provided in Example 1 of the present application, a first instruction is executed, and a target code file is read and loaded through target parameters, including: starting a preset tool by executing the first instruction, wherein the preset tool is configured with an interceptor mechanism; reading the code file included in the preset code project through the interceptor mechanism; and loading the target code file by reading the target parameters when it is detected that the preset code project adds a target code file.
[0066] In the first embodiment, by running the first instruction, the Java Agent, i.e., the preset tool mentioned above, can be started to load and start, so that the bytecode file of the application can be read and modified. Exemplarily, the first instruction can be "-javaagent: / path / agent.jar". When the Java application is started using the command line, the JVM will load and execute the preset tool in agent.jar before the application is officially run. The tool is initialized and configured before the JVM loads the user class by executing the premain method (if supported by the Java Agent).
[0067] The interceptor mechanism is a key mechanism in Java Agent, which is used to intercept and modify bytecode during class loading. When the Java application is running, the interceptor in Java Agent will intercept the class loading event, which will trigger the reading and analysis of the code files (i.e. bytecode files) contained in the preset code project, so that Java Agent can check the classes being loaded and decide whether they need to be modified.
[0068] After the Java Agent detects that the preset code project adds a target code file, it locates the target code file through the target parameter (for example, -DMONITOR_SERVICE_METHOD). The Java Agent intervenes in the class loading process and uses the target code file to replace the original bytecode file, thereby obtaining thread information through the modified target code file.
[0069] By running the first instruction to start the preset tool configured with the interceptor mechanism, it is possible to dynamically load and replace specific code files (target code files) during the running of the Java application, which not only avoids the need to directly modify the source code, but also enables the application to have the ability to handle asynchronous thread information transmission at runtime.
[0070] Optionally, in the thread information acquisition method provided in Example 1 of the present application, the target code file is loaded by reading the target parameters, including: parsing the parameters contained in the target parameters to obtain a parameter set; when the parameter set includes the class name contained in the target code file, and the parameter set includes a preset string, and the parameter set includes a storage path, generating a target storage path according to the parameter set; reading the target code file according to the target storage path, and loading the target code file into the memory.
[0071] In the first embodiment of the present invention, the JVM parameter -DMONITOR_SERVICE_METHOD (i.e., the target parameter mentioned above) is passed to the preset tool (Java Agent). Exemplarily, the target parameter may be "-DMONITOR_SERVICE_METHOD = / package_name / ... / class_name#replaceClassFile(new_class_name.class)". The target parameter includes the class name "new_class_name.class" to be replaced or enhanced, the preset string "replaceClassFile", and the storage path of the new class bytecode " / package_name / ... / class_name". The target parameter is parsed and split into multiple components to form a parameter set. The parameter set is concatenated to generate the above-mentioned target storage path.
[0072] Before generating the target storage path, it is necessary to check whether the parameter set meets the following three conditions: (1) The parameter set must contain the class name contained in the target code file, that is, there must be a clear class name in the parameter set, which is the name of the target class that needs to be replaced or enhanced; (2) The parameter set must contain a preset string, where the preset string may be replaceClassFile or other identifiers, which are used to indicate the use of the dynamic replacement function; (3) The parameter set must contain a storage path, that is, the parameter set must contain a valid file path pointing to the newly compiled and enhanced class bytecode file, that is, the above-mentioned target code file. If all three conditions are met, the target storage path is generated according to the information in the parameter set.
[0073] After the target storage path is generated, the Java Agent reads the target code file from the disk according to the target storage path. This file contains the modified or enhanced class bytecode, which is used to replace the original class bytecode. Reading files is usually implemented through Java's standard IO operations, such as Files.readAllBytes(Paths.get(classPath)), which reads the contents of the entire bytecode file into memory and generates a byte array (replaceClassBytes).
[0074] By parsing and generating the target storage path through Java Agent, and then reading and loading the target code file into the memory, subsequent bytecode replacement and class function enhancement can be performed, while avoiding the complexity and risk of directly modifying the source code.
[0075] Optionally, in the method for obtaining thread information provided in Example 1 of the present application, before adding the target code file to the preset code project, the above method also includes: obtaining the target code, determining the class name contained in the target code, wherein the target code is used to obtain the thread information of the target thread; compiling the target code to obtain a compiled code file; determining the storage path of the compiled code file; and determining the target code file based on the class name, storage path and compiled code file.
[0076] In the first embodiment, the target code refers to the source code that contains the modification or enhancement of the existing Spring asynchronous thread processing logic to obtain the thread information of the target thread. The class name refers to the name of the Java class defined in the target code. The class name is used to accurately identify and locate the class that needs to be modified or enhanced. In Java, the class name is usually the same as its file name (but does not include the file extension).
[0077] Then, compile the target code to get the compiled code file. Convert the target code into a bytecode file (.class file) to get the binary code that the JVM can directly execute, that is, the compiled code file mentioned above. Determine the storage path of the compiled code file so that the Java Agent can find and read the file to dynamically replace and enhance the class function at runtime. The storage path is usually a file system path, such as / path / to / your / classes.
[0078] In Java Agent, the premain method reads JVM parameters (such as -DMONITOR_SERVICE_METHOD) to parse the class name and storage path. When the premain method is executed, Java Agent checks whether agentArgs (the target parameter mentioned above) contains the preset string replaceClassFile and a non-empty file path. If the conditions are met, the Agent generates a new target path based on the extracted class name and storage path information, such as AgentPath+<package_name> / <class_name> .class, where AgentPath is the configured Agent base path. Then, the Java Agent uses a preset code function (for example, the Files.readAllBytes method) to read the bytecode of the new class file from this target path and load it into memory. In this way, when the JVM tries to load the original class, the Java Agent can intervene in advance and replace the original bytecode with the modified or enhanced .class file, thereby realizing dynamic enhancement without modifying the source code, ensuring that asynchronous threads can obtain the tracking information of the parent thread.
[0079] By editing the source code, using the compiler, generating and storing bytecode files, and dynamically searching and loading bytecode files by the Java Agent at runtime, it is possible to enhance the thread information transmission function without directly modifying the application source code, especially to handle information transmission in Spring asynchronous threads, thereby improving the efficiency of system monitoring and debugging.
[0080] Optionally, in the thread information acquisition method provided in Example 1 of the present application, the target code includes at least: a first code, a second code, and a third code; wherein the first code is used to obtain a first category, and the first category is used to filter and process tracking thread information; the second code is used to submit an asynchronous thread so that the asynchronous thread carries and adopts the thread information of the target thread during runtime; the third code is used to obtain the thread information of the target thread based on the first code and the second code.
[0081] In the first embodiment, the first code is used to obtain the first class, which may be TraceFilter, for filtering and processing thread information related to tracing, for example, obtaining tracing information TraceID and SpanID from the current thread context. Exemplarily, the Class.forName method may be used to dynamically load the TraceFilter class, so that methods in the class can be accessed and called. At the same time, the class loader TRACING_CLASS_LOADER is used to ensure that the TraceFilter class can be loaded correctly.
[0082] The second code is used to submit an asynchronous thread and ensure that the tracking information of the target thread (usually the parent thread or the main thread) can be carried and used when the asynchronous thread is running. Exemplarily, the submission of an asynchronous thread is achieved by modifying or enhancing the submit method of ExecutorService so that tracking information can be attached when submitting an asynchronous task. At the same time, the wrap method is called to wrap the asynchronous task, and the getContext method is called to obtain the tracking information of the current thread. When the wrapped task taskWarp is running in an asynchronous thread, it can access and use this information, thereby realizing the transmission of tracking information between asynchronous threads.
[0083] The third code is used to actually obtain the thread information of the target thread. The third code obtains the tracing information based on the getCurrentTraceContext method in the TraceFilter class called by the first code, and then passes this information to the asynchronous task. The getContext method can call contextMethod (i.e. getCurrentTraceContext) to obtain the tracing context information of the current thread. If the call is successful, this information will be encapsulated by the second code and passed to the asynchronous task, thereby ensuring that each asynchronous thread can access the complete tracing information.
[0084] By designing the first, second, and third codes, a dynamic, non-intrusive asynchronous thread tracing information transmission mechanism can be constructed, so that in complex distributed systems, even when asynchronous thread calls are involved, the continuity and accuracy of tracing information can be maintained, thereby greatly simplifying the debugging and performance analysis process. Among them, the first code is responsible for obtaining and processing classes for tracing information; the second code ensures that asynchronous tasks can run with tracing information; and the third code is used to actually obtain and transmit tracing information.
[0085] Optionally, in the thread information acquisition method provided in the first embodiment of the present application, parameter information is configured, including: determining a first code file of a preset tool, and determining a file name of the first code file; generating a first instruction based on the preset instruction and the file name of the first code file; configuring target parameters based on input parameter information of a preset function and code information of the target code; and determining parameter information based on the first instruction and the target parameters.
[0086] In the first embodiment, the first code file of the preset tool represents a .jar package that implements the Java Agent mechanism. The first code file encapsulates the tool code that can dynamically modify the bytecode before the application is started. Its file name is, for example, agent.jar. The preset instruction -javaagent: is a parameter of the Java virtual machine, which is used to start the Java Agent mechanism. It needs to be used in conjunction with the path of the first code file. Therefore, combining the -javaagent: instruction with the full path of agent.jar can generate a first instruction, such as -javaagent: / path / agent.jar, which tells the JVM to load and execute the Java Agent under the specified path at startup.
[0087] The preset function refers to the function used to process JVM parameters in the Java Agent tool, namely the premain method, which is the entry point called by the Java Agent before the JVM is started. The input parameter information refers to the parameter information passed by the JVM to the Java Agent. The code information of the target code includes the storage path of the target code and the preset string "replaceClassFile" representing the replacement bytecode file. The target parameter obtained by combining the input parameter information of the preset function and the code information of the target code can be expressed as "-DMONITOR_SERVICE_METHOD= / package_name / ... / class_name#replaceClassFile(new_class_name.class)".
[0088] Finally, the first instruction (-javaagent: / path / agent.jar) and the target parameter (such as the value of -DMONITOR_SERVICE_METHOD) are combined to form parameter information. The parameter information completely configures the startup and operation instructions of the Java Agent, including the loading path of the Java Agent tool, the specific class that needs to be bytecode replaced, and the storage path of the modified class file.
[0089] By determining the parameter information, the Java Agent can accurately locate and read the target code file when the JVM starts, and then dynamically replace or enhance the bytecode of the application based on the information in the target parameters, thereby achieving non-intrusive enhancement of Spring asynchronous thread information transmission.
[0090] Optionally, in this embodiment 1, Figure 3 FIG. 1 is a schematic diagram of an optional process for obtaining thread information according to Embodiment 1 of the present application. Figure 3As shown in the figure, first, the class file modified by the developer (i.e., the new class file) is stored in the specified path in the container. Then, the container is started to provide an environment for the deployment of the Java Agent. When starting the JVM, the jar package of the Java Agent is specified through the -javaagent parameter. This operation ensures that the Java Agent is loaded before the JVM is initialized. After the JVM is started, the ClassLoader starts to load the class files of the application. The JVM calls the premain method of the Java Agent, which is used to parse the JVM parameters and determine the class file corresponding to the Agent-Class, that is, the core class of the JavaAgent itself. Inside the premain method, the Java Agent code starts to run, reads all the JVM parameters, and parses out the key information for dynamic enhancement, such as the -DMONITOR_SERVICE_METHOD parameter. Then, the Java Agent enters the monitoring mode and intercepts the loading process of the Class file. When the ClassLoader attempts to load a specific Class file, the Java Agent determines whether a replacement operation is required based on the information in the JVM parameters. For Class files that need to be dynamically enhanced, the Java Agent will read the new class file located in the specified storage path and replace the original bytecode based on the information provided by the -DMONITOR_SERVICE_METHOD parameter before ClassLoader loads it. Once the Class file is replaced, ClassLoader loads the replaced bytecode file (that is, the "new class file" modified by the developer), which contains the code logic for passing parent thread information in asynchronous threads. When executing the replaced class, the preset context acquisition method, such as reflective call getCurrentTraceContext, can be used to read and pass the parent thread's TraceID to the asynchronous child thread, ensuring the correct transmission of asynchronous thread information.
[0091] Figure 3 The demonstrated process can effectively solve the problem of asynchronous thread context information transmission, especially in large distributed systems. Through the combination of non-intrusive design and dynamic context transmission logic, the traceability and debugging efficiency of asynchronous tasks are significantly improved, and the maintenance cost and the risk of introducing errors are reduced. In practical applications, the system provides more powerful tracking and debugging capabilities for applications under the Spring framework, supports more refined system operation and maintenance and error troubleshooting, and plays an important role in improving system stability and user experience.
[0092] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0093] To summarize, the method for obtaining thread information provided in the embodiment of the present application is achieved by adding a target code file to a preset code project, wherein the target code file is used to obtain the thread information of a target thread, and the target thread represents the thread of the preset code project calling an asynchronous thread; configuring parameter information, wherein the parameter information includes at least: a first instruction and a target parameter, wherein the first instruction is used to start a preset tool, and the target parameter is used to use the target code file as an input parameter of a preset function; running the first instruction, reading and loading the target code file through the target parameter; obtaining the thread information of the target thread by running the target code file, thereby solving the problem in the related art that when a link tracking framework is used to track the call information of a data processing request, the source code needs to be modified so that the asynchronous thread obtains the thread information of the parent thread, resulting in a high code maintenance cost.
[0094] By adding the modified target code file to the preset code project and configuring specific JVM parameter information, the class file can be dynamically replaced when the JVM is started, so that developers do not need to directly modify the source code, that is, pass thread information to asynchronous threads, reducing maintenance costs and achieving dynamic and non-intrusive asynchronous thread information transmission. At the same time, the tracking ability of asynchronous threads is enhanced, allowing developers to fully trace the request chain across services, which helps to locate and diagnose delays and faults, and improve the stability of distributed systems.
[0095] Example 2
[0096] The embodiment of the present application also provides a device for obtaining thread information. It should be noted that the device for obtaining thread information in the embodiment of the present application can be used to execute the method for obtaining thread information provided in the embodiment of the present application. The device for obtaining thread information provided in the embodiment of the present application is introduced below.
[0097] According to an embodiment of the present application, a device for implementing the above-mentioned thread information acquisition method is also provided. Figure 4 As shown, the device comprises:
[0098] Specifically, the adding unit 401 is used to add the target code file to the preset code project, wherein the target code file is used to obtain thread information of a target thread, and the target thread represents a thread that the preset code project calls an asynchronous thread.
[0099] The configuration unit 402 is used to configure parameter information, wherein the parameter information at least includes: a first instruction and a target parameter, wherein the first instruction is used to start a preset tool, and the target parameter is used to use a target code file as an input parameter of a preset function.
[0100] The loading unit 403 is used to execute the first instruction, read and load the target code file through the target parameter.
[0101] The acquisition unit 404 is used to acquire the thread information of the target thread by running the target code file.
[0102] The thread information acquisition device provided in the embodiment of the present application adds the target code file to the preset code project through the adding unit 401, wherein the target code file is used to obtain the thread information of the target thread, and the target thread represents the thread of the preset code project calling the asynchronous thread; the configuration unit 402 configures the parameter information, wherein the parameter information at least includes: a first instruction and a target parameter, the first instruction is used to start the preset tool, and the target parameter is used to use the target code file as an input parameter of the preset function; the loading unit 403 runs the first instruction, reads and loads the target code file through the target parameter; the acquisition unit 404 obtains the thread information of the target thread by running the target code file, which solves the problem in the related art that when a link tracking framework is used to track the call information of a data processing request, the source code needs to be modified so that the asynchronous thread obtains the thread information of the parent thread, resulting in a high code maintenance cost.
[0103] By adding the modified target code file to the preset code project and configuring specific JVM parameter information, the class file can be dynamically replaced when the JVM is started, so that developers do not need to directly modify the source code, that is, pass thread information to asynchronous threads, reducing maintenance costs and achieving dynamic and non-intrusive asynchronous thread information transmission. At the same time, the tracking ability of asynchronous threads is enhanced, allowing developers to fully trace the request chain across services, which helps to locate and diagnose delays and faults, and improve the stability of distributed systems.
[0104] Optionally, in the thread information acquisition device provided in Example 2 of the present application, the above-mentioned device deploys a target system. When the target system receives a data processing request, it calls the target thread to process the data processing request through a preset code project, and the target thread asynchronously calls other threads. The device also includes: a transmission unit, which is used to transmit the thread information of the target thread to other threads after obtaining the thread information of the target thread by running the target code file, wherein the other threads continue to run by inheriting the thread information of the target thread to complete the data processing request; a first determination unit, which is used for the target system to determine the call link of the data processing request based on the thread information of the target thread and the thread information of other threads.
[0105] Optionally, in the thread information acquisition device provided in Example 2 of the present application, the above-mentioned loading unit 403 includes: a startup subunit, used to start a preset tool by running a first instruction, wherein the preset tool is configured with an interceptor mechanism; a reading subunit, used to read the code file included in the preset code project through the interceptor mechanism; a loading subunit, used to load the target code file by reading the target parameters when it is detected that the preset code project adds a target code file.
[0106] Optionally, in the thread information acquisition device provided in Example 2 of the present application, the above-mentioned loading sub-unit includes: a parsing module, used to parse the parameters contained in the target parameters to obtain a parameter set; a generating module, used to generate a target storage path according to the parameter set when the parameter set contains the class name contained in the target code file, and the parameter set contains a preset string, and the parameter set contains a storage path; a loading module, used to read the target code file according to the target storage path, and load the target code file into the memory.
[0107] Optionally, in the thread information acquisition device provided in Example 2 of the present application, the above-mentioned device also includes: a second determination unit, used to obtain the target code and determine the class name contained in the target code before adding the target code file to the preset code project, wherein the target code is used to obtain the thread information of the target thread; a compilation unit, used to compile the target code to obtain a compiled code file; a third determination unit, used to determine the storage path of the compiled code file; and a fourth determination unit, used to determine the target code file based on the class name, storage path and compiled code file.
[0108] Optionally, in the thread information acquisition device provided in Example 2 of the present application, the above-mentioned target code includes at least: a first code, a second code, and a third code; wherein the first code is used to obtain the first category, and the first category is used to filter and process tracking thread information; the second code is used to submit an asynchronous thread so that the asynchronous thread carries and adopts the thread information of the target thread during runtime; the third code is used to obtain the thread information of the target thread based on the first code and the second code.
[0109] Optionally, in the thread information acquisition device provided in Example 2 of the present application, the above-mentioned configuration unit 402 includes: a first determination subunit, used to determine the first code file of the preset tool and determine the file name of the first code file; a generation subunit, used to generate a first instruction based on the preset instruction and the file name of the first code file; a configuration subunit, used to configure target parameters based on the input parameter information of the preset function and the code information of the target code; a second determination subunit, used to determine parameter information based on the first instruction and the target parameter.
[0110] It should be noted that the above-mentioned adding unit 401, configuring unit 402, loading unit 403 and acquiring unit 404 correspond to steps S201 to S204 in Embodiment 1, and the examples and application scenarios implemented by the two modules and the corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned Embodiment 1. It should be noted that the above-mentioned modules or units may be hardware components or software components stored in a memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102 thread information acquisition, ..., 102n), and the above-mentioned modules may also be part of the device and may be run in the computer terminal 10 provided in Embodiment 1.
[0111] Example 3
[0112] An embodiment of the present application may provide an electronic device, Figure 5 is a structural block diagram of an electronic device according to an embodiment of the present application. Figure 5 As shown, the electronic device may include: one or more ( Figure 5 (only one is shown) processor 502, memory 504, storage controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.
[0113] Among them, the memory can be used to store software programs and modules, such as program instructions / modules corresponding to the methods and devices in the embodiments of the present application, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the above-mentioned method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0114] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: add the target code file to the preset code project, wherein the target code file is used to obtain the thread information of the target thread, and the target thread represents the thread of the preset code project calling the asynchronous thread; configure parameter information, wherein the parameter information at least includes: a first instruction, a target parameter, the first instruction is used to start the preset tool, and the target parameter is used to use the target code file as an input parameter of the preset function; run the first instruction, read and load the target code file through the target parameter; obtain the thread information of the target thread by running the target code file.
[0115] The processor can call the information and application programs stored in the memory through the transmission device to perform the following steps: the above method is applied to the target system, and when the target system receives a data processing request, the target system calls the target thread to process the data processing request through a preset code project, and the target thread asynchronously calls other threads. After obtaining the thread information of the target thread by running the target code file, the above method also includes: passing the thread information of the target thread to other threads, wherein the other threads continue to run by inheriting the thread information of the target thread to complete the data processing request; the target system determines the call link of the data processing request based on the thread information of the target thread and the thread information of other threads.
[0116] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: run the first instruction, read and load the target code file through the target parameter, including: start the preset tool by running the first instruction, wherein the preset tool is configured with an interceptor mechanism; read the code file included in the preset code project through the interceptor mechanism; and load the target code file by reading the target parameter when it is detected that the preset code project adds the target code file.
[0117] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: load the target code file by reading the target parameters, including: parsing the parameters contained in the target parameters to obtain a parameter set; when the parameter set includes the class name contained in the target code file, and the parameter set includes a preset string, and the parameter set includes a storage path, generate a target storage path according to the parameter set; read the target code file according to the target storage path, and load the target code file into the memory.
[0118] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: before adding the target code file to the preset code project, the above method also includes: obtaining the target code, determining the class name contained in the target code, wherein the target code is used to obtain the thread information of the target thread; compiling the target code to obtain a compiled code file; determining the storage path of the compiled code file; determining the target code file based on the class name, storage path and compiled code file.
[0119] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: the target code includes at least: a first code, a second code, and a third code; wherein the first code is used to obtain the first category, and the first category is used to filter and process tracking thread information; the second code is used to submit the asynchronous thread so that the asynchronous thread carries and adopts the thread information of the target thread during operation; the third code is used to obtain the thread information of the target thread based on the first code and the second code.
[0120] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: configure parameter information, including: determining the first code file of the preset tool and determining the file name of the first code file; generating a first instruction based on the preset instruction and the file name of the first code file; configuring target parameters based on the input parameter information of the preset function and the code information of the target code; determining parameter information based on the first instruction and the target parameters.
[0121] According to an embodiment of the present application, a method for obtaining thread information is provided. By adding a target code file to a preset code project, wherein the target code file is used to obtain thread information of a target thread, and the target thread represents a thread that calls an asynchronous thread in the preset code project; configuring parameter information, wherein the parameter information at least includes: a first instruction, a target parameter, wherein the first instruction is used to start a preset tool, and the target parameter is used to use the target code file as an input parameter of a preset function; running the first instruction, reading and loading the target code file through the target parameter; obtaining thread information of the target thread by running the target code file, thereby solving the technical problem that when using a link tracking framework to track the call information of a data processing request, the source code needs to be modified so that the asynchronous thread obtains the thread information of the parent thread, resulting in a high code maintenance cost.
[0122] By adding the modified target code file to the preset code project and configuring specific JVM parameter information, the class file can be dynamically replaced when the JVM is started, so that developers do not need to directly modify the source code, that is, pass thread information to asynchronous threads, reducing maintenance costs and achieving dynamic and non-intrusive asynchronous thread information transmission. At the same time, the tracking ability of asynchronous threads is enhanced, allowing developers to fully trace the request chain across services, which helps to locate and diagnose delays and faults, and improve the stability of distributed systems.
[0123] It can be understood by those skilled in the art that Figure 5 The structure shown is for illustration only, and the electronic device may also be a terminal device such as a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Moile Internet Devices, MID), a PAD, etc. Figure 5 The structure of the electronic device is not limited. Figure 5 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 5 Different configurations are shown.
[0124] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0125] Example 4
[0126] The embodiment of the present application further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the thread information acquisition method provided in the first embodiment.
[0127] Optionally, in this embodiment, the above storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0128] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing the steps of the method for obtaining thread information.
[0129] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0130] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0131] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0132] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0133] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0134] If the integrated unit is implemented in the form of 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 the present 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, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0135] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for obtaining thread information, characterized in that: include: Adding a target code file to a preset code project, wherein the target code file is used to obtain thread information of a target thread, wherein the target thread represents a thread that the preset code project calls an asynchronous thread; Configuration parameter information, wherein the parameter information at least includes: a first instruction and a target parameter, wherein the first instruction is used to start a preset tool, and the target parameter is used to use the target code file as an input parameter of a preset function; Run the first instruction, read and load the target code file through the target parameter; The thread information of the target thread is obtained by running the target code file.
2. The method according to claim 1, characterized in that The method is applied to a target system. When receiving a data processing request, the target system calls the target thread through the preset code project to process the data processing request. The target thread asynchronously calls other threads. After acquiring thread information of the target thread by running the target code file, the method further includes: Passing the thread information of the target thread to the other threads, wherein the other threads continue to run by inheriting the thread information of the target thread to complete the data processing request; The target system determines the call link of the data processing request according to the thread information of the target thread and the thread information of the other threads.
3. The method according to claim 1, characterized in that Running the first instruction, reading and loading the target code file through the target parameter, includes: Starting the preset tool by running the first instruction, wherein the preset tool is configured with an interceptor mechanism; Read the code file included in the preset code project through the interceptor mechanism; In the case where it is detected that the preset code item adds the target code file, the target code file is loaded by reading the target parameter.
4. The method according to claim 3, characterized in that Loading the target code file by reading the target parameter includes: Parsing the parameters contained in the target parameters to obtain a parameter set; In a case where the parameter set includes the class name included in the target code file, the parameter set includes a preset character string, and the parameter set includes a storage path, generating a target storage path according to the parameter set; The target code file is read according to the target storage path, and the target code file is loaded into the memory.
5. The method according to claim 1, characterized in that Before adding the target code file to the preset code project, the method further includes: Obtaining a target code and determining a class name contained in the target code, wherein the target code is used to obtain thread information of the target thread; Compiling the target code to obtain a compiled code file; Determine the storage path of the compiled code file; The target code file is determined according to the class name, the storage path and the compiled code file.
6. The method according to claim 5, characterized in that The target code includes at least: a first code, a second code, and a third code; wherein the first code is used to obtain a first category, and the first category is used to filter and process tracking thread information; the second code is used to submit an asynchronous thread so that the asynchronous thread carries and adopts the thread information of the target thread during runtime; the third code is used to obtain the thread information of the target thread based on the first code and the second code.
7. The method according to claim 1, characterized in that Configuration parameter information, including: Determine a first code file of the preset tool, and determine a file name of the first code file; Generate the first instruction according to a preset instruction and the file name of the first code file; Configuring the target parameters according to the input parameter information of the preset function and the code information of the target code; The parameter information is determined according to the first instruction and the target parameter.
8. A device for obtaining thread information, characterized in that: include: An adding unit, configured to add a target code file to a preset code project, wherein the target code file is used to obtain thread information of a target thread, wherein the target thread represents a thread that the preset code project calls an asynchronous thread; A configuration unit, configured to configure parameter information, wherein the parameter information at least includes: a first instruction and a target parameter, wherein the first instruction is used to start a preset tool, and the target parameter is used to use the target code file as an input parameter of a preset function; A loading unit, configured to execute the first instruction, read and load the target code file through the target parameter; An acquisition unit is used to acquire thread information of the target thread by running the target code file.
9. An electronic device, characterized in that: include: A memory storing an executable program; A processor, configured to run the program, wherein the program executes the method according to any one of claims 1 to 7 when running.
10. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Cross-thread link tracking information transmission method and device, electronic equipment and medium
CN121078031A