Method, system and product for dynamically detecting service hotspot based on Java Agent
By embedding monitoring logic into the Java Virtual Machine through a Java Agent, hot methods in Java application services can be detected and analyzed in real time. This solves the problems of high invasiveness and poor real-time performance in existing technologies, and achieves non-intrusive, real-time performance optimization and flexible early warning.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HEBEI HAPPY CONSUMPTION FINANCE CO LTD
- Filing Date
- 2025-12-31
- Publication Date
- 2026-04-28
AI Technical Summary
Existing technologies for identifying hot methods in Java application services suffer from high intrusiveness and poor real-time performance, leading to complex business logic and untimely handling of performance issues.
By using bytecode enhancement technology, monitoring logic is implanted into the Java Virtual Machine using a Java Agent to collect and analyze method execution information in real time, dynamically detect hot methods, and provide a non-intrusive real-time monitoring and early warning mechanism through the Java Agent.
It achieves non-intrusive, real-time hotspot method detection, reduces code maintenance costs, improves the real-time performance and accuracy of performance optimization, and provides flexible early warning methods.
Smart Images

Figure CN121935102A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and specifically to a method, system, and product for dynamically detecting service hotspots based on Java Agent. Background Technology
[0002] In the production operation and maintenance of Java application services, quickly locating and resolving performance bottlenecks is crucial. Identifying "hot methods" (i.e., methods that are called abnormally frequently or have abnormally long execution times) is key to performance optimization.
[0003] Existing technologies primarily employ log tracking to identify hot methods in Java application services. Specifically, this involves manually inserting log statements at the entry and exit points of business methods. This records key information such as the start time and input parameters at the method entry point and the end time at the method exit point. Hot methods are then identified by analyzing the log files afterward.
[0004] However, the above-mentioned existing technologies have the following drawbacks:
[0005] Highly intrusive: This method requires inserting logging statements into a large amount of business code, which complicates the original business logic and increases code maintenance costs;
[0006] Poor real-time performance: Log file analysis is usually done after the fact, making it impossible to obtain information on hot methods in real time, and making it difficult to detect and handle performance issues in a timely manner. Summary of the Invention
[0007] This invention provides a solution for dynamically detecting service hotspots based on Java Agent. Through bytecode enhancement technology, it enables non-intrusive, real-time dynamic detection of service hotspots.
[0008] On one hand, one embodiment of the present invention is a method for dynamically detecting service hotspots based on a Java Agent, which includes at least the following steps:
[0009] Configure Java proxy parameters in the JVM (Java Virtual Machine) startup parameters of the target application service, wherein the Java proxy parameters point to the path of the proxy JAR package;
[0010] The target application service is started, and the JVM loads and initializes the Java Agent in the agent JAR package according to the Java agent parameters. The Java Agent then performs bytecode enhancement on the predetermined target methods in the target application service to inject monitoring logic.
[0011] Through the implanted monitoring logic, the execution information of the enhanced target method is collected in real time when the method is executed.
[0012] The execution information is analyzed in real time according to at least one preset dynamic rule;
[0013] When the real-time analysis results meet the dynamic rules, the target method is determined to be a hotspot method.
[0014] In some implementations, the method further includes: pre-installing the proxy JAR package to a specified file path on the target server running the target application service.
[0015] In some implementations, the preset dynamic rules include at least one of the following:
[0016] First rule: Within a preset first time window, the number of times the target method is called exceeds a first threshold;
[0017] Second rule: Within a preset second time window, the average execution time of the target method exceeds a second threshold.
[0018] In some implementations, the JVM startup parameters also include an alarm recipient parameter, which specifies the alarm recipient.
[0019] In some implementations, the method further includes: when the target method is determined to be a hotspot method, triggering an early warning notification to a designated alarm receiver.
[0020] In some implementations, the method of triggering the warning notification includes at least one of the following: WeChat notification, telephone notification, and email notification.
[0021] In some implementations, the method further includes: if no specific alarm receiver is configured, printing an early warning log when the target method is determined to be a hotspot method.
[0022] In some implementations, the target method is a class or method in the target application service that is annotated with a specific annotation. In some implementations, the specific annotation includes the @RestController annotation.
[0023] In some implementations, the execution information includes at least one or more of the following: method identifier, number of calls, execution start time, and execution end time.
[0024] In some implementations, the method further includes providing a visualization page to display the execution information and / or the determination results of the hotspot method in real time.
[0025] On the other hand, another embodiment of the present invention relates to a system for a dynamic service hotspot detection method based on a Java Agent, which is used to implement the method described in any embodiment of the present invention, the system comprising:
[0026] The proxy configuration module is used to configure Java proxy parameters in the JVM startup parameters of the target application service, wherein the Java proxy parameters point to the path of the proxy JAR package;
[0027] The bytecode enhancement module is used to load and initialize the Java Agent in the agent JAR package by the JVM according to the Java agent parameters when the target application service is started, and to enhance the bytecode of the predetermined target methods in the target application service through the Java Agent in order to inject monitoring logic.
[0028] The data collection and real-time analysis module is used to: collect execution information of the enhanced target method in real time when the enhanced target method is executed through the implanted monitoring logic; perform real-time analysis of the execution information according to at least one preset dynamic rule; and determine the target method as a hotspot method when the real-time analysis result satisfies the dynamic rule.
[0029] In some implementations, the system further includes an early warning module, used to trigger an early warning notification to a designated alarm recipient or trigger the printing of an early warning log when the target method is determined to be a hot method.
[0030] In some implementations, the system further includes a visualization module for providing a visualization page to display the execution information and / or the determination results of the hotspot method in real time.
[0031] Furthermore, embodiments of the present invention also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the method described in any embodiment of the present invention.
[0032] In addition, embodiments of the present invention also provide a computer device, which includes:
[0033] A memory on which computer programs are stored;
[0034] A processor that, when executing the computer program, implements the steps of the method described in any embodiment of the present invention.
[0035] The implementation of this invention has the following beneficial effects:
[0036] Non-intrusive to business code: The implementation of this invention only requires specifying the path of the proxy JAR package on the target server and specifying the alarm receiver when setting JVM startup parameters to complete system access.
[0037] Non-intrusive monitoring: The implementation of this invention achieves monitoring by dynamically enhancing bytecode through a Java Agent, reducing the intrusion on business code, improving code maintainability, and avoiding the complexity and maintenance costs to business logic caused by adding monitoring code.
[0038] High real-time performance: The implementation of this invention collects the execution information of the target method in real time when the target application service is executed, quickly and accurately identifies hot methods, provides timely data support for system performance optimization, and solves the problem of poor real-time performance in the prior art.
[0039] Flexible warning methods: The implementation of this invention can notify the alarm recipient through various means such as WeChat, telephone, and email, ensuring timely delivery of information on hot topics.
[0040] Various aspects, features, and advantages of embodiments of the present invention will be specifically described below in conjunction with the accompanying drawings. These aspects, features, and advantages will become clearer from the following detailed description in conjunction with the accompanying drawings. Attached Figure Description
[0041] Figure 1 This is a schematic flowchart illustrating a method for dynamically detecting service hotspots based on a Java Agent according to an embodiment of the present invention.
[0042] Figure 2 This is a schematic block diagram illustrating the system structure of the Java Agent-based dynamic service hotspot detection method according to an embodiment of the present invention.
[0043] Figure 3 This is a schematic structural block diagram illustrating a computer device according to an embodiment of the present invention. Detailed Implementation
[0044] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. It should be noted that the present invention can be implemented in many forms and is therefore not limited to the specific embodiments described herein or shown in the accompanying drawings.
[0045] The terms “comprising,” “including,” and “having” are used herein to indicate the presence of certain features, steps, operations, elements, and / or components, but do not exclude the presence or addition of other features, steps, operations, elements, components, or combinations thereof.
[0046] Although the methods of the embodiments of the present invention have been described or illustrated in a certain order in this document and in the accompanying drawings, it should be understood that the methods of the present invention are not necessarily performed in the order described or illustrated.
[0047] Reference Figure 1 In an exemplary embodiment of the present invention, the method for dynamically detecting service hotspots based on Java Agent includes at least the following steps:
[0048] S10, Configure Java proxy parameters in the JVM startup parameters of the target application service, wherein the Java proxy parameters point to the path of the proxy JAR package;
[0049] S20, the target application service is started, the JVM loads and initializes the Java Agent in the agent JAR package according to the Java agent parameters, and the Java Agent performs bytecode enhancement on the predetermined target methods in the target application service to inject monitoring logic;
[0050] S30, through the implanted monitoring logic, the execution information of the enhanced target method is collected in real time when the enhanced target method is executed;
[0051] S40, perform real-time analysis of the execution information according to at least one preset dynamic rule;
[0052] S50, when the real-time analysis results meet the dynamic rules, the target method is determined to be a hotspot method.
[0053] In some implementations, the method further includes: pre-installing the proxy JAR package to a specified file path on the target server running the target application service.
[0054] In some implementations, the preset dynamic rules include at least one of the following:
[0055] First rule: Within a preset first time window, the number of times the target method is called exceeds a first threshold;
[0056] Second rule: Within a preset second time window, the average execution time of the target method exceeds a second threshold.
[0057] For example, if the current interface processes more than 5000 requests within 10 minutes, or if the average execution time of the interface exceeds 5 seconds, then the current method is marked as a hot method. In this example, the first time window and the second time window are the same, both being 10 minutes. Optionally, the first time window and the second time window can be different.
[0058] In some implementations, the JVM startup parameters also include an alarm recipient parameter, which specifies the alarm recipient.
[0059] In some implementations, the method further includes: when the target method is determined to be a hotspot method, triggering an early warning notification to a designated alarm receiver.
[0060] In some implementations, the method of triggering the warning notification includes at least one of the following: WeChat notification, telephone notification, and email notification.
[0061] In some implementations, the method further includes: if no specific alarm receiver is configured, printing an early warning log when the target method is determined to be a hotspot method.
[0062] In some implementations, the target method is a class or method in the target application service that has a specified annotation.
[0063] In some implementations, the execution information includes at least one or more of the following: method identifier, number of calls, execution start time, and execution end time.
[0064] In some implementations, the method further includes providing a visualization page to display the execution information and / or the determination results of the hotspot method in real time.
[0065] In some implementations, the specified annotation includes the `@RestController` annotation. When an external service requests the target application service, the Java Agent provided by this invention automatically records the number of times the current controller requests, the start time, the end time, and the request method path, and synchronizes this real-time data to the visualization page. If the current interface processes more than 5000 requests within 10 minutes, or the average execution time of the interface exceeds 5 seconds, the Java Agent marks the current method as a hot method and notifies the configured alarm receiver via WeChat, informing them of the hot method's execution count and average execution time. If no alarm receiver is configured, only an alarm log is printed, and no alarm is issued. If it is not a hot method, only the real-time data is synchronized to the visualization page.
[0066] Reference Figure 2 Another embodiment of the present invention relates to a system for implementing the method described in any embodiment of the present invention. For example... Figure 2 As shown, a system for dynamically detecting service hotspots based on Java Agents includes:
[0067] The proxy configuration module 2100 is used to configure Java proxy parameters in the Java Virtual Machine (JVM) startup parameters of the target application service, wherein the Java proxy parameters point to the path of the proxy JAR package;
[0068] The bytecode enhancement module 2200 is used to load and initialize the Java Agent in the agent JAR package by the JVM according to the Java agent parameters when the target application service is started, and to enhance the bytecode of the predetermined target method in the target application service through the Java Agent in order to inject monitoring logic.
[0069] The data collection and real-time analysis module 2300 is used to: collect execution information of the enhanced target method in real time when the enhanced target method is executed through the implanted monitoring logic; perform real-time analysis of the execution information according to at least one preset dynamic rule; and determine the target method as a hotspot method when the real-time analysis result satisfies the dynamic rule.
[0070] In some embodiments, the system further includes an early warning module 2400, which is used to trigger an early warning notification to a designated alarm recipient or trigger the printing of an early warning log when the target method is determined to be a hot method.
[0071] In some implementations, the system further includes a visualization module 2500, which provides a visualization page to display the execution information and / or the determination results of the hotspot method in real time.
[0072] It should be understood that the steps, processes, and operations described in the above embodiments can be implemented by computer software programs. Therefore, the embodiments of the present invention also relate to a computer program product, which includes a computer program that, when executed by a processor, implements the steps, processes, or operations of the method described in any embodiment of the present invention. In some embodiments, program code for executing the computer program of the embodiments of the present invention can be written in any combination of one or more programming languages. For example, the computer program can be written using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, languages such as Java, C++, Python, "C", or similar programming languages. The program code can be executed entirely on a personal computing device, partially on a personal computing device, partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the personal computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0073] It should also be understood that the computer program product may be stored on a computer-readable storage medium, such as hard disks, floppy disks, magnetic tapes, optical disks, solid-state drives, flash memory, etc.
[0074] Furthermore, it can be understood that the method of any embodiment of the present invention can be executed by a computer device. Accordingly, embodiments of the present invention also relate to a computer device comprising: a memory storing a computer program thereon; and a processor that, when executing the computer program, implements the steps (processing, operations, etc.) of the method described in any embodiment of the present disclosure.
[0075] Figure 3 An exemplary structure of a computer device is shown. Figure 3 As shown, the computer device 100 may include at least a processor 101 and a memory 102, wherein the memory 102 may be or include a storage medium storing a computer program (or computer-readable instructions). The processor 101 executes the computer program to perform some or all of the operations described in any embodiment of this disclosure, including but not limited to: S10, configuring Java agent parameters in the JVM startup parameters of the target application service, wherein the Java agent parameters point to the path of the agent JAR package; S20, starting the target application service, wherein the JVM loads and initializes the Java Agent in the agent JAR package according to the Java agent parameters, and performs bytecode enhancement on a predetermined target method in the target application service through the Java Agent to implant monitoring logic; S30, collecting execution information of the enhanced target method in real time when it is executed through the implanted monitoring logic; S40, performing real-time analysis on the execution information according to at least one preset dynamic rule; S50, determining the target method as a hot method when the real-time analysis result satisfies the dynamic rule.
[0076] In some embodiments, the computer device 100 may further include a data storage device 103, a display 104, a speaker 105, and a communication module 106. The processor 101, memory 102, and data storage device 103 communicate with each other via a bus and interact with peripheral devices, such as the display 104 and communication module 106, via the bus and I / O module 107.
[0077] Specifically, the data storage device 103 can store application programs and their various configuration files and data. The memory 102 stores computer programs. The processor 101 executes the computer programs to perform various processes, operations, or steps described in any embodiment of the present invention. The display 104 can be used to display various data, images, etc.
[0078] In optional embodiments, the communication module 106 may be omitted where communication with the other systems, devices, or equipment is not required. In some embodiments, the computer device 100 may further include a speaker 105 for voice output.
[0079] In some implementations, processor 101 may include any suitable semiconductor-based electronic processing unit, chip, microchip, or integrated circuit (IC). Memory 102 is a programmable memory, which may include any suitable electronic storage device configured to store instructions and be reprogrammable. For example, programmable memory may include an erasable programmable read-only memory (EPROM) device. Data storage device 103 may be a persistent storage device, which may include any suitable electronic storage configured to retain stored information as power cycles. For example, data storage device 103 may include a hard disk drive, solid-state drive (SSD), flash memory drive, hybrid drive, etc., or any combination thereof.
[0080] Therefore, processor 101 can control the output of information on I / O module 107 by storing information in memory and / or executing programs / instructions stored in memory. For example, several aspects of the methods described herein can be executed by processor 101 according to programs / instructions stored in memory (e.g., memory 102 and / or data storage device 103).
[0081] Furthermore, the processor 101 can electronically communicate with the I / O module 107 and / or the communication module 106 to receive or send relevant instructions and information. The I / O module 107 may include any suitable mechanical or virtual user interface configured to enable a user to interact with the computer device 100 or to allow the user to perform one or more functions of the computer device 100 itself, such as a graphical user interface (GUI) on a screen or other display. In some instances, the user interface may include a voice interface capable of speech recognition, through which an operator can provide voice commands to the processor.
[0082] The communication module 106 may include any suitable devices and / or structures configured to facilitate information exchange between the computer device 100 and external electronic devices. The communication module 106 may include devices configured to send and / or receive wireless or wired information with other devices. For example, the communication module 106 may include an antenna, a transceiver, a connector for wired reception and / or transmission of data, a data exchange device, etc., or any combination thereof. The communication module 106 may also include ancillary components, such as filtering circuits, encryption / decryption circuits, and / or integrated circuit (IC) chips for processing signals (e.g., (Chip). In some implementations, the communication module 106 may include a WiFi device configured to connect to a local wireless network.
[0083] In some implementations, computer device 100 may include a smartphone, wearable computer, portable / mobile electronic device, tablet computer, smartwatch, personal digital assistant (PDA), personal computer (PC), desktop computer, laptop computer, server, etc. Computer device 100 may include or have installed one or more application programs (APPs), one of which is configured to perform the Java Agent-based dynamic service hotspot detection method described herein.
[0084] Although not shown, it should be understood that the computer device 100 also includes a power supply component, which may include any suitable device and / or structure configured to provide an electrical interface between the computer device 100 and a power source. The power source may include any suitable source of electrical energy, such as a battery, socket, capacitor, fuel cell, etc., or any combination thereof. Additionally or optionally, the power source may be included within the power supply component. For example, a battery or battery pack may be included within the computer device 100. In some embodiments, the battery may be rechargeable, for example, charged via a cable or an interface provided by the power supply component. In some embodiments, the power supply component may share features with or repeat features of the communication module 106. For example, a USB or micro-USB cable connector may be included in the computer device 100, so that power supply or data communication is performed by the same component.
[0085] Based on the above embodiments, the solution of the agent-based dynamic detection service hotspot method proposed in this invention has the following advantages:
[0086] Easy to use and efficient: The JAR package path is specified via JVM parameters, simplifying operation and improving system integration and usage efficiency. Simultaneously, the alerting method is convenient, allowing application administrators to obtain information promptly.
[0087] Non-intrusive and flexible access: Unified standards lead to technical accumulation, ensuring no intrusion into business code and flexible access methods that do not affect the original business logic, thus reducing maintenance costs.
[0088] Real-time monitoring and analysis: Provides a visual interface that allows users to view hot methods in real time, instantly identify method performance bottlenecks, and provide strong support for system performance optimization.
[0089] Those skilled in the art should understand that the above disclosure is merely illustrative of embodiments of the present invention, and the scope of patent protection claimed in this application is not limited thereto. Various modifications, alterations, substitutions, and other changes can be made to the embodiments disclosed herein without departing from the spirit of the invention, and such changes are within the scope covered by the claims of this application.
Claims
1. A method for dynamically detecting service hotspots based on Java Agent, characterized in that, Includes the following steps: Configure Java proxy parameters in the JVM startup parameters of the target application service, wherein the Java proxy parameters point to the path of the proxy JAR package; The target application service is started, and the JVM loads and initializes the Java Agent in the agent JAR package according to the Java agent parameters. The Java Agent then performs bytecode enhancement on the predetermined target methods in the target application service to inject monitoring logic. Through the implanted monitoring logic, the execution information of the enhanced target method is collected in real time when the method is executed. The execution information is analyzed in real time according to at least one preset dynamic rule; When the real-time analysis results meet the dynamic rules, the target method is determined to be a hotspot method.
2. The method according to claim 1, characterized in that, Also includes: The proxy JAR package is pre-installed to a specified file path on the target server running the target application service.
3. The method according to claim 1, characterized in that, The preset dynamic rules include at least one of the following: First rule: Within a preset first time window, the number of times the target method is called exceeds a first threshold; Second rule: Within a preset second time window, the average execution time of the target method exceeds a second threshold.
4. The method according to claim 1, characterized in that, The JVM startup parameters also include an alarm recipient parameter, which is used to specify the alarm recipient.
5. The method according to claim 4, characterized in that, Also includes: When the target method is identified as a hot method, an early warning notification is triggered and sent to the designated alarm receiver.
6. The method according to claim 5, characterized in that, The methods for triggering early warning notifications include at least one of the following: enterprise WeChat notification, telephone notification, and email notification.
7. The method according to claim 4, characterized in that, Also includes: If no alarm receiver is configured, an early warning log will be printed when the target method is identified as a hotspot method.
8. The method according to claim 1, characterized in that, The target method is a class or method in the target application service that has a specified annotation.
9. The method according to claim 8, characterized in that, The specified annotation includes the @RestController annotation.
10. The method according to claim 1, characterized in that, The execution information includes at least one or more of the following: method identifier, number of calls, execution start time, and execution end time.
11. The method according to any one of claims 1 to 10, characterized in that, Also includes: A visualization page is provided to display the execution information and / or the determination results of the hotspot methods in real time.
12. A system for dynamically detecting service hotspots based on a Java Agent, characterized in that, The system for implementing the method as described in any one of claims 1 to 11 includes: The proxy configuration module is used to configure Java proxy parameters in the Java Virtual Machine (JVM) startup parameters of the target application service, wherein the Java proxy parameters point to the path of the proxy JAR package; The bytecode enhancement module is used to load and initialize the Java Agent in the agent JAR package by the JVM according to the Java agent parameters when the target application service is started, and to enhance the bytecode of the predetermined target methods in the target application service through the Java Agent in order to inject monitoring logic. The data collection and real-time analysis module is used to: collect execution information of the enhanced target method in real time when the enhanced target method is executed through the implanted monitoring logic; perform real-time analysis of the execution information according to at least one preset dynamic rule; and determine the target method as a hotspot method when the real-time analysis result satisfies the dynamic rule.
13. The system according to claim 12, characterized in that, Also includes: The early warning module is used to trigger an early warning notification to a designated alarm recipient or to trigger the printing of an early warning log when the target method is determined to be a hot method.
14. The system according to claim 12 or 13, characterized in that, Also includes: The visualization module is used to provide a visualization page to display the execution information and / or the determination results of the hotspot methods in real time.
15. A computer program product comprising a computer program, characterized in that, When executed by a processor, the computer program performs the steps of the method according to any one of claims 1 to 11.
16. A computer device, characterized in that, include: A memory on which computer programs are stored; A processor that, when executing the computer program, implements the steps of the method according to any one of claims 1 to 11.