A dynamic configuration method and device of a thread pool

By using dynamic configuration mechanisms and hot-swap technology, the problem of static thread pool configurations being unable to adapt to changes in business load is solved, enabling dynamic adjustment of the thread pool and improving system performance and resource utilization efficiency.

CN122195656APending Publication Date: 2026-06-12INNER MONGOLIA BRANCH OF CHINA CONSTR BANK CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
INNER MONGOLIA BRANCH OF CHINA CONSTR BANK CO LTD
Filing Date
2026-03-11
Publication Date
2026-06-12

AI Technical Summary

Technical Problem

Traditional static thread pool configurations are difficult to meet the dynamically changing business load requirements, leading to resource waste or performance impact.

Method used

By using a dynamic configuration mechanism, changes in thread pool configuration parameters are monitored, a second thread pool is created and hot-swapped, thus enabling dynamic adjustment of the thread pool configuration.

🎯Benefits of technology

Ensure that the thread pool adapts to the current business load, avoids insufficient or excessive resources, guarantees system performance and stability, and provides convenient thread monitoring and troubleshooting.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122195656A_ABST
    Figure CN122195656A_ABST
Patent Text Reader

Abstract

The application provides a dynamic configuration method and device of a thread pool, the method comprising: obtaining thread pool configuration parameters from a configuration source; creating a first thread pool based on the thread pool configuration parameters; receiving tasks submitted by a business service using the first thread pool and processing the tasks; listening to changes in the thread pool configuration parameters in the configuration source, and when a change is listened to, creating a second thread pool based on the latest thread pool configuration parameters; and using the second thread pool to perform hot replacement on the first thread pool. In the present scheme, when the system starts, the thread pool configuration parameters are read from a configuration file, and a thread pool is constructed, then changes in the thread pool configuration parameters are listened to, and once an update is detected, a new thread pool is reconstructed, and hot replacement is performed on the old thread pool, so as to achieve the purpose of dynamically adjusting the thread pool configuration in the running process of the thread pool.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and more specifically to a method and apparatus for dynamically configuring a thread pool. Background Technology

[0002] In modern banking systems, especially when interfacing with third-party systems (such as those of external partners), the challenge of handling a large number of concurrent requests is frequently encountered. To improve system performance and resource utilization, thread pool technology is typically used to manage concurrently executed tasks.

[0003] Traditional static thread pool configurations (where the thread pool configuration is initialized with preset values ​​at system startup and remains unchanged during runtime) often fail to meet dynamically changing business load demands. Setting the thread pool parameters too low can lead to slow transaction processing or even timeouts; setting them too high can waste resources and even affect system stability. Summary of the Invention

[0004] In view of this, embodiments of the present invention provide a method and apparatus for dynamic configuration of a thread pool, so as to achieve the purpose of dynamically adjusting the thread pool configuration during the operation of the thread pool.

[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0006] The first aspect of this invention discloses a method for dynamically configuring a thread pool, the method comprising:

[0007] Obtain thread pool configuration parameters from the configuration source;

[0008] Based on the thread pool configuration parameters, a first thread pool is created;

[0009] The first thread pool is used to receive and process tasks submitted by business services.

[0010] Monitor changes to the thread pool configuration parameters in the configuration source, and when a change is detected, create a second thread pool based on the latest thread pool configuration parameters;

[0011] The first thread pool is hot-swapped using the second thread pool.

[0012] Optionally, the step of receiving and processing tasks submitted by business services using the first thread pool includes:

[0013] Register the first thread pool into the Spring container to obtain the corresponding first Bean component;

[0014] The first Bean component is used to receive tasks submitted by the business service through dependency injection, and the first thread pool is used to process the tasks.

[0015] Optionally, the hot replacement of the first thread pool using the second thread pool includes:

[0016] The second thread pool is registered to the Spring container to obtain the corresponding second Bean component;

[0017] In the Spring container, the first Bean component is replaced with the second Bean component, so that the business service submits new tasks to the second Bean component through dependency injection, and the new tasks are processed by the second thread pool;

[0018] When the remaining tasks in the first thread pool have been processed, the first thread pool is destroyed.

[0019] Optionally, the method further includes:

[0020] After obtaining the thread pool configuration parameters from the configuration source, the integrity of the thread pool configuration parameters is verified.

[0021] When a missing thread pool configuration parameter is detected, the missing thread pool configuration parameter is filled in using a preset default value.

[0022] Optionally, the method further includes:

[0023] During the process of using the first thread pool to process the task, the running status index values ​​of the first thread pool are continuously collected.

[0024] An alarm notification is triggered when the operating status indicator value meets the preset alarm conditions.

[0025] A second aspect of this invention discloses a dynamic configuration device for a thread pool, the device comprising:

[0026] The retrieval unit is used to obtain thread pool configuration parameters from the configuration source.

[0027] A creation unit is used to create a first thread pool based on the thread pool configuration parameters;

[0028] The task processing unit is used to receive tasks submitted by business services using the first thread pool and to process the tasks.

[0029] The listening unit is used to listen for changes in the thread pool configuration parameters in the configuration source, and when a change is detected, to create a second thread pool based on the latest thread pool configuration parameters;

[0030] The replacement unit is used to perform hot replacement of the first thread pool using the second thread pool.

[0031] Optionally, the task processing unit is specifically used for:

[0032] Register the first thread pool into the Spring container to obtain the corresponding first Bean component;

[0033] The first Bean component is used to receive tasks submitted by the business service through dependency injection, and the first thread pool is used to process the tasks.

[0034] Optionally, the replacement unit is specifically used for:

[0035] The second thread pool is registered to the Spring container to obtain the corresponding second Bean component;

[0036] In the Spring container, the first Bean component is replaced with the second Bean component, so that the business service submits new tasks to the second Bean component through dependency injection, and the new tasks are processed by the second thread pool;

[0037] When the remaining tasks in the first thread pool have been processed, the first thread pool is destroyed.

[0038] Optionally, the device further includes:

[0039] The verification unit is used to perform integrity verification on the thread pool configuration parameters after obtaining the thread pool configuration parameters from the configuration source.

[0040] When a missing thread pool configuration parameter is detected, the missing thread pool configuration parameter is filled in using a preset default value.

[0041] Optionally, the device further includes:

[0042] An alarm unit is used to continuously collect the running status indicator values ​​of the first thread pool during the process of using the first thread pool to process the task.

[0043] An alarm notification is triggered when the operating status indicator value meets the preset alarm conditions.

[0044] Based on the above embodiments of the present invention, a dynamic configuration method and apparatus for a thread pool are provided. The method includes: obtaining thread pool configuration parameters from a configuration source; creating a first thread pool based on the thread pool configuration parameters; receiving and processing tasks submitted by business services using the first thread pool; monitoring changes in the thread pool configuration parameters in the configuration source, and creating a second thread pool based on the latest thread pool configuration parameters when a change is detected; and hot-replacing the first thread pool using the second thread pool. In this solution, when the system starts, it reads the thread pool configuration parameters from the configuration file and constructs a thread pool. Then, it monitors changes in the thread pool configuration parameters. Once an update is detected, a new thread pool is reconstructed, and the old thread pool is hot-replacing, thereby achieving the purpose of dynamically adjusting the thread pool configuration during thread pool operation. Attached Figure Description

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

[0046] Figure 1 This is a flowchart illustrating a dynamic configuration method for a thread pool according to an embodiment of the present invention;

[0047] Figure 2 This is a structural diagram of a dynamic configuration device for a thread pool disclosed in an embodiment of the present invention;

[0048] Figure 3 This is a structural diagram of an electronic device disclosed in an embodiment of the present invention. Detailed Implementation

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

[0050] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0051] First, the technical terms appearing in this application will be explained:

[0052] Thread pool: A thread pool is a tool for managing threads based on the pooling concept. It can reduce the overhead of creating and destroying threads and improve response speed.

[0053] Dynamic configuration: During application runtime, various parameters of the thread pool, such as the core number of threads and the maximum number of threads, can be adjusted in real time based on external configuration (configuration source).

[0054] External transactions: External transactions refer to various business interactions between the bank and external entities' systems, such as payment, inquiry, and refund.

[0055] As the background technology shows, traditional static thread pool configurations (i.e., the thread pool configuration is initialized with preset values ​​at system startup and does not change during runtime) often fail to meet dynamically changing business load requirements. If the thread pool parameters are set too low, it will lead to slow transaction processing or even timeouts; if they are set too high, it will cause resource waste and even affect system stability.

[0056] Therefore, the dynamic configuration method and apparatus for a thread pool disclosed in this embodiment of the invention reads the thread pool configuration parameters from the configuration file and constructs the thread pool when the system starts. Then, it listens for changes in the thread pool configuration parameters. Once an update is detected, a new thread pool is reconstructed and the old thread pool is hot-replaced, so as to achieve the purpose of dynamically adjusting the thread pool configuration during the operation of the thread pool.

[0057] like Figure 1 The diagram shown is a flowchart of a dynamic configuration method for a thread pool disclosed in an embodiment of the present invention, which mainly includes the following steps:

[0058] Step S101: Obtain thread pool configuration parameters from the configuration source.

[0059] In step S101, the thread pool configuration parameters are read and parsed, including but not limited to: core thread count (corePoolSize), which specifies the minimum number of active threads in the thread pool; maximum thread count (maximumPoolSize), which limits the maximum number of threads that the thread pool is allowed to create; thread keep-alive time (keepAliveTime), which defines the maximum lifespan of non-core threads in the idle state; and work queue capacity (queueCapacity), which specifies the length of the buffer queue waiting for tasks to be executed.

[0060] It should be noted that the configuration source can take many forms, including but not limited to local configuration files (such as application.properties), database configuration tables, or distributed configuration centers (such as Apollo, Nacos, etc.).

[0061] The thread pool configuration parameters in the configuration source are not fixed, but will be dynamically adjusted according to the actual business load.

[0062] Specifically, when the system faces peak business periods, operations and maintenance personnel can manually increase the number of core threads and the maximum number of threads to improve concurrent processing capabilities and avoid task backlog; when business enters a low period, these parameters can be reduced accordingly to release system resources and reduce resource consumption. Changes to thread pool configuration parameters can be achieved by modifying local configuration files or operating the management interface of the configuration center. The changed thread pool configuration parameters will be captured by the subsequent configuration monitoring mechanism, thereby triggering dynamic updates of the thread pool.

[0063] In one embodiment, after obtaining the thread pool configuration parameters from the configuration source, the integrity of the thread pool configuration parameters is checked; when a missing thread pool configuration parameter is detected, the missing thread pool configuration parameter is filled in using a preset default value.

[0064] In its implementation, the `@ConfigurationProperties` annotation is used to automatically bind configuration properties, and Spring Boot automatically handles type conversion and validation. In the `YBServicePushFileThreadPool` class, `Optional.of()` is used to wrap configuration values, ensuring that the system can still function even if the configuration is missing. Default values ​​are set for configuration properties in the `YbjfProperties` class, such as `jFServicePushFileThreadPoolCorePoolSize` which defaults to "8". This ensures that the system can still start normally even if these parameters are not specified in the configuration file. Spring Boot's configuration handling mechanism itself has good fault tolerance; when encountering invalid configurations, it will use default values ​​or throw explicit error messages instead of causing the system to fail to start.

[0065] Step S102: Create the first thread pool based on the thread pool configuration parameters.

[0066] In step S102, based on the obtained thread pool configuration parameters, the first thread pool instance (i.e., the first thread pool) is constructed using the ThreadPoolExecutor class in the Java concurrency package.

[0067] Specifically, parameters such as the core number of threads, the maximum number of threads, and the thread lifespan are passed to the ThreadPoolExecutor constructor, and a work queue with a specified capacity (such as LinkedBlockingQueue) is initialized to cache tasks to be processed.

[0068] During the creation process, a custom thread factory (BaseThreadFactory) is used to set a name with a specific business identifier for each worker thread in the thread pool. The name contains the thread pool identification information, which makes it easier to track the execution status of specific threads and troubleshoot faults through monitoring tools or logs.

[0069] For example, the BaseThreadFactory class names each thread using BaseThreadFactory.class.getSimpleName() followed by a sequence number. For instance, if two threads are created, they would be named BaseThreadFactory1 and BaseThreadFactory2. This naming convention allows staff to clearly identify threads belonging to a specific thread pool from monitoring tools or logs, facilitating troubleshooting and performance tuning.

[0070] Optionally, the first thread pool instance enters the RUNNING state immediately after its creation, enabling it to receive and execute tasks. However, at this time, worker threads may not have been actually created yet and will be dynamically generated based on the thread pool configuration parameters when the task is submitted for the first time.

[0071] Optionally, when creating a thread, each thread is assigned a unique incrementing sequence number as part of its name. When the sequence number reaches the maximum number of threads set in the thread pool configuration parameters, thread creation stops. If no maximum number of threads is set, the number of system CPU cores is used as the reference for the number of threads by default.

[0072] Step S103: Receive and process tasks submitted by business services using the first thread pool.

[0073] In the specific implementation of step S103, the first thread pool is registered in the Spring container to obtain the corresponding first Bean component; the first Bean component is used to receive tasks submitted by the business service through dependency injection, and the first thread pool is used to process the tasks.

[0074] In step S103, the first thread pool instance that has been created is incorporated into the Spring container for unified management in order to establish a standardized task submission channel.

[0075] Specifically, the first thread pool class (such as YBServicePushFileThreadPool) is declared as a Spring component using the `@Component` annotation. This allows the Spring container to automatically scan and create instances of this class during startup. Afterward, the first thread pool has a unique identifier within the Spring container (i.e., the first Bean component). Business services do not need to manually create thread pool instances using the `new` keyword, nor do they need to explicitly pass thread pool references in the code. Instead, they can directly inject and use the first thread pool using the `@Autowired` annotation.

[0076] When a business service generates a task to be processed, it directly calls the execute() or submit() method of the injected first Bean component to submit the task; the first thread pool (as the actual execution entity) allocates the task to the worker thread for processing according to its internal task scheduling mechanism, or temporarily stores the task in the work queue to wait for execution when there are not enough worker threads.

[0077] In this embodiment of the invention, the dependency injection mechanism decouples the business logic from the thread pool creation logic, enabling the thread pool instance to be shared and reused by multiple business services in the system. It also provides a unified management entry point for subsequent hot replacement. That is, only the registration information of the Bean component in the Spring container needs to be changed to achieve seamless switching of the task receiving entry point without modifying the code of the business service.

[0078] In one embodiment, during the process of using the first thread pool to process tasks, the running status indicator value of the first thread pool is continuously collected; when the running status indicator value meets the preset alarm conditions, an alarm notification is triggered.

[0079] Among these metrics, operational status indicators (such as the number of active threads, queue size, and number of completed tasks) can help operations and maintenance personnel understand the working status of the thread pool, promptly identify potential problems, and make corresponding adjustments. For example, when the number of active threads consistently approaches the maximum number of threads, it may mean that the thread pool capacity needs to be increased.

[0080] In this embodiment of the invention, to improve the observability and fault warning capabilities of the system, throughout the entire lifecycle of the business tasks processed by the first thread pool, its running status indicators are continuously collected by calling the monitoring APIs provided by ThreadPoolExecutor (such as getActiveCount(), getQueue().size(), getCompletedTaskCount(), etc.). These indicators cover key dimensions such as the number of active threads (reflecting the current concurrent processing pressure), the backlog of the task queue (reflecting the system load saturation), the number of completed tasks (reflecting the cumulative processing capacity), and the historical maximum number of threads (reflecting the peak concurrent demand). The collected indicator data can be exposed to the monitoring system in real time (such as through Micrometer to connect to Prometheus), or analyzed in real time by the built-in threshold judgment logic. When it is detected that the number of active threads is continuously approaching the maximum number of threads and the queue backlog exceeds a preset threshold (such as 80% of the queue capacity), the system is determined to be in a high-load risk state, and an alarm notification is triggered to prompt the operation and maintenance personnel to perform dynamic adjustment or expansion of the thread pool parameters in a timely manner, thereby preventing transaction timeouts or system avalanches caused by the exhaustion of thread pool resources, and providing data support for the formulation of dynamic parameter configuration strategies.

[0081] Step S104: Listen for changes in the thread pool configuration parameters in the configuration source, and when a change is detected, create a second thread pool based on the latest thread pool configuration parameters.

[0082] In step S104, the system monitors changes in the configuration parameters of the thread pool corresponding to the first thread pool in the configuration source. These changes are usually caused by operations personnel manually modifying the configuration file based on system load. For example, during peak business periods, it may be necessary to increase the core thread count and maximum thread count of the thread pool to handle more requests; during off-peak periods, these parameters can be decreased to save system resources.

[0083] Specifically, a configuration listener is started to establish a continuous monitoring mechanism for thread pool-related parameters in the configuration source. The configuration listener can be implemented using various technologies, and this invention is not limited to any particular one.

[0084] It can be understood that, based on the latest thread pool configuration parameters, the process of creating a second thread pool is the same as the process of creating the first thread pool described above. They can be referred to each other, and will not be repeated here.

[0085] Step S105: Use the second thread pool to perform a hot replacement of the first thread pool.

[0086] The first thread pool and the second thread pool are relative concepts, and their roles dynamically change during hot-swap operations.

[0087] Initial state: The first thread pool refers to the currently running thread pool (which is the first thread pool when it is initially created), which is responsible for handling all tasks of business services.

[0088] During hot replacement: The second thread pool refers to a new thread pool created based on the latest configuration parameters, which is used to take over subsequent new tasks; at this time, the first thread pool only processes existing tasks and no longer accepts new tasks.

[0089] After the replacement is completed: the original second thread pool becomes the new currently running thread pool after completing the registration and replacement (its role will be transformed into the new first thread pool when the configuration is changed in the future); while the original first thread pool exits the system after the existing tasks are processed and destroyed.

[0090] Therefore, when a change in configuration parameters is detected again, the currently running thread pool (i.e., the second thread pool after the previous hot replacement) will be replaced by the new thread pool (the new second thread pool) as the first thread pool. This process is repeated to achieve continuous dynamic updates of the thread pool configuration.

[0091] It's important to note that hot swapping doesn't require restarting the entire business service. Instead, it refers to hot swapping only the thread pool component during the business service's runtime. Tasks currently executing continue running in the old thread pool until completion, while new tasks are submitted to the newly created thread pool for execution. This approach avoids business service interruptions, ensuring business continuity, and is fundamentally different from existing technologies that require restarting the entire service before adjusting thread pool parameters.

[0092] Specifically, the second thread pool is registered in the Spring container to obtain the corresponding second Bean component; the first Bean component is replaced with the second Bean component in the Spring container so that the business service can submit new tasks to the second Bean component through dependency injection, and the second thread pool can process the new tasks; when the remaining tasks in the first thread pool are completed, the first thread pool is destroyed.

[0093] To ensure a smooth thread pool instance replacement process without affecting currently executing tasks during hot replacement, the following strategies can be adopted:

[0094] Instead of directly shutting down the old thread pool, mark it as "shutting down" and let it complete the tasks it has already accepted.

[0095] New tasks are submitted to the newly created thread pool.

[0096] Clean up old thread pools that have completed all tasks at appropriate times (such as during system off-peak periods).

[0097] The entire replacement process is transparent to external users, shielding the underlying implementation details through a unified access interface.

[0098] It should be noted that when a configuration change is triggered, the second thread pool, built according to the latest configuration parameters, is first registered with the Spring container, giving it an independent Bean identity. Subsequently, at the container level, the task submission path for business services is switched from the original first Bean component to the second Bean component. After that, all newly initiated service requests are directed to the second thread pool for processing through the dependency injection mechanism, while the original first thread pool enters a no-entry cleanup state, continuing to execute the cached tasks in its work queue until all are completed. After the existing tasks are cleared, the first thread pool is shut down and awaits termination, and finally the instance is destroyed and the system resources it occupies are released, thus achieving seamless hot switching of thread pool instances without interrupting the overall service.

[0099] During hot-swap operations, thread safety must be ensured to avoid race conditions. Thread safety should be guaranteed through the following methods:

[0100] Use synchronization mechanisms (such as the synchronized keyword or ReentrantReadWriteLock) to protect the replacement process of thread pool instances.

[0101] During the replacement process, ensure that the tasks being executed can be completed smoothly in the old thread pool.

[0102] When submitting a new task, ensure that the latest thread pool instance is used.

[0103] The `volatile` keyword can be used to modify thread pool references to ensure visibility between threads.

[0104] In summary, the beneficial effects achieved by the various embodiments of this invention are as follows: By introducing a dynamic configuration mechanism to manage the thread pool, the core parameters of the thread pool (such as the core number of threads, the maximum number of threads, and the queue capacity) can be adjusted in real time according to external configuration at runtime. When the system starts, it reads the initial thread pool parameters from the configuration file and constructs a thread pool instance. Simultaneously, the system listens for configuration changes, and once a configuration update is detected, it reconstructs the thread pool or adjusts the parameters of the existing thread pool. This mechanism ensures that the thread pool can always adapt to the current business load, avoiding performance impact due to insufficient resources or waste due to excessive resources. Furthermore, by using the factory pattern to create threads, more meaningful names can be assigned to the threads, facilitating monitoring and debugging.

[0105] Corresponding to the dynamic configuration method for a thread pool disclosed in the above embodiments of the present invention, such as Figure 2The diagram shown is a structural diagram of a dynamic configuration device for a thread pool disclosed in an embodiment of the present invention. The device includes: an acquisition unit 201, a creation unit 202, a task processing unit 203, a listening unit 204, and a replacement unit 205.

[0106] Acquisition unit 201 is used to obtain thread pool configuration parameters from the configuration source;

[0107] Create unit 202 to create the first thread pool based on thread pool configuration parameters;

[0108] The task processing unit 203 is used to receive and process tasks submitted by business services using the first thread pool.

[0109] Listening unit 204 is used to listen for changes in thread pool configuration parameters in the configuration source, and when a change is detected, to create a second thread pool based on the latest thread pool configuration parameters;

[0110] Replacement unit 205 is used to hot replace the first thread pool using the second thread pool.

[0111] Optionally, the task processing unit 203 is specifically used for:

[0112] Register the first thread pool into the Spring container to obtain the corresponding first Bean component;

[0113] The first Bean component receives tasks submitted by business services via dependency injection and processes these tasks using the first thread pool.

[0114] Optionally, replacement unit 205 is used specifically for:

[0115] Register the second thread pool into the Spring container to obtain the corresponding second Bean component;

[0116] In the Spring container, the first Bean component is replaced with the second Bean component so that the business service submits new tasks to the second Bean component through dependency injection, and the new tasks are processed by the second thread pool.

[0117] Once the remaining tasks in the first thread pool have been processed, the first thread pool is destroyed.

[0118] Optionally, the device also includes:

[0119] The verification unit is used to perform integrity verification on the thread pool configuration parameters after obtaining the thread pool configuration parameters from the configuration source.

[0120] When a missing thread pool configuration parameter is detected, the missing thread pool configuration parameter is filled in using the preset default value.

[0121] Optionally, the device also includes:

[0122] The alarm unit is used to continuously collect the running status indicator values ​​of the first thread pool during the process of using the first thread pool to process tasks.

[0123] An alarm notification is triggered when the operating status indicator value meets the preset alarm conditions.

[0124] In summary, the beneficial effects achieved by the various embodiments of this invention are as follows: By introducing a dynamic configuration mechanism to manage the thread pool, the core parameters of the thread pool (such as the core number of threads, the maximum number of threads, and the queue capacity) can be adjusted in real time according to external configuration at runtime. When the system starts, it reads the initial thread pool parameters from the configuration file and constructs a thread pool instance. Simultaneously, the system listens for configuration changes, and once a configuration update is detected, it reconstructs the thread pool or adjusts the parameters of the existing thread pool. This mechanism ensures that the thread pool can always adapt to the current business load, avoiding performance impact due to insufficient resources or waste due to excessive resources. Furthermore, by using the factory pattern to create threads, more meaningful names can be assigned to the threads, facilitating monitoring and debugging.

[0125] Another embodiment of this application provides an electronic device, such as... Figure 3 As shown, it includes:

[0126] Memory 301 and processor 302.

[0127] The memory 301 is used to store the program.

[0128] The processor 302 is used to execute the program stored in the memory 301. When the program is executed, it is specifically used to implement the dynamic configuration method of the thread pool as provided in any of the above embodiments.

[0129] Another embodiment of this application provides a computer storage medium for storing a computer program, which, when executed by a processor, implements the dynamic configuration method of a thread pool as provided in any of the above embodiments.

[0130] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0131] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0132] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for dynamically configuring a thread pool, characterized in that, The method includes: Obtain thread pool configuration parameters from the configuration source; Based on the thread pool configuration parameters, a first thread pool is created; The first thread pool is used to receive and process tasks submitted by business services. Monitor changes to the thread pool configuration parameters in the configuration source, and when a change is detected, create a second thread pool based on the latest thread pool configuration parameters; The first thread pool is hot-swapped using the second thread pool.

2. The method according to claim 1, characterized in that, The step of receiving and processing tasks submitted by business services using the first thread pool includes: Register the first thread pool into the Spring container to obtain the corresponding first Bean component; The first Bean component is used to receive tasks submitted by the business service through dependency injection, and the first thread pool is used to process the tasks.

3. The method according to claim 2, characterized in that, The hot replacement of the first thread pool using the second thread pool includes: The second thread pool is registered to the Spring container to obtain the corresponding second Bean component; In the Spring container, the first Bean component is replaced with the second Bean component, so that the business service submits new tasks to the second Bean component through dependency injection, and the new tasks are processed by the second thread pool; When the remaining tasks in the first thread pool have been processed, the first thread pool is destroyed.

4. The method according to claim 1, characterized in that, The method further includes: After obtaining the thread pool configuration parameters from the configuration source, the integrity of the thread pool configuration parameters is verified. When a missing thread pool configuration parameter is detected, the missing thread pool configuration parameter is filled in using a preset default value.

5. The method according to any one of claims 1 to 4, characterized in that, The method further includes: During the process of using the first thread pool to process the task, the running status index values ​​of the first thread pool are continuously collected. An alarm notification is triggered when the operating status indicator value meets the preset alarm conditions.

6. A dynamic configuration device for a thread pool, characterized in that, The device includes: The retrieval unit is used to obtain thread pool configuration parameters from the configuration source. A creation unit is used to create a first thread pool based on the thread pool configuration parameters; The task processing unit is used to receive tasks submitted by business services using the first thread pool and to process the tasks. The listening unit is used to listen for changes in the thread pool configuration parameters in the configuration source, and when a change is detected, to create a second thread pool based on the latest thread pool configuration parameters; The replacement unit is used to perform hot replacement of the first thread pool using the second thread pool.

7. The apparatus according to claim 6, characterized in that, The task processing unit is specifically used for: Register the first thread pool into the Spring container to obtain the corresponding first Bean component; The first Bean component is used to receive tasks submitted by the business service through dependency injection, and the first thread pool is used to process the tasks.

8. The apparatus according to claim 7, characterized in that, The replacement unit is specifically used for: The second thread pool is registered to the Spring container to obtain the corresponding second Bean component; In the Spring container, the first Bean component is replaced with the second Bean component, so that the business service submits new tasks to the second Bean component through dependency injection, and the new tasks are processed by the second thread pool; When the remaining tasks in the first thread pool have been processed, the first thread pool is destroyed.

9. The apparatus according to claim 6, characterized in that, The device further includes: The verification unit is used to perform integrity verification on the thread pool configuration parameters after obtaining the thread pool configuration parameters from the configuration source. When a missing thread pool configuration parameter is detected, the missing thread pool configuration parameter is filled in using a preset default value.

10. The apparatus according to any one of claims 6 to 9, characterized in that, The device further includes: An alarm unit is used to continuously collect the running status indicator values ​​of the first thread pool during the process of using the first thread pool to process the task. An alarm notification is triggered when the operating status indicator value meets the preset alarm conditions.