Method and system for dynamically adjusting third-party thread pool
By injecting default configuration parameters when initializing third-party components and adjusting the thread pool and queue size in real time, the problem of unreasonable resource allocation of thread pools is solved, and the stability and reliability of the system are improved.
Patent Information
- Application Number
- CN202510257964.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-05
- Publication Date
- 2025-07-22
AI Technical Summary
In the prior art, the maximum number of threads and the maximum capacity of the task queue are usually fixed, and the lack of a dynamic adjustment mechanism leads to unreasonable resource allocation in the system when the load fluctuates, which may lead to performance bottlenecks, memory overflows or excessive thread creation, affecting system stability and reliability.
Inject preset default configuration parameters when initializing third-party components, including the maximum number of threads in the thread pool and the maximum capacity of the task queue, and adjust dynamic configuration parameters in real time to adapt to resource requirements in different business scenarios, and optimize visual display with monitoring tools.
It improves the readability of monitoring tools, avoids the risk of memory overflow, improves the stability and reliability of the system, and adapts to resource needs in different business scenarios.
Smart Images

Figure CN120353571A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular, to a method and system for dynamically adjusting a third-party thread pool. Background Art
[0002] The main problem of the prior art is that the maximum number of threads in the thread pool and the maximum capacity of the task queue are usually fixed, and the configuration parameters lack a dynamic adjustment mechanism. In practical applications, when the system load fluctuates greatly, static configuration may lead to unreasonable resource allocation. For example, setting the maximum number of threads in the thread pool too large may cause waste of system resources; while setting it too small, it cannot meet the business requirements in high-concurrency scenarios, thus causing performance bottlenecks. More seriously, if the configuration of the thread pool fails to be adjusted in real time according to actual needs, even with the limit of the upper limit value, memory overflow (OOM) or excessive thread creation may still occur, ultimately affecting the stability and reliability of the system.
[0003] For the above problems, no effective solution has been proposed yet. Summary of the Invention
[0004] Embodiments of the present invention provide a method and system for dynamically adjusting a third-party thread pool to at least solve the technical problem of system instability caused by unreasonable setting of dynamic configuration parameters in the prior art.
[0005] According to one aspect of the embodiments of the present invention, a method for dynamically adjusting a third-party thread pool is provided, including: when a third-party component is initialized, injecting preset default configuration parameters into the thread pool, where the default configuration parameters include the maximum number of threads in the thread pool and the maximum capacity of the task queue; based on the obtained dynamic configuration parameters, performing real-time adjustment on the maximum number of threads in the thread pool and the maximum capacity of the task queue to adapt to the resource requirements of different business scenarios.
[0006] According to another aspect of the embodiments of the present invention, a system for dynamically adjusting a third-party thread pool is further provided, including: an injection module configured to inject preset default configuration parameters into the thread pool when a third-party component is initialized, where the default configuration parameters include the maximum number of threads in the thread pool and the maximum capacity of the task queue; an adjustment module configured to perform real-time adjustment on the maximum number of threads in the thread pool and the maximum capacity of the task queue based on the obtained dynamic configuration parameters to adapt to the resource requirements of different business scenarios.
[0007] In the embodiments of the present invention, when a third-party component is initialized, preset default configuration parameters are injected into a thread pool, where the default configuration parameters include the maximum number of threads in the thread pool and the maximum capacity of the task queue; based on the obtained dynamic configuration parameters, the maximum number of threads in the thread pool and the maximum capacity of the task queue are adjusted in real time to adapt to the resource requirements of different business scenarios. Through the above solution, the technical problem of system instability caused by unreasonable setting of dynamic configuration parameters in the prior art is solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] The drawings described herein are used to provide a further understanding of the present invention, form a part of this application, and the illustrative embodiments and descriptions of the present invention are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0009] Figure 1 is a flowchart of an optional method for dynamically adjusting a third-party thread pool according to an embodiment of the present invention;
[0010] Figure 2 is a monitoring interface diagram of tomcat according to the prior art;
[0011] Figure 3 is a monitoring interface diagram of okhttp3 according to the prior art;
[0012] Figure 4 is a flowchart of an optional method for a dynamic-tp to adapt to a third-party thread pool according to an embodiment of the present invention;
[0013] Figure 5 is a screenshot of the code for modifying tomcat according to an embodiment of the present invention;
[0014] Figure 6 is a screenshot of the code for modifying okhttp3 according to an embodiment of the present invention;
[0015] Figure 7 is a working flowchart of a system for dynamically adjusting a third-party thread pool according to an embodiment of the present invention;
[0016] Figure 8 is an architecture diagram of an optional system for dynamically adjusting a third-party thread pool according to an embodiment of the present invention;
[0017] Figure 9 shows a schematic structural diagram of an electronic device suitable for implementing the embodiments of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0018] To enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0019] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present invention described here can be implemented in an order different from those illustrated or described here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0020] According to an embodiment of the present invention, a method embodiment for dynamically adjusting a third-party thread pool is 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 the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that here.
[0021] Figure 1 is a flowchart of a method for dynamically adjusting a third-party thread pool according to an embodiment of the present invention. As Figure 1 shown, the method includes the following steps:
[0022] Step S102, when the third-party component is initialized, inject preset default configuration parameters into the thread pool, where the default configuration parameters include the maximum number of threads in the thread pool and the maximum capacity of the task queue.
[0023] For example, insert configuration logic into the initialization code of the third-party component to overwrite its original thread pool parameters; through a dependency injection framework, bind the default configuration parameters to the thread pool instance of the third-party component. Among them, a thread pool is a form of multithreaded processing that maintains a group of threads for executing submitted tasks. The thread pool can reduce the overhead generated when creating and destroying threads and improve system performance. This step realizes the standardized control of the third-party thread pool parameters through code instrumentation and dependency injection technologies, reducing code invasiveness.
[0024] Step S104: Based on the obtained dynamic configuration parameters, adjust the maximum number of threads in the thread pool and the maximum capacity of the task queue in real time to adapt to the resource requirements of different business scenarios.
[0025] First, adjust the maximum number of threads in the thread pool in real time. Specifically, update the preset thread number threshold in real time through the thread number dynamic adjustment value configured in the configuration file or received through the runtime interface; for example, dynamically calculate the recommended value of the number of threads according to the number of CPU cores and the load condition of the current system; perform weighted fusion on the recommended value and the thread number dynamic adjustment value, and update the preset thread number threshold based on the fusion result. Then, modify the maximum number of threads in the task queue of the thread pool, and adjust the default value of the maximum number of threads to the thread number threshold. In this embodiment, the dynamic adjustment of the number of threads combines static configuration and real-time load characteristics, and can elastically adapt to resource requirements. In addition, the hot update technology is used to achieve interruption-free adjustment, reduce the waste of thread resources and task processing delay, effectively alleviate the resource contention problem in high-concurrency scenarios, and improve the system throughput and response efficiency.
[0026] Next, adjust the maximum capacity of the task queue in the thread pool in real time. Update the preset queue capacity threshold in real time through the queue capacity dynamic adjustment value configured in the configuration file or received through the runtime interface; modify the maximum capacity of the task queue in the thread pool, and adjust the default value of the maximum capacity to the queue capacity threshold. Alternatively, dynamically calculate the safe upper limit value of the queue capacity according to the memory usage rate of the current system; when the queue capacity dynamic adjustment value input by the user or configured exceeds the safe upper limit value, automatically set the default value of the maximum capacity of the queue capacity to the safe upper limit value. In this embodiment, the dual-mode queue capacity adjustment strategy introduces a memory safety threshold mechanism, which can actively intercept over-limit configurations and significantly reduce the risk of memory overflow.
[0027] After adjusting the maximum number of threads in the thread pool and the maximum capacity of the task queue in real time, the method further includes: visually display the running status of the adjusted thread pool and task queue through a monitoring tool, where the vertical coordinate range of the visual display is dynamically scaled according to the upper limit value of the dynamic configuration parameters. In this embodiment, the visual monitoring method using dynamic vertical coordinate scaling improves the readability of metrics and can quickly locate the bottleneck in the operation of the thread pool. In addition, the integrated key metric view supports real-time analysis, forms a "monitoring - tuning" closed loop, greatly shortens the operation and maintenance response time, and enhances the system operation and maintenance automation ability and overall stability.
[0028] In the open-source community, the dynamic-tp framework is widely used due to its powerful functions and ease of use. The dynamic-tp framework supports rapid deployment and monitoring and is applicable to various business scenarios. However, in some environments, dynamic-tp has some limitations. Through the monitoring of tomcat and okhttp3, as Figure 2 and Figure 3 shown, it can be found that the maximum number of threads of okhttp3 and the maximum queue capacity of tomcat are both set to Integer.MAX_VALUE. Although such a setting is reasonable in theory, in actual applications, due to memory limitations, a more reasonable upper limit value usually needs to be set.
[0029] The main disadvantage of the existing technology is that the value of Integer.MAX_VALUE is very large. In Grafana monitoring, this will cause the numerical value on the vertical axis to be too large, which will in turn affect the observation effect of other indicators. In addition, if threads or queues are created without limit, even if an upper limit value is set, there is still a risk of out-of-memory (OOM).
[0030] To solve the above problems, this application provides a method for dynamic-tp to adapt to a third-party thread pool. In this method, colored-logic is added during the initialization of the third-party component, default values are injected, and configuration support is provided.
[0031] Specifically, in the embodiment of this application, the maximum queue size of tomcat is modified, and the configuration of the default value is supported. Similarly, the maximum number of threads of okhttp3 is also adjusted, and the support for the default value configuration is provided. As Figure 4 shown, the method for dynamic-tp to adapt to a third-party thread pool includes the following steps:
[0032] Step S402, the service starts.
[0033] In the system service startup phase, initialize the thread pool management module of the third-party component (such as Tomcat, OkHttp3), and load the dynamic configuration center or local configuration file. Through the ApplicationRunner interface of Spring Boot or a similar mechanism, trigger the thread pool adaptation process to ensure that the dynamic injection of thread pool parameters and configuration loading are completed before the service is fully started.
[0034] Step S404, obtain the bean corresponding to tomcat / okhttp3.
[0035] In the Spring container, obtain the Bean instances of third-party components (such as the Connector of Tomcat or the Dispatcher of OkHttp3) through BeanFactory or ApplicationContext. For the thread pool implementation classes of different components (such as ThreadPoolExecutor of Tomcat and ExecutorService of OkHttp3), adopt component-specific Bean name or type matching strategies to ensure accurate positioning of the target thread pool instance and provide an entry for subsequent reflection operations.
[0036] Step S406, obtain the thread pool through reflection.
[0037] Utilize the Java reflection mechanism to extract the thread pool object from the Bean instance. For example, access the private field executor of the Tomcat Connector or the field executorService of the OkHttp3 Dispatcher through the Field.get() method. To bypass access restrictions, call the setAccessible(true) method to lift the encapsulation of the private field, ensuring that the core parameters of the thread pool (such as the maximum number of threads and queue capacity) can be directly manipulated to achieve dynamic override of underlying parameters.
[0038] Step S408, copy the thread pool configuration and create the dynamic-tp enhanced class.
[0039] Based on the configuration of the original thread pool (such as the core number of threads and rejection policy), create a configuration copy to avoid directly modifying the original instance. Subsequently, instantiate the enhanced proxy class of the Dynamic-TP framework (such as DynamicThreadPoolExecutor), inject the copy configuration into the proxy class, and bind the dynamic adjustment listener. This proxy class inherits the functions of the original thread pool and integrates the dynamic parameter update interface, supporting real-time adjustment of thread pool parameters through the configuration center or API during runtime.
[0040] Step S410, determine whether there is a configuration.
[0041] By querying the configuration center (such as Nacos, Apollo) or the local configuration file, detect whether the user has defined custom parameters (such as the maximum number of threads maxThreads and queue capacity queueCapacity) for the current thread pool. If there is a custom configuration, enter step S412; otherwise, adopt predefined reasonable default values (such as the maximum number of threads calculated based on the number of CPU cores and the queue capacity limited by the memory safety threshold), enter step S414, to ensure that the thread pool parameters are always within a controllable range.
[0042] Step S412, modify integer.MAX to a set value.
[0043] For the maximum queue size of Tomcat, call the setMaxCapacity(int) method of TaskQueue through reflection to replace the original Integer.MAX_VALUE with the threshold value set by the user (such as 2000). For OkHttp3, modify the maximum number of threads of the ExecutorService in Dispatcher and dynamically adjust it through the setMaximumPoolSize(int) method of ThreadPoolExecutor. This process realizes hot update through the configuration management module of Dynamic-TP, without restarting the service, to ensure business continuity. Specifically, modify the maximum queue size of tomcat and support default value configuration, as Figure 5 shown. Modify the maximum number of threads of okhttp3 and support default value configuration, as Figure 6 shown. Then, jump to step S416.
[0044] Step S414, modify inter.MAX to a default reasonable value.
[0045] If no user-defined configuration is detected, automatically calculate the security threshold based on system resources (such as the number of CPU cores and the available memory of the JVM). For example, the default value of the Tomcat queue capacity is the number of CPU cores × 200, and the default value of the maximum number of threads of OkHttp3 is the number of CPU cores × 2. Avoid hard coding through dynamic calculation formulas to adapt to different deployment environments (such as physical machines, containers), and prevent memory overflow or monitoring metric distortion problems caused by Integer.MAX_VALUE.
[0046] Step S416, put the thread pool back into the bean through reflection.
[0047] Inject the modified Dynamic-TP enhanced thread pool instance back into the private field of the original Bean through reflection (such as the executor field of the Tomcat Connector). To ensure the atomicity of thread pool replacement, use the double-checked locking or synchronization block mechanism to avoid thread safety issues in a concurrent environment. Finally, the enhanced thread pool takes over task scheduling to achieve dynamic effect and real-time monitoring of parameters.
[0048] In the embodiments of the present application, by injecting default values during the initialization of third-party components, dynamically adjusting the thread pool and queue sizes of Tomcat and OkHttp3, and providing configuration support to allow users to adjust the sizes of the thread pool and queue according to actual needs, the present application has the following beneficial effects compared with the prior art: improving the readability of monitoring tools and avoiding affecting the observation of other metrics due to excessive ordinate values; reducing the risk of memory overflow and reducing the situation of creating threads or queues without limit through reasonable default value configuration; improving the stability and reliability of the system by dynamically adjusting the sizes of the thread pool and queue to better adapt to different business scenarios.
[0049] In some other alternative embodiments, different thread pool management strategies can also be used, such as a fixed-size thread pool, to reduce memory usage. A memory usage monitoring mechanism can also be introduced to dynamically adjust the sizes of the thread pool and queue to avoid memory overflow. Other monitoring tools or custom monitoring logics can also be adopted to more effectively display the current states of the thread pool and queue.
[0050] The embodiments of the present application also provide a system for dynamically adjusting a third-party thread pool, which is particularly applicable to third-party components such as Tomcat and OkHttp3. In the prior art, the thread pools of these components default to setting the maximum number of threads and the task queue capacity to Integer.MAX_VALUE. Although theoretically it can support unlimited expansion, in actual applications, it will cause the ordinate range of the monitoring tool to be too large, making it difficult to observe other key metrics, and there is a risk of memory overflow. The embodiments of the present application effectively solve the above problems by injecting reasonable default values in the component initialization stage, combining dynamic configuration parameters to adjust the thread pool parameters in real time, and optimizing the visual display through the monitoring tool.
[0051] The core architecture of the system for dynamically adjusting a third-party thread pool includes the following modules: a configuration management module, which is responsible for loading preset default configuration parameters (such as the maximum number of threads and the queue capacity) and the adjustment values dynamically input by users. A parameter injection module, which is used to overwrite the native thread pool parameters through code logic during the initialization of third-party components to ensure that the initial values meet the system resource limitations; a dynamic adjustment engine, which is used to calculate the safety threshold and update the thread pool configuration according to the resource metrics such as the number of CPU cores, system load, and memory usage rate collected in real time, combined with the dynamic parameters input by users; a monitoring adaptation module, which is used to integrate with monitoring tools such as Grafana, dynamically adjust the ordinate range of the visualization chart, and mark abnormal states.
[0052] The operation process of the system for dynamically adjusting a third-party thread pool in the embodiments of the present application is as Figure 7 shown and includes the following steps:
[0053] Step S702, initialization phase, inject default configuration parameters.
[0054] During the initialization of the third-party component, modify the construction logic of its native thread pool, replacing the default parameter from Integer.MAX_VALUE with a preset reasonable value. Taking Tomcat as an example, when its native thread pool is initialized, the maximum number of threads and the queue capacity are not restricted, resulting in potential risks.
[0055] This embodiment realizes parameter injection through the following steps:
[0056] First, insert custom configuration logic into the initialization code of Tomcat. Specifically, by overriding the constructor of the thread pool, change the maximum number of threads from Integer.MAX_VALUE to a preset default value, and adjust the maximum capacity of the task queue from Integer.MAX_VALUE to the default value. In this way, it can be ensured that the component is in a safe configuration state when starting.
[0057] Second, use a dependency injection framework (such as Spring) to bind the default parameters to the thread pool instance. By defining a configuration class and using annotations (such as @Bean), associate the creation process of the thread pool instance with the preset parameters. For example, in the Spring framework, when generating a thread pool instance through declarative configuration, directly specify the default values of the maximum number of threads and the queue capacity, thus overriding the native implementation of the third-party component.
[0058] In some other embodiments, if the dependency injection framework is not available, the source code of the third-party component can be manually modified or bytecode enhancement technology (such as Java Agent) can be used to dynamically replace the thread pool parameters at runtime. For example, modify the bytecode through the ASM library to directly replace the parameter values in the constructor.
[0059] Step S704, adjust dynamic parameters.
[0060] During the operation of the component, the system supports receiving dynamic adjustment instructions through a configuration file or a runtime interface and updating the thread pool parameters in real time. The specific steps are as follows:
[0061] The dynamic parameters support the following two input methods: 1) Configuration file: Define the dynamic adjustment values through a YAML or Properties file. For example, specify that the maximum number of threads of Tomcat is 300 and the queue capacity is 1500 in the configuration file. The system loads these values at startup and automatically triggers parameter update when detecting changes in the configuration file. 2) Provided by the runtime interface: Provide a RESTful API to receive external adjustment instructions. Users can send new thread number or queue capacity values through an HTTP request, and the system takes effect immediately after parsing the request.
[0062] To prevent the user input value from exceeding the system's carrying capacity, it is necessary to calculate the safety threshold in combination with real-time resource metrics.
[0063] 1) Dynamic adjustment of the number of threads: Calculate the recommended value based on the current number of CPU cores and system load. For example, if the number of CPU cores is 4 and the current system load is 2.0, the recommended number of threads is 4*(1 + 2.0) = 12. The system combines the recommended value with the user input value according to a weight (such as 7:3) to generate the final adjusted value.
[0064] 2) Dynamic adjustment of the queue capacity: Dynamically correct the user input value according to the memory usage rate. For example, if the current heap memory usage rate exceeds 80%, the upper limit of the queue capacity is automatically reduced to 50% of the default value to prevent memory overflow. If the user input value is lower than the safety threshold, the user input value is directly adopted.
[0065] When updating the thread pool parameters, it is necessary to call the setMaximumPoolSize() method of the thread pool to modify the maximum number of threads, and modify the capacity field of the task queue (such as the capacity attribute of LinkedBlockingQueue) through the reflection mechanism. To ensure thread safety, locks or atomic operations need to be used during the adjustment process to avoid inconsistent states caused by concurrent modifications.
[0066] In some other embodiments, if it is not supported to modify the queue capacity by reflection, a new thread pool instance can be recreated and replaced with the original instance. Although this method can achieve parameter update, it will cause a short service interruption and is applicable to scenarios with lower real-time requirements.
[0067] Step S706, monitoring and visual display.
[0068] The adjusted thread pool parameters need to be synchronized to the monitoring system, and the display effect is optimized by dynamically shrinking the vertical coordinate range.
[0069] First, set the upper limit of the vertical coordinate of the monitoring chart according to the maximum number of threads and queue capacity of the current thread pool. For example, if the maximum number of threads is adjusted to 300, the vertical coordinate range is set to 0 to 350 to avoid other metrics being compressed and displayed due to excessive values.
[0070] Next, perform abnormal status marking. When the number of threads or queue capacity is close to the safety threshold (such as reaching 80% of the upper limit), it is highlighted in the monitoring chart with a red area to remind the operation and maintenance personnel to intervene.
[0071] This application also provides a system for dynamically adjusting a third-party thread pool, such as Figure 8As shown, it includes: an injection module 12 configured to inject preset default configuration parameters into a thread pool when a third-party component is initialized, where the default configuration parameters include the maximum number of threads in the thread pool and the maximum capacity of the task queue; an adjustment module 14 configured to perform real-time adjustment on the maximum number of threads in the thread pool and the maximum capacity of the task queue based on the obtained dynamic configuration parameters to adapt to the resource requirements of different service scenarios.
[0072] It should be noted that: for the system for dynamically adjusting a third-party thread pool provided in the above embodiment, only the division of the above functional modules is used for illustration. In actual applications, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the system for dynamically adjusting a third-party thread pool provided in the above embodiment and the embodiment of dynamically adjusting a third-party thread pool belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be elaborated here.
[0073] Figure 9 The figure shows a schematic structural diagram of an electronic device suitable for implementing the embodiments of the present disclosure. It should be noted that Figure 9 The shown electronic device is only an example and should not impose any restrictions on the functions and usage scope of the embodiments of the present disclosure.
[0074] As Figure 9 shown, the electronic device includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1002 or the program loaded from the storage part 1008 into the random access memory (RAM) 1003. In the RAM 1003, various programs and data required for system operation are also stored. The CPU 1001, ROM 1002, and RAM 1003 are connected to each other through a bus 1004. The input / output (I / O) interface 1005 is also connected to the bus 1004.
[0075] The following components are connected to the I / O interface 1005: an input part 1006 including a keyboard, a mouse, etc.; an output part 1007 including such as a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage part 1008 including a hard disk, etc.; and a communication part 1009 including a network interface card such as a LAN card, a modem, etc. The communication part 1009 performs communication processing via a network such as the Internet. A driver 1010 is also connected to the I / O interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the driver 1010 as needed so that a computer program read from it can be installed into the storage part 1008 as needed.
[0076] The above are only the preferred embodiments of the present application. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present application, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present application.
Claims
1. A method for dynamically adjusting a third-party thread pool, characterized in that, Including: When initializing a third - party component, injecting preset default configuration parameters into the thread pool, where the default configuration parameters include the maximum number of threads in the thread pool and the maximum capacity of the task queue; Based on the obtained dynamic configuration parameters, dynamically adjust the maximum number of threads in the thread pool and / or the maximum capacity of the task queue in real - time to adapt to the resource requirements of different business scenarios.
2. The method according to claim 1, wherein After dynamically adjusting the maximum number of threads in the thread pool and the maximum capacity of the task queue, the method further includes: visually displaying the running status of the adjusted thread pool and the task queue through a monitoring tool, where the vertical coordinate range of the visual display is dynamically scaled according to the upper limit value of the dynamic configuration parameters.
3. The method according to claim 1, wherein Based on the obtained dynamic configuration parameters, dynamically adjusting the maximum number of threads in the thread pool includes: Using the thread number dynamic adjustment value configured through a configuration file or received through a runtime interface to update the preset thread number threshold in real - time; modifying the maximum number of threads in the task queue of the thread pool and adjusting the default value of the maximum number of threads to the thread number threshold.
4. The method according to claim 3, characterized in that, Using the thread number dynamic adjustment value configured through a configuration file or received through a runtime interface to update the preset thread number threshold in real - time includes: Dynamically calculating the recommended value of the number of threads according to the number of CPU cores and the load situation of the current system; Performing weighted fusion on the recommended value and the thread number dynamic adjustment value, and updating the preset thread number threshold in real - time based on the fusion result.
5. The method according to claim 1, wherein Based on the obtained dynamic configuration parameters, dynamically adjusting the maximum capacity of the task queue in the thread pool includes: Using the queue capacity dynamic adjustment value configured through a configuration file or received through a runtime interface to update the preset queue capacity threshold in real - time; modifying the maximum capacity of the task queue of the thread pool and adjusting the default value of the maximum capacity to the queue capacity threshold; or Dynamically calculating the safe upper limit value of the queue capacity according to the memory usage rate of the current system; when the queue capacity dynamic adjustment value input by the user or configured exceeds the safe upper limit value, automatically setting the default value of the maximum capacity of the queue capacity to the safe upper limit value.
6. The method according to claim 1, characterized in that, When initializing a third - party component, injecting preset default configuration parameters into the thread pool, including: Inserting configuration logic into the initialization code of the third - party component to overwrite its original thread pool parameters; Through a dependency injection framework, binding the default configuration parameters to the thread pool instance of the third - party component.
7. A system for dynamically adjusting a third-party thread pool, characterized in that, Including: An injection module, configured to inject preset default configuration parameters into the thread pool when initializing a third - party component, where the default configuration parameters include the maximum number of threads in the thread pool and the maximum capacity of the task queue; An adjustment module, configured to dynamically adjust the maximum number of threads in the thread pool and / or the maximum capacity of the task queue in real - time based on the obtained dynamic configuration parameters to adapt to the resource requirements of different business scenarios.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein when the program runs, it controls the device where the computer-readable storage medium is located to execute the method according to any one of claims 1 to 6.
9. A computer device, characterized in that, Comprising: a memory and a processor, the memory stores a computer program; the processor is configured to execute the computer program stored in the memory, and when the computer program runs, it causes the processor to execute the method according to any one of claims 1 to 6.
10. A computer program product comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the method according to any one of claims 1 to 6.