Non-intrusive thread pool dynamic management method and system

Through Java Agent technology and bytecode enhancement, dynamic management of thread pool parameters and adaptive queue adjustment are achieved, which solves the flexibility and intrusiveness problems of thread pool management and provides thread pool optimization capabilities with zero code modification.

CN120653454AActive Publication Date: 2025-09-16SSE INFORMATION NETWORK LTD

Patent Information

Application Number
CN202511165643.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-20
Publication Date
2025-09-16
Estimated Expiration
2045-08-20

AI Technical Summary

Technical Problem

Existing thread pool management methods lack flexibility and timeliness. Static configuration adjustments require restarting the application, while dynamic management is costly and intrusive to the program.

Method used

The Java Agent intercepts the loading request of the thread pool class and performs bytecode enhancement. Combined with the configuration of the monitoring service and the adaptive queue capacity adjustment algorithm, dynamic management of thread pool parameters and adaptive adjustment of task queues are achieved.

Benefits of technology

It enables transparent adjustment of thread pool parameters at runtime without modifying application code. It has adaptive scaling capabilities, reduces transformation costs and risks, and is suitable for various thread pool usage scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120653454A_ABST
    Figure CN120653454A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data management, and provides a non-intrusive thread pool dynamic management method and system.The method comprises the steps that S1, in the application program loading stage of a virtual machine, a loading request of a thread pool class is intercepted through a Java Agent; s2, performing byte code enhancement processing on the thread pool class; s3, dynamic management during operation: S31, when the configuration monitoring service monitors configuration change, initiating adjustment of related thread pool parameters, and S32, when a monitoring reporting period is reached, reporting the collected indexes; and S33, a blocking queue type set in the thread pool parameters is a bounded queue, and corresponding capacity expansion and capacity reduction operations are performed according to a self-adaptive queue capacity adjustment algorithm in combination with the acquired monitoring indexes. The method has the core advantages of zero transformation cost, fast dynamic response and strong framework compatibility, and provides a thread pool optimization capability which is ready to use when the box is opened for a high-concurrency system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data management technology, and in particular to a non-intrusive thread pool dynamic management method and system. Background Art

[0002] In the prior art, thread pool adjustment methods mainly include the following methods: Static configuration adjustment loads core thread pool parameters, such as the number of core threads, maximum number of threads, thread active time, and task queue length, from a configuration file during program initialization. Once loaded, these parameters cannot be adjusted during runtime. Adjusting these parameters requires modifying the configuration file and restarting the application, making timely adjustments impossible in the face of sudden traffic and load surges.

[0003] By redeveloping the native thread pool or introducing a specific framework for dynamic management, this method will redevelop the native thread pool of JDK or introduce third-party dependencies, which is invasive to the original program code and has high modification and maintenance costs.

[0004] In summary, the existing thread pool management method has the following disadvantages: 1) Lack of flexibility and timeliness. Using static configuration adjustments requires restarting the application, and it is impossible to make timely adjustments based on actual conditions during program operation.

[0005] 2) It is invasive to the program and requires modifying the program code and introducing a new customized thread pool to achieve dynamic parameter management. This may damage the original program logic, resulting in high modification costs and risks. Summary of the Invention

[0006] In order to help solve the above technical problems, the present application provides a non-intrusive thread pool dynamic management method and system.

[0007] In a first aspect, the present application provides a non-intrusive thread pool dynamic management method, which includes: S1. During the application loading phase of the virtual machine, the Java Agent intercepts the thread pool class loading request; S2. Perform bytecode enhancement on the thread pool class, including: S21. Add a configuration listening service to the thread pool construction method and bind the thread pool parameters to the configuration center. The thread pool parameters include the maximum number of threads, the number of core threads, the blocking queue type, the thread keepalive time and the rejection policy; S22. Indicator collection is performed before, during, and after the execution of the thread pool. Various monitoring indicators are periodically collected and reported to the monitoring module during the thread pool operation. The monitoring indicators include task execution time, number of active threads, blocking queue length, and number of rejection policy executions. S3. Dynamic management at runtime, including: S31. When the configuration monitoring service detects a configuration change, it initiates adjustments to the relevant thread pool parameters. S32. When the monitoring reporting cycle is reached, the collected indicators are reported; S33. The blocking queue type set in the thread pool parameters is a bounded queue. According to the adaptive queue capacity adjustment algorithm, the corresponding expansion and contraction operations are performed in combination with the collected monitoring indicators.

[0008] Preferably, the S33 includes: the adaptive queue capacity adjustment algorithm includes: Expansion operation: The expansion score ES is calculated using a multi-factor weighted composite formula: , where W1-W4 are the weights of different factors, Waitavg is the average waiting time of the task, Waitth is the waiting time threshold, q is the current waiting task queue length, Capacity is the queue capacity, Taskreject is the number of tasks that trigger the rejection policy, Taskall is the total number of executed tasks, Thact is the number of active threads in the thread pool, and Thmax is the maximum number of threads; When the ES value is greater than the preset expansion threshold and the system resources are sufficient, the expansion operation is performed and atomic queue migration is executed.

[0009] Preferably, the S33 includes: the adaptive queue capacity adjustment algorithm includes: Scaling operation: The shrinkage score is calculated using a multi-factor weighted composite formula: , where W5-W7 are the weights of different factors, Thact is the number of active threads in the thread pool, Thmax is the maximum number of threads, Tasksub is the number of task submissions in the time window, Ratepeak is the peak arrival rate of the task, and Twindow is the statistical time window; When the SS values ​​of a preset number of consecutive collection cycles exceed the preset shrinking threshold and there is no shrinking operation within the preset operation time, a shrinking operation is performed.

[0010] Preferably, the S2 includes: Intercept JVM class loading requests and identify thread pool classes; Modify the construction method of the loading request to inject the configuration listening service; Enhance the task execution method to insert indicator collection logic; Return the enhanced bytecode to the JVM for loading.

[0011] Preferably, the S3 includes: Periodically collect monitoring indicators and calculate decision factors; Trigger queue adjustments based on expansion / contraction conditions; Record capacity change events and generate adjustment reports.

[0012] In a second aspect, the present application provides a non-intrusive thread pool dynamic management system, wherein the non-intrusive thread pool dynamic management method as described in any one of the first aspects is adopted, including: Java Agent module, used to intercept the bytecode of the thread pool class when the virtual machine loads the application; Bytecode enhancement engine, used to enhance the construction method of thread pool class; A configuration monitoring module is injected into the thread pool construction method through the bytecode enhancement engine to dynamically bind thread pool parameters with the configuration center. The thread pool parameters include the maximum number of threads, the number of core threads, the blocking queue type, the thread keepalive time, and the rejection policy. An indicator collection module, which is injected into the thread pool task execution method through the bytecode enhancement engine, and is used to periodically collect and report thread pool runtime indicators; The task queue capacity adjustment module is used to perform adaptive queue capacity adjustment based on the collected monitoring indicators when the thread pool adopts a bounded blocking queue.

[0013] In summary, compared with the prior art, the present invention has the following advantages: 1. It is transparent to the application and does not require any modification to the existing application. Through bytecode interception technology, the -javaagent parameter is added when the program is started to manage and monitor the thread pool parameters.

[0014] 2. Implement adaptive adjustment of the thread pool task queue. Through a multi-dimensional decision-making model, assign different weights to different decision factors for comprehensive judgment, automatically expand and shrink the task queue, and introduce anti-jitter protection to avoid frequent triggering of shrinkage.

[0015] The method of the present invention is universal and effective not only for thread pools in business programs, but also for any program that uses thread pools, such as common components and frameworks such as Tomcat and Dubbo. It can easily customize the thread pool parameters in basic components. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 This is a schematic diagram of the bytecode enhancement principle in the present invention; Figure 2 A schematic block diagram of a non-intrusive thread pool dynamic management method of the present invention; Figure 3This is a flowchart of bytecode enhancement using Java Agent technology in the present invention.

[0017] Figure 4 This is a flowchart of the task queue adaptive adjustment in the present invention. DETAILED DESCRIPTION

[0018] The present invention will be further described below with reference to the accompanying drawings. The structure and principle of the present invention will be very clear to those skilled in the art. It should be understood that the specific embodiments described herein are only intended to explain the present invention and are not intended to limit the present invention.

[0019] Figure 1 The bytecode enhancement principle diagram of the present invention includes the following three basic elements: the application containing the thread pool is a business application written in Java. The Java Agent component contains the bytecode enhancement engine, a special JAR package that can modify and enhance the bytecode of the thread pool class in the business application. The JVM virtual machine is the Java environment that runs the application.

[0020] Figure 2 Schematic diagram of a non-intrusive thread pool dynamic management method of the present invention, the method comprising: S1. During the application loading phase of the virtual machine, the Java Agent intercepts the thread pool class loading request; S2. Perform bytecode enhancement on the thread pool class, including: S21. Add a configuration listening service to the thread pool construction method and bind the thread pool parameters to the configuration center. The thread pool parameters include the maximum number of threads, the number of core threads, the blocking queue type, the thread keepalive time and the rejection policy; S22. Indicator collection is performed before, during, and after the execution of the thread pool. Various monitoring indicators are periodically collected and reported to the monitoring module during the thread pool operation. The monitoring indicators include task execution time, number of active threads, blocking queue length, and number of rejection policy executions. S3. Dynamic management at runtime, including: S31. When the configuration monitoring service detects a configuration change, it initiates adjustments to the relevant thread pool parameters. S32. When the monitoring reporting cycle is reached, the collected indicators are reported; S33. The blocking queue type set in the thread pool parameters is a bounded queue. According to the adaptive queue capacity adjustment algorithm, the corresponding expansion and contraction operations are performed in combination with the collected monitoring indicators.

[0021] In the embodiment of the present application, the startup parameter is -javaagent, the agent component is Java Agent, and the virtual machine is a JVM virtual machine.

[0022] S33 includes: The adaptive queue capacity adjustment algorithm includes: Expansion operation: Calculate the expansion score value through a multi-factor weighted composite formula ES : ,in W 1- W 4 is the weight of different factors, Wait avg is the average waiting time of the task, Wait th is the waiting time threshold, q is the current waiting task queue length, Capacity is the queue capacity, Task reject To trigger the rejection policy task number, Task all is the total number of tasks executed, Th act is the number of active threads in the thread pool, Th max is the maximum number of threads; when ES When the value is greater than the preset expansion threshold and system resources are sufficient, the expansion operation is performed and atomic queue migration is executed.

[0023] Scaling operation: The shrinkage score is calculated using a multi-factor weighted composite formula: ,in, W 5 - W 7 are the weights of different factors, Th act is the number of active threads in the thread pool, Th max is the maximum number of threads, Task sub is the number of task submissions within the time window, Rate peak is the peak arrival rate of the task, T window is the statistical time window; When the preset number of acquisition cycles is continuous SS When all values ​​exceed the preset shrinking threshold and no shrinking operation occurs within the preset operation time, a shrinking operation is performed.

[0024] Specifically, the configuration center is responsible for distributing thread pool parameters at runtime. After bytecode enhancement via the Java Agent component, the application's thread pool now has the capabilities for parameter monitoring, metrics collection, and dynamic adjustment. Once instantiated, the enhanced thread pool can monitor parameter changes in the configuration center and dynamically adjust thread pool parameters at runtime. Monitoring metrics can be periodically reported through monitoring points. When the thread pool task queue uses a bounded queue, the task queue capacity can be adaptively calculated and adjusted based on collected metrics.

[0025] S2 includes: Intercept JVM class loading requests and identify thread pool classes; Modify the construction method of the loading request to inject the configuration listening service; Enhance the task execution method to insert indicator collection logic; Return the enhanced bytecode to the JVM for loading.

[0026] 1. During the application loading phase of the virtual machine, the bytecode enhancement technology of the Java agent is used to enhance the bytecode of the thread pool related classes without any code intrusion into the application. The enhancement process is as follows: Figure 3 , 1) The business application is started using the -javaagent parameter. 2) The bytecode enhancement engine intercepts the virtual machine's class loading request, 3) Determine whether the loaded class is a thread pool class. If so, execute step 4) Otherwise, intercept the next class. 4) Get the bytecode of the thread pool class, 5) Add a configuration listening service to its constructor to bind thread pool parameters to the configuration center. These parameters include the maximum number of threads, the number of core threads, the blocking queue type, the thread keepalive time, and the rejection policy. Metrics are collected before, during, and after the thread pool execution method. Various thread pool runtime metrics, including task execution time, the number of active threads, the actual length of the blocking queue, and the number of rejection policy executions, are periodically collected and reported to the monitoring module.

[0027] 6) The enhanced class bytecode is handed over to the virtual machine to load and instantiate.

[0028] S3 includes: Periodically collect monitoring indicators and calculate decision factors; Trigger queue adjustments based on expansion / contraction conditions; Record capacity change events and generate adjustment reports.

[0029] 2. During the dynamic management phase at runtime, when the configuration monitoring service detects a configuration change, it initiates adjustments to the relevant thread pool parameters. When the monitoring reporting period arrives, the collected metrics are reported.

[0030] Furthermore, if the blocking queue type set in the above thread pool parameters is a bounded queue, then the adaptive queue capacity adjustment algorithm is used in combination with the collected monitoring indicators to perform corresponding expansion and contraction operations. For the specific process, refer to Figure 4 .

[0031] 1) After the thread pool is started, periodic monitoring indicators are collected.

[0032] 2) Use the multi-factor weighted composite calculation of the acquisition indicators to expand the capacity. The formula is: , where W 1- W 4 is the weight of different factors, Wait avg is the average waiting time of the task, Wait th is the waiting time threshold, q is the current waiting task queue length, Capacity is the queue capacity, Task reject To trigger the rejection policy task number, Task all is the total number of tasks to be executed, Th act is the number of active threads in the thread pool, Th max The maximum number of threads.

[0033] when ES If the value is greater than the set threshold and the CPU load is sufficient in the case of heap memory resources, the expansion operation is performed to create a new task queue with 150% of the current queue capacity and perform atomic queue migration. Expansion operation: The expansion score is calculated according to the first multi-factor weighted formula. When the score exceeds the expansion threshold and the system resources are sufficient, the queue capacity is expanded to 150% of the current capacity; 3) Use the collected indicators to perform multi-factor weighted composite calculation of shrinkage. The formula is: , where W 5 - W 7 are the weights of different factors, Th act is the number of active threads in the thread pool, Th max is the maximum number of threads, Task sub is the number of task submissions within the time window, Rate peak is the peak arrival rate of the task, Twindow The statistical time window.

[0034] When three consecutive cycles SS If all values ​​are greater than the reduction threshold and no reduction operation has been performed within 60 seconds before the current time, the queue capacity is reduced to 90% of the current value, and the reduction operation time is recorded. Reduction operation: The reduction score is calculated based on the second multi-factor weighted formula. If the score exceeds the reduction threshold for three consecutive collection cycles and more than 60 seconds have passed since the last reduction operation, the queue capacity is reduced to 90% of the current capacity.

[0035] 4) After the adaptive adjustment of the triggered queue is completed, the queue capacity change event is recorded and an adjustment report is generated.

[0036] Through the above-mentioned implementation, the present invention innovatively introduces Java Agent technology, enabling runtime parameter adjustment and indicator monitoring of thread pools without code intrusion into the program, and also proposes an adaptive task queue adjustment method. This solves the problems of thread pool parameters being unable to be dynamically modified at runtime and queue size adjustment being delayed. Furthermore, the present invention eliminates the need for secondary code development for JDK's native thread pool, is non-invasive to applications, and reduces development and deployment costs for technical researchers. It has broad application prospects and practical value in fields such as cloud computing and microservices.

[0037] The present invention also proposes a non-intrusive thread pool dynamic management system, which adopts the above-mentioned non-intrusive thread pool dynamic management method, and the system includes: Java Agent module, used to intercept the bytecode of the thread pool class when the virtual machine loads the application; Bytecode enhancement engine, used to enhance the construction method of thread pool class; A configuration monitoring module is injected into the thread pool construction method through the bytecode enhancement engine to dynamically bind thread pool parameters with the configuration center. The thread pool parameters include the maximum number of threads, the number of core threads, the blocking queue type, the thread keepalive time, and the rejection policy. An indicator collection module, which is injected into the thread pool task execution method through the bytecode enhancement engine, and is used to periodically collect and report thread pool runtime indicators; The task queue capacity adjustment module is used to perform adaptive queue capacity adjustment based on the collected monitoring indicators when the thread pool adopts a bounded blocking queue.

[0038] In summary, this invention, based on Java Agent technology, implements dynamic management with zero code intrusion, supporting millisecond-level hot updates of parameters such as the number of core threads, maximum number of threads, and queue capacity, without the need to restart applications or modify business code. It also provides adaptive control of thread pool task queues and innovatively proposes a bidirectional elastic scaling algorithm that integrates multiple dimensional indicators such as task waiting time, thread idle rate, and system load to achieve intelligent expansion / contraction decisions. Compared with traditional solutions, this approach offers the core advantages of zero modification cost, fast dynamic response, and strong framework compatibility, providing out-of-the-box thread pool optimization capabilities for high-concurrency systems.

Claims

1. A non-intrusive thread pool dynamic management method, characterized in that: include: S1. During the application loading phase of the virtual machine, the Java Agent intercepts the thread pool class loading request; S2. Perform bytecode enhancement on the thread pool class, including: S21. Add a configuration listening service to the thread pool construction method and bind the thread pool parameters to the configuration center. The thread pool parameters include the maximum number of threads, the number of core threads, the blocking queue type, the thread keepalive time and the rejection policy; S22. Indicator collection is performed before, during, and after the execution of the thread pool. Various monitoring indicators are periodically collected and reported to the monitoring module during the thread pool operation. The monitoring indicators include task execution time, number of active threads, blocking queue length, and number of rejection policy executions. S3. Dynamic management at runtime, including: S31. When the configuration monitoring service detects a configuration change, it initiates adjustments to the relevant thread pool parameters. S32. When the monitoring reporting cycle is reached, the collected indicators are reported; S33. The blocking queue type set in the thread pool parameters is a bounded queue. According to the adaptive queue capacity adjustment algorithm, the corresponding expansion and contraction operations are performed in combination with the collected monitoring indicators.

2. The non-intrusive thread pool dynamic management method according to claim 1, characterized in that: The S33 includes: the adaptive queue capacity adjustment algorithm includes: Expansion operation: Calculate the expansion score value through a multi-factor weighted composite formula ES : ,in W 1- W 4 is the weight of different factors, Wait avg is the average waiting time of the task, Wait th is the waiting time threshold, q is the current waiting task queue length, Capacity is the queue capacity, Task reject To trigger the rejection policy task number, Task all is the total number of tasks executed, Th act is the number of active threads in the thread pool, Th max is the maximum number of threads; when ES When the value is greater than the preset expansion threshold and system resources are sufficient, the expansion operation is performed and atomic queue migration is executed.

3. The non-intrusive thread pool dynamic management method according to claim 2, characterized in that: The S33 includes: the adaptive queue capacity adjustment algorithm includes: Scaling operation: The shrinkage score is calculated using a multi-factor weighted composite formula: ,in, W 5 - W 7 are the weights of different factors, Th act is the number of active threads in the thread pool, Th max is the maximum number of threads, Task sub is the number of task submissions within the time window, Rate peak is the peak arrival rate of the task, T window is the statistical time window; When the preset number of acquisition cycles is continuous SS When all values ​​exceed the preset shrinking threshold and no shrinking operation occurs within the preset operation time, a shrinking operation is performed.

4. The non-intrusive thread pool dynamic management method according to claim 1, characterized in that: The S2 includes: Intercept JVM class loading requests and identify thread pool classes; Modify the construction method of the loading request to inject the configuration listening service; Enhance the task execution method to insert indicator collection logic; Return the enhanced bytecode to the JVM for loading.

5. The non-intrusive thread pool dynamic management method according to claim 1, characterized in that: The S3 includes: Periodically collect monitoring indicators and calculate decision factors; Trigger queue adjustments based on expansion / contraction conditions; Record capacity change events and generate adjustment reports.

6. A non-intrusive thread pool dynamic management system, characterized in that: The non-intrusive thread pool dynamic management method according to any one of claims 1 to 5 is adopted, comprising: Java Agent module, used to intercept the bytecode of the thread pool class when the virtual machine loads the application; Bytecode enhancement engine, used to enhance the construction method of thread pool class; A configuration monitoring module is injected into the thread pool construction method through the bytecode enhancement engine to dynamically bind thread pool parameters with the configuration center. The thread pool parameters include the maximum number of threads, the number of core threads, the blocking queue type, the thread keepalive time, and the rejection policy. An indicator collection module, which is injected into the thread pool task execution method through the bytecode enhancement engine, and is used to periodically collect and report thread pool runtime indicators; The task queue capacity adjustment module is used to perform adaptive queue capacity adjustment based on the collected monitoring indicators when the thread pool adopts a bounded blocking queue.

Citation Information

Patent Citations

  • Terminal application behavior reflection processing method

    CN110362301A

  • Server processing method and device, electronic equipment and computer readable medium

    CN115048279A

  • Message transmission method and device

    CN115242728A

  • Method and system for dynamically adjusting parameters of thread pool during operation, medium and terminal

    CN115686785A

  • Middle station service model monitoring system

    CN115729784A

Cited By

  • Tomcat container application thread pool isolation method and device based on Java Agent and medium

    CN121918940A