Thread pool management method and device, equipment and medium

Through dynamic management and real-time monitoring of thread pool business tables, the uneven resource allocation and performance bottlenecks in thread pool management are solved, and the stability and reliability of the software system are improved.

CN119226088APending Publication Date: 2024-12-31BANK OF NINGBO
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411383622.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-30
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

In the prior art, thread pool management is difficult to centrally manage, resulting in uneven resource allocation, performance bottlenecks and maintenance difficulties, especially in large software systems.

Method used

By creating thread pool business tables, dynamically create thread pools, and monitoring their operating status in real time, triggering alerts based on preset alarm conditions, and updating thread pool parameters to optimize resource allocation and avoid crashes.

Benefits of technology

It realizes centralized management of thread pools, optimizes resource allocation, avoids resource waste and performance bottlenecks, and improves the stability and reliability of the software system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119226088A_ABST
    Figure CN119226088A_ABST
Patent Text Reader

Abstract

The invention provides a thread pool management method and device, equipment and a medium, and relates to the technical field of computers. According to the application, centralized management of all the thread pools is realized by introducing the thread pool service table, so that an administrator can obtain the configuration information of each thread pool, and the problems of scattered configuration, non-uniform resource allocation and difficulty in tracking of a plurality of thread pools are avoided. Moreover, the parameter values in the service table of the thread pool support real-time updating, which means that the configuration of the thread pool can be dynamically adjusted and at least one thread pool can be created according to the actual operation condition and the service demand, thereby being beneficial to optimizing resource allocation and avoiding resource waste and performance bottleneck. Furthermore, the current running state of the thread pool can be obtained in real time. When the current operation state reaches the preset alarm condition, the alarm indication is triggered, so that potential problems can be found in time, corresponding measures are taken for processing, and expansion of the problems and collapse of the thread pool are avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a thread pool management method, device, equipment and medium. Background Art

[0002] As software systems become increasingly complex and concurrent requirements increase, traditional single-thread or simple multi-thread management methods can no longer meet the requirements of high efficiency, scalability, and high resource utilization. Thread pools significantly improve the response speed and resource utilization of software systems by reusing threads, reducing the overhead of thread creation and destruction, and better managing thread and task execution.

[0003] In the related technology, in Java, a thread pool can be created through the ThreadPool Executor class, which provides a wealth of parameter configurations, such as the number of core threads, the maximum number of threads, the thread survival time, the task queue, etc., allowing developers to flexibly adjust the behavior of the thread pool according to specific needs. However, although the Thread Pool Executor is powerful, there may be problems with multiple thread pools not being centrally managed when used directly, making it difficult to monitor and maintain. In the Spring framework, the @Async annotation provides a convenient way to create and manage asynchronous tasks, but these tasks are usually executed using Spring's default thread pool or a public thread pool specified by the developer. Although this simplifies the creation of asynchronous tasks, it may not meet specific thread pool configuration requirements when faced with a variety of different business scenarios.

[0004] Therefore, whether you use ThreadPool Executor directly or use Spring's @Async annotation to create and manage thread pools, it is easy to encounter problems such as multiple thread pools not being centrally managed. Especially in large software systems, there may be problems such as uneven resource allocation, performance bottlenecks, and difficulty in maintenance and debugging. Summary of the invention

[0005] Based on the above problems, the present application provides a thread pool management method, device, equipment and medium, which can optimize resource allocation, avoid resource waste and performance bottlenecks while avoiding the problems of multiple thread pools being dispersed, unevenly allocated resources and difficult to track, and by monitoring the thread pool, avoid the expansion of problems and the collapse of the thread pool.

[0006] The embodiments of the present application disclose the following technical solutions:

[0007] In a first aspect, the present application discloses a thread pool management method, the method comprising:

[0008] Creating a thread pool service table, wherein the thread pool service table includes at least one thread parameter, wherein the thread parameter includes a thread pool name, a number of core threads, a maximum number of threads, and a thread idle survival time, and the value of the thread parameter is updated in real time;

[0009] Dynamically create at least one thread pool by reading the value of the thread parameter in the thread pool business table;

[0010] By monitoring the thread pool, the current running state of the thread pool is obtained;

[0011] When the current running state meets the preset alarm condition, an alarm indication is triggered.

[0012] Optionally, obtaining the current running state of the thread pool by monitoring the thread pool includes:

[0013] Collecting operation data of the thread pool periodically or in real time, the operation data including at least one of the number of threads in the thread pool, the length of the task queue, the number of completed tasks, and the number of rejected tasks;

[0014] By analyzing the operation data, the current operation status of the thread pool is obtained, and the current operation status includes at least one of the load condition of the thread pool, the thread utilization rate, and whether the configuration upper limit of the thread pool is reached.

[0015] Optionally, the current running status includes the number of queue backlog tasks;

[0016] When the current running state meets the preset alarm condition, triggering an alarm indication includes:

[0017] When the number of queue backlog tasks in the thread pool is greater than a preset backlog threshold, an alarm indication is triggered.

[0018] Optionally, the current running state includes the number of executed tasks and the number of unexecuted tasks of the thread pool; the method further includes:

[0019] According to the number of executed tasks and the number of unexecuted tasks, the values ​​of thread parameters in the thread pool service table are updated.

[0020] Optionally, after executing the dynamically creating at least one thread pool, the method further includes:

[0021] Assigning a unique identifier to each of the thread pools;

[0022] The identifier of the thread pool and the value of the thread parameter are saved in a memory, so as to obtain the value of the thread parameter corresponding to the identifier in the memory through the identifier.

[0023] In a second aspect, an embodiment of the present application discloses a thread pool management device, the device comprising: a business table creation module, a thread pool creation module, a state acquisition module and an alarm indication module;

[0024] The service table creation module is used to create a thread pool service table, wherein the thread pool service table includes at least one thread parameter, wherein the thread parameter includes the thread pool name, the number of core threads, the maximum number of threads and the thread idle survival time, and the value of the thread parameter is updated in real time;

[0025] The thread pool creation module is used to dynamically create at least one thread pool by reading the values ​​of the thread parameters in the thread pool business table;

[0026] The state acquisition module obtains the current running state of the thread pool by monitoring the thread pool;

[0027] The alarm indication module is used to trigger an alarm indication when the current operating state meets a preset alarm condition.

[0028] Optionally, the state acquisition module includes: a first acquisition module and a second acquisition module;

[0029] The first acquisition module is used to collect the operation data of the thread pool periodically or in real time, wherein the operation data includes at least one of the number of threads in the thread pool, the length of the task queue, the number of completed tasks, and the number of rejected tasks;

[0030] The second acquisition module is used to obtain the current running state of the thread pool by analyzing the running data, and the current running state includes at least one of the load condition of the thread pool, the thread utilization rate and whether the configuration upper limit of the thread pool is reached.

[0031] Optionally, the current running status includes the number of queue backlog tasks;

[0032] The alarm indication module is specifically used to trigger an alarm indication when the number of queue backlog tasks in the thread pool is greater than a preset backlog threshold.

[0033] Optionally, the current running state includes the number of executed tasks and the number of unexecuted tasks of the thread pool; the device further includes: a parameter updating module;

[0034] The parameter updating module is used to update the values ​​of the thread parameters in the thread pool service table according to the number of executed tasks and the number of unexecuted tasks.

[0035] Optionally, the device further includes: an identification allocation module and a parameter acquisition module;

[0036] The identifier allocation module is used to allocate a unique identifier to each thread pool;

[0037] The parameter acquisition module is used to save the identifier of the thread pool and the value of the thread parameter into a memory, so as to acquire the value of the thread parameter corresponding to the identifier in the memory through the identifier.

[0038] In a third aspect, the present application discloses a thread pool management device, the device comprising: a memory and a processor;

[0039] The memory is used to store programs;

[0040] The processor is used to execute the program to implement the various steps of the thread pool management method as described in the first aspect.

[0041] In a fourth aspect, the present application discloses a computer-readable medium having a computer program stored thereon, and when the computer program is executed by a processor, the various steps of the thread pool management method described in the first aspect are implemented.

[0042] Compared with the prior art, this application has the following beneficial effects:

[0043] The embodiment of the present application provides a thread pool management method, device, equipment and medium, the method comprising: creating a thread pool business table, the thread pool business table includes at least one thread parameter, the thread parameter includes the thread pool name, the number of core threads, the maximum number of threads and the thread idle survival time, and the value of the thread parameter is updated in real time; by reading the value of the thread parameter in the thread pool business table, dynamically creating at least one thread pool; by monitoring the thread pool, obtaining the current running state of the thread pool; when the current running state meets the preset alarm condition, triggering an alarm indication. Thus, the present application realizes the centralized management of all thread pools by introducing the thread pool business table, so that the administrator can obtain the configuration information of each thread pool, thereby avoiding the problems of multiple thread pools being dispersedly configured, unevenly allocated resources and difficult to track. In addition, the parameter values ​​in the thread pool business table support real-time updates, which means that the configuration of the thread pool can be dynamically adjusted and at least one thread pool can be created according to the actual operation situation and business needs, thereby helping to optimize resource allocation and avoid resource waste and performance bottlenecks. Further, the present application can also obtain the current running state of the thread pool in real time. When the current running status reaches the preset alarm condition, an alarm indication will be triggered, which will help to discover potential problems in time and take appropriate measures to deal with them, avoiding the expansion of problems and the collapse of the thread pool. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0045] Figure 1 A flowchart of a thread pool management method provided in an embodiment of the present application;

[0046] Figure 2 A flowchart of another thread pool management method provided in an embodiment of the present application;

[0047] Figure 3 A schematic diagram of a thread pool management device provided in an embodiment of the present application;

[0048] Figure 4 A schematic diagram of a computer-readable medium provided for an embodiment of the present application. DETAILED DESCRIPTION

[0049] As described above, whether you use Thread Pool Executor directly or use Spring's @Async annotation to create and manage thread pools, it is easy to encounter the problem of multiple thread pools not being centrally managed. Especially in large software systems, there may be problems such as uneven resource allocation, performance bottlenecks, and difficulty in maintenance and debugging.

[0050] After research, the inventor has proposed a thread pool management method, device, equipment and medium. This application realizes centralized management of all thread pools by introducing a thread pool business table, so that the administrator can obtain the configuration information of each thread pool, thereby avoiding the problems of multiple thread pools being dispersedly configured, unevenly allocated resources, and difficult to track. In addition, the parameter values ​​in the thread pool business table support real-time updates, which means that the configuration of the thread pool can be dynamically adjusted and at least one thread pool can be created according to the actual operation situation and business needs, thereby helping to optimize resource allocation and avoid resource waste and performance bottlenecks. Further, this application can also obtain the current running state of the thread pool in real time. When the current running state reaches the preset alarm condition, an alarm indication will be triggered, thereby helping to discover potential problems in a timely manner, and taking corresponding measures to deal with them, avoiding the expansion of problems and the collapse of the thread pool. In summary, through the comprehensive effects of centralized management, dynamic adjustment, monitoring and alarm mechanisms, the technical solution of this application helps to improve the stability and reliability of the software system, and avoid the software system crash or performance degradation caused by uneven resource allocation or performance bottlenecks.

[0051] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0052] See also Figure 1 , which is a flow chart of a thread pool management method provided by an embodiment of the present application. The method includes:

[0053] S101: Create a thread pool business table, which includes at least one thread parameter. The thread parameter includes a thread pool name, a number of core threads, a maximum number of threads, and a thread idle survival time. The values ​​of the thread parameters are updated in real time.

[0054] The thread pool service table includes at least one thread parameter, which is a key indicator for defining the behavior of the thread pool. In the thread pool management method disclosed in the embodiment of the present application, the thread parameters may include the thread pool name, the number of core threads, the maximum number of threads, and the thread idle survival time.

[0055] Among them, the thread pool name is used to uniquely distinguish different thread pools in the software system. Through the thread pool name, system administrators or developers can easily identify and reference specific thread pools. The number of core threads is the number of threads that always remain alive in the thread pool, and they will not be destroyed even if they are idle. The number of core threads determines the lower limit of the number of tasks that the thread pool can handle simultaneously. The maximum number of threads is the maximum number of threads allowed in the thread pool. When the number of tasks in the task queue exceeds the processing capacity of the core threads, the thread pool will create new threads to handle these tasks, but the total number of threads will not exceed this maximum value. The thread idle survival time is the maximum time that a thread waits for a new task before being automatically destroyed after remaining idle. If a thread does not receive a new task during this time, it will be considered no longer needed and removed from the thread pool.

[0056] In addition, the values ​​of thread parameters are updated in real time, which means that the values ​​of thread parameters can be dynamically modified during the operation of the software system. This real-time update capability enables the software system to flexibly adjust the configuration of the thread pool according to the actual workload and performance requirements. For example, when the software system load increases, the number of core threads or the maximum number of threads can be increased to improve processing power; when the software system load decreases, the number of core threads or the maximum number of threads can be reduced to save resources.

[0057] S102: Dynamically create at least one thread pool by reading the values ​​of thread parameters in the thread pool business table.

[0058] First, the thread parameter values ​​in the thread pool business table are read and parsed. Then, based on the values ​​of the parsed thread parameters, the software system dynamically creates at least one thread pool. The created thread pool will initialize and manage its internal thread resources according to the values ​​of these thread parameters.

[0059] It should be noted that in order to facilitate the management and access of the thread pool, the software system may store the created thread pool reference somewhere, such as a data structure in memory or a database table. In this way, the software system can quickly locate the corresponding thread pool through the reference and perform corresponding operations, such as submitting tasks, closing thread pools, etc.

[0060] It should also be noted that the execution of "dynamically creating at least one thread pool" may not be a one-time operation, but may be repeated as the software system runs and thread parameters are updated. For example, when the system administrator modifies the values ​​of thread parameters in the thread pool business table, the software system may re-read the values ​​of these thread parameters and dynamically adjust or re-create the thread pool according to the new thread parameters. This application does not limit this.

[0061] It should also be noted that each thread pool can also be assigned a unique identifier (ID), which can be a number, a string, or any other data type that can uniquely distinguish different thread pools. Next, the thread pool identifier and the corresponding thread parameter values ​​(such as the number of core threads, the maximum number of threads, the thread idle survival time, etc.) are saved in memory. Storing data in memory can significantly improve access speed, because the read and write speed of memory is much faster than that of storage devices such as hard disks. After the thread pool identifier and the thread parameter value are saved in memory, the software system can quickly obtain the thread parameter value corresponding to the identifier through the thread pool identifier. This mechanism makes the configuration information of the thread pool queryable and updateable. When the software system needs to adjust the configuration of the thread pool, it only needs to find the corresponding thread pool identifier and then modify the parameter value associated with it.

[0062] S103: Obtain the current running status of the thread pool by monitoring the thread pool.

[0063] In order to monitor the thread pool, the operation data of the thread pool can be collected regularly or in real time, such as the number of threads in the thread pool (including the number of core threads, the number of active threads, the number of idle threads, etc.), the length of the task queue, the number of completed tasks, the number of rejected tasks, etc. These operation data can be obtained through the API interface or management tool provided by the thread pool. Subsequently, by analyzing the collected operation data, the current operation status of the thread pool can be obtained. Including the load of the thread pool (such as whether the task queue is congested), thread utilization (i.e., the ratio of the number of active threads to the total number of threads), and whether the configuration upper limit of the thread pool (such as the maximum number of threads) has been reached.

[0064] It should be noted that in order to better track and analyze the running status of the thread pool, the monitored running data and current running status can also be recorded in logs. These logs can be used as historical data for subsequent performance analysis, troubleshooting or auditing purposes.

[0065] S104: When the current operating state meets the preset alarm condition, an alarm indication is triggered.

[0066] During the configuration phase, the administrator will preset a series of alarm conditions based on factors such as thread pool performance indicators, business requirements, and software system tolerance. These alarm conditions are usually related to the current running status of the thread pool, such as the length of the task queue in the thread pool exceeds a certain threshold, the number of active threads in the thread pool continues to be higher than a certain ratio, and the number of tasks rejected by the thread pool increases sharply in a short period of time.

[0067] After the current running state of the thread pool is obtained through step S103, the monitored current running state can be compared with the preset alarm condition to determine whether the current running state meets any alarm condition. If the current running state meets one or some preset alarm conditions, an alarm indication will be triggered.

[0068] The warning indication can be in various forms, such as sending emails, SMS notifications, displaying warning information on the software system interface, etc. The purpose of the warning indication is to attract the attention of administrators or relevant personnel, so that administrators or relevant personnel can understand the current problems of the thread pool and take measures to deal with them as soon as possible, such as increasing the resources of the thread pool (such as increasing the number of core threads or the maximum number of threads), optimizing the allocation and execution strategy of tasks, checking and repairing the reasons that lead to task rejection or abnormal execution, etc.

[0069] It should be noted that after the administrator or relevant personnel handles the alarm, they need to provide feedback on the processing results and adjust the preset alarm conditions according to the actual situation, so as to ensure that the alarm mechanism of the software system is always synchronized with business needs and system status, and improve the reliability and stability of the software system.

[0070] In summary, the present application discloses a thread pool management method, which realizes centralized management of all thread pools by introducing a thread pool business table, so that the administrator can obtain the configuration information of each thread pool, thereby avoiding the problems of multiple thread pools being dispersedly configured, unevenly allocated resources, and difficult to track. In addition, the parameter values ​​in the thread pool business table support real-time updates, which means that the configuration of the thread pool can be dynamically adjusted and at least one thread pool can be created according to the actual operation situation and business needs, thereby helping to optimize resource allocation and avoid resource waste and performance bottlenecks. Further, the present application can also obtain the current running state of the thread pool in real time. When the current running state reaches the preset alarm condition, an alarm indication will be triggered, thereby helping to discover potential problems in a timely manner, and taking corresponding measures to deal with them, avoiding the expansion of problems and the collapse of the thread pool. In summary, through the comprehensive effects of centralized management, dynamic adjustment, monitoring and alarm mechanisms, the technical solution of the present application helps to improve the stability and reliability of the software system, and avoid the software system crash or performance degradation caused by uneven resource allocation or performance bottlenecks.

[0071] See also Figure 2 , which is a flow chart of another thread pool management method provided by an embodiment of the present application. The method includes:

[0072] S201: Create and initialize a thread pool.

[0073] When the application starts, you need to create and initialize the thread pool in the Spring configuration through the @Bean annotation, thereby ensuring that the thread pool is ready when the Spring container starts and can be used directly in the business logic. It should be noted that the thread pool created and initialized here is not a centrally managed thread pool.

[0074] For example, the code to create a thread pool can be as follows:

[0075]

[0076] S202: A centrally managed thread pool is obtained by creating a new thread pool business table, creating and implementing an interface for creating a thread pool, creating and implementing an interface for destroying a thread pool, and reading values ​​of thread parameters in the thread pool business table.

[0077] When multiple thread pools are needed, thread pools with different parameters such as threadPoolExecutor1, threadPoolExecutor2, and threadPoolExecutor3 can be created to adapt to different business needs. However, if the number of thread pools increases, the management difficulty will also increase. Therefore, centralized management of thread pools is required to achieve configuration of creating new thread pools and changing thread pool parameters to avoid hard coding.

[0078] In order to realize the centralized management of thread pool, a new thread pool service table (THREAD_POOL_LIST) can be created, and parameters such as thread pool name, number of core threads, maximum number of threads, thread idle survival time, etc. can be stored in the thread pool service table, so that the parameters of thread pool can be adjusted by modifying the configuration information in the new thread pool service table without modifying the code. Exemplarily, the code of the new thread pool service table can be as follows:

[0079]

[0080]

[0081]

[0082] In some specific implementations, in order to achieve centralized management of the thread pool, a new interface for creating a thread pool can be created and implemented. The interface for creating a thread pool can be an InitializingBean interface. Exemplarily, the code for creating a new InitializingBean interface can be as follows:

[0083] / **

[0084] *Function DescriptionBusiness Thread Pool Set

[0085] ** /

[0086] @Slf4j

[0087] @Service

[0088] public class CommThreadPoolService implements InitializingBean{}

[0089] And, after creating the InitializingBean interface, you need to override the afterPropertiesSet method. For example, the code for overriding the afterPropertiesSet method of InitializingBean can be as follows:

[0090]

[0091]

[0092] When the interface is newly created and the method is rebuilt, the Spring container will automatically call the afterPropertiesSet method after all bean properties are set (that is, after the bean dependency injection is completed), thereby automatically executing the initialization logic. Among them, the initialization logic may include: reading in the business table data of the business thread pool, which means that some database operations will be performed inside the method to retrieve configuration information related to the business thread pool from the database. This configuration information may include the number of core threads, the maximum number of threads, the survival time, etc. of the thread pool. The initialization logic may also include: creating thread pools in sequence, that is, according to the configuration information retrieved from the database, the afterPropertiesSet method will create multiple thread pools in a loop. The configuration of each thread pool (such as the number of core threads, the maximum number of threads, etc.) is based on the corresponding configuration information read from the database.

[0093] Therefore, when the Spring container starts, the thread pool is dynamically configured and initialized according to business needs so that it can be used in subsequent runs of the application. This approach makes the configuration of the thread pool more flexible and configurable, and can be adjusted according to different business needs and environments.

[0094] In some other specific implementations, in order to realize the centralized management of the thread pool, a new interface for destroying the thread pool may be created and implemented. The interface for destroying the thread pool may be a DisposableBean interface. For example, the code for creating a new DisposableBean interface may be as follows:

[0095] / **

[0096] *Function DescriptionBusiness Thread Pool Set

[0097] ** /

[0098] @Slf4j

[0099] @Service

[0100] public class CommThreadPoolService implements DisposableBean{}

[0101] And, after creating a new DisposableBean interface, you need to rewrite the destroy method. For example, the code for rewriting the destroy method of DisposableBean can be as follows:

[0102]

[0103] When you create this interface and rebuild this method, the Spring container will automatically call the destroy method before destroying the beans it manages (that is, when the container is closed or the application context is closed), thereby closing the thread pools of all businesses. This means that you need to ensure that all thread pools created and managed by the application are properly closed before the Spring container is destroyed. The thread pool is closed to avoid resource leaks, ensure that all executing tasks have a chance to complete (this depends on the configuration of the thread pool, such as whether to allow tasks to complete when closed), and release system resources occupied by the thread pool.

[0104] After the thread pool service table is subsequently established, at least one thread pool may be dynamically created according to the values ​​of the thread parameters in the thread pool service table.

[0105] S203: Encapsulate the centrally managed thread pool.

[0106] Since ThreadPoolExecutor itself does not provide monitoring and alarm functions, it is usually necessary to encapsulate the centrally managed thread pool in order to add these functions. Specifically, encapsulation can include any one or more of monitoring, alarming, and logging. Among them, monitoring refers to recording the status of the thread pool, such as the length of the task queue, the number of active threads, etc., by extending ThreadPoolExecutor or using aspect-oriented programming. Alarming refers to triggering an alarm mechanism to notify developers or system administrators when the thread pool status reaches a certain threshold (such as the task queue is too long, new tasks are rejected, etc.) based on the monitored data. Logging refers to recording the key operations performed by the thread pool for debugging and tracking when problems occur.

[0107] It should be noted that by implementing centralized management of thread pools, multiple thread pools can be managed more flexibly, hard coding can be reduced, and the maintainability and scalability of the code can be improved. By configuring thread pool parameters, the performance of the thread pool can be easily adjusted to adapt to different business scenarios. At the same time, the monitoring and alarm functions can ensure the stable operation of the thread pool and detect and solve problems in a timely manner.

[0108] S204: Obtain the current running status of the thread pool by monitoring the thread pool.

[0109] Although the parameter configuration of the thread pool has a decisive impact on business operations, in actual applications, it is often impossible to accurately predict which parameter settings are optimal. Currently, configuration can only be performed based on experience, testing, or a rough estimate of the business load, so the configuration accuracy is low. Therefore, it is necessary to monitor the thread pool status to understand the operation of the thread pool.

[0110] In order to monitor the status of the thread pool, a ThreadPoolMonitor class needs to be created. Since the ThreadPoolMonitor class inherits all methods and properties from the ThreadPoolExecutor class in the Java concurrency package, and allows developers to rewrite these methods or add new methods to expand or modify the behavior of the original thread pool, it is possible to add custom functions while maintaining the basic functions of the thread pool, such as monitoring the operation of the thread pool (such as task execution time, thread pool status, etc.), and issuing alarms when necessary. In this way, developers can dynamically adjust the configuration of the thread pool according to the actual operation situation to optimize the performance and stability of the system. Exemplary, the code to create the ThreadPoolMonitor class can be as follows:

[0111] public class ThreadPoolMonitor extends ThreadPoolExecutor{}}

[0112] It should be noted that the HashMap and thread pool name need to be initialized before monitoring.

[0113] For example, the code to initialize the HashMap and thread pool name can be as follows:

[0114]

[0115] In some specific implementations, a variable of type ThreadLocal, startTimeThreadLocal, can be defined and the beforeExecute method can be overridden to record the start time of the task before the task is executed. For example, the code for defining a variable of type ThreadLocal, startTimeThreadLocal, and overriding the beforeExecute method can be as follows:

[0116]

[0117] In another specific implementation, a variable startTimeThreadLocal of ThreadLocal type can be defined and the afterExecute method can be rewritten to record the execution time (i.e., end time) of the task after the task is executed. Subsequently, by combining the start time and execution time of the same task, the longest execution time of the thread, the shortest execution time of the thread, the average execution time of the thread, and the status of the thread pool can be calculated. Exemplarily, the code for obtaining the data such as the longest execution time of the thread and the shortest execution time of the thread can be as follows:

[0118]

[0119]

[0120]

[0121] In other specific implementations, you can also override the shutdown method to count the thread pool status when the thread pool is delayed in shutdown. Specifically, in Java's ThreadPoolExecutor class, the shutdown() method is used to start the thread pool shutdown sequence. Once shutdown() is called, the thread pool will no longer accept new tasks, but will continue to execute tasks that have been submitted to the queue until all tasks are completed. If you want to count the thread pool status during the delayed shutdown of the thread pool, or count the thread pool status at a specific time of shutdown, you need to override the shutdown() method to meet this requirement. Exemplarily, the code to override the shutdown method can be as follows:

[0122]

[0123] In some other specific implementations, a thread factory (ThreadFactory) interface can also be created. Each thread is named by passing the thread name in the ThreadFactory interface. In this way, even if there are multiple thread pools running in the same application, it is possible to immediately identify which thread pool the thread belongs to, thereby locating the problem more quickly. Exemplarily, the code for rewriting the default thread factory of the thread pool can be as follows: static classMonitorThreadFactory

[0124]

[0125]

[0126] It should be noted that the ThreadPoolExecutor in the business thread pool class needs to be changed to ThreadPoolMonitor, so as to achieve more detailed monitoring and management of the thread pool operation by inheriting and extending the functions of ThreadPoolExecutor. After the final operation, the following effect can be obtained:

[0127] 16:32:52.278[obank_voucher_query-pool-13-thread-4]INFO

[0128] com.nbcb.tms.application.service.common.ThreadPoolMonitor:

[0129] Thread pool obank_voucher_query, task takes 13ms, the longest execution time so far is 22ms, the shortest execution time is 9ms, and the average execution time is 13ms. Current thread pool situation, the number of completed tasks is 8, the total number of tasks is 9, the number of queued tasks is 0, the maximum number of threads in the pool is 5, the maximum number of threads allowed is 10, and the current number of active threads is 1.

[0130] S205: When the current running state meets the preset alarm condition, an alarm indication is triggered.

[0131] In some specific implementations, the current running status includes the number of queue backlog tasks. When the number of queue backlog tasks of the thread pool is greater than the preset backlog threshold, it usually means that the thread pool has approached or reached the limit of its processing capacity and cannot process newly submitted tasks in time, resulting in a backlog of tasks in the queue. Therefore, an alarm indication needs to be triggered. The alarm can remind the administrator or system monitoring personnel to pay attention to the current status of the thread pool and take corresponding measures to solve the problem, such as increasing the resources of the thread pool (such as increasing the number of core threads or the maximum number of threads), optimizing the allocation and execution strategy of tasks, and reducing the submission speed of new tasks.

[0132] In some other specific implementations, the current running state includes the number of executed tasks and the number of unexecuted tasks of the thread pool. Then, the values ​​of the thread parameters in the thread pool business table can be updated according to the number of executed tasks and the number of unexecuted tasks. For example, if the task backlog rate continues to be high, the software system may consider increasing the number of core threads or the maximum number of threads in the thread pool to improve processing capabilities. Once it is determined which parameters need to be adjusted, the software system can update the corresponding values ​​in the thread pool business table.

[0133] In summary, the present application discloses a thread pool management method, which realizes centralized management of all thread pools by introducing a thread pool business table, so that the administrator can obtain the configuration information of each thread pool, thereby avoiding the problems of multiple thread pools being dispersedly configured, unevenly allocated resources, and difficult to track. In addition, the parameter values ​​in the thread pool business table support real-time updates, which means that the configuration of the thread pool can be dynamically adjusted and at least one thread pool can be created according to the actual operation situation and business needs, thereby helping to optimize resource allocation and avoid resource waste and performance bottlenecks. Further, the present application can also obtain the current running state of the thread pool in real time. When the current running state reaches the preset alarm condition, an alarm indication will be triggered, thereby helping to discover potential problems in a timely manner, and taking corresponding measures to deal with them, avoiding the expansion of problems and the collapse of the thread pool. In summary, through the comprehensive effects of centralized management, dynamic adjustment, monitoring and alarm mechanisms, the technical solution of the present application helps to improve the stability and reliability of the software system, and avoid the software system crash or performance degradation caused by uneven resource allocation or performance bottlenecks.

[0134] See also Figure 3 , which is a schematic diagram of a thread pool management device provided by the present application. The thread pool management device 300 includes: a business table creation module 301, a thread pool creation module 302, a state acquisition module 303 and an alarm indication module 304.

[0135] The service table creation module 301 is used to create a thread pool service table, which includes at least one thread parameter, including the thread pool name, the number of core threads, the maximum number of threads and the thread idle survival time, and the value of the thread parameter is updated in real time;

[0136] The thread pool creation module 302 is used to dynamically create at least one thread pool by reading the values ​​of thread parameters in the thread pool business table;

[0137] The status acquisition module 303 obtains the current running status of the thread pool by monitoring the thread pool;

[0138] The alarm indication module 304 is used to trigger an alarm indication when the current operating state meets a preset alarm condition.

[0139] Optionally, the state acquisition module 303 includes: a first acquisition module and a second acquisition module;

[0140] A first acquisition module is used to collect operation data of the thread pool periodically or in real time, where the operation data includes at least one of the number of threads in the thread pool, the length of the task queue, the number of completed tasks, and the number of rejected tasks;

[0141] The second acquisition module is used to obtain the current running state of the thread pool by analyzing the running data. The current running state includes at least one of the load condition of the thread pool, the thread utilization rate and whether the configuration upper limit of the thread pool is reached.

[0142] Optionally, the current running status includes the number of queue backlog tasks;

[0143] The alarm indication module 304 is specifically used to trigger an alarm indication when the number of queue backlog tasks of the thread pool is greater than a preset backlog threshold.

[0144] Optionally, the current running state includes the number of executed tasks and the number of unexecuted tasks of the thread pool; the thread pool management device 300 further includes: a parameter updating module;

[0145] The parameter update module is used to update the values ​​of thread parameters in the thread pool business table according to the number of executed tasks and the number of unexecuted tasks.

[0146] Optionally, the thread pool management device 300 further includes: an identification allocation module and a parameter acquisition module;

[0147] The identification allocation module is used to assign a unique identification to each thread pool;

[0148] The parameter acquisition module is used to save the identifier of the thread pool and the value of the thread parameter into the memory, so as to obtain the value of the thread parameter corresponding to the identifier in the memory through the identifier.

[0149] In summary, the present application discloses a thread pool management device, which realizes centralized management of all thread pools by introducing a thread pool business table, so that the administrator can obtain the configuration information of each thread pool, thereby avoiding the problems of multiple thread pools being dispersedly configured, unevenly allocated resources, and difficult to track. In addition, the parameter values ​​in the thread pool business table support real-time updates, which means that the configuration of the thread pool can be dynamically adjusted and at least one thread pool can be created according to the actual operation situation and business needs, thereby helping to optimize resource allocation and avoid resource waste and performance bottlenecks. Further, the present application can also obtain the current running state of the thread pool in real time. When the current running state reaches the preset alarm condition, an alarm indication will be triggered, thereby helping to discover potential problems in a timely manner, and taking corresponding measures to deal with them, avoiding the expansion of problems and the collapse of the thread pool. In summary, through the comprehensive effects of centralized management, dynamic adjustment, monitoring and alarm mechanisms, the technical solution of the present application helps to improve the stability and reliability of the software system, and avoid the software system crash or performance degradation caused by uneven resource allocation or performance bottlenecks.

[0150] The embodiment of the present application also provides a corresponding thread pool management device and a computer-readable medium for implementing the thread pool management method provided in the embodiment of the present application.

[0151] Among them, the thread pool management device includes a memory and a processor, the memory is used to store instructions or codes, and the processor is used to execute instructions or codes so that the device executes a thread pool management method of any embodiment of the present application.

[0152] See also Figure 4 , which is a schematic diagram of a computer-readable medium provided in an embodiment of the present application. The computer-readable medium 400 stores a computer program 411, which implements the above-mentioned Figure 1 Steps of the thread pool management method.

[0153] It should be noted that in the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0154] It should be noted that the machine-readable medium mentioned above in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0155] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0156] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.

[0157] Although several specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present application. Certain features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination.

[0158] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.

Claims

1. A thread pool management method, characterized in that: The method comprises: Creating a thread pool service table, wherein the thread pool service table includes at least one thread parameter, wherein the thread parameter includes a thread pool name, a number of core threads, a maximum number of threads, and a thread idle survival time, and the value of the thread parameter is updated in real time; Dynamically create at least one thread pool by reading the value of the thread parameter in the thread pool business table; By monitoring the thread pool, the current running status of the thread pool is obtained; When the current running state meets the preset alarm condition, an alarm indication is triggered.

2. The method according to claim 1, characterized in that The monitoring of the thread pool to obtain the current running state of the thread pool includes: Collecting operation data of the thread pool periodically or in real time, the operation data including at least one of the number of threads in the thread pool, the length of the task queue, the number of completed tasks, and the number of rejected tasks; By analyzing the operation data, the current operation status of the thread pool is obtained, and the current operation status includes at least one of the load condition of the thread pool, the thread utilization rate, and whether the configuration upper limit of the thread pool is reached.

3. The method according to claim 1, characterized in that The current running status includes the number of queue backlog tasks; When the current running state meets the preset alarm condition, triggering an alarm indication includes: When the number of queue backlog tasks in the thread pool is greater than a preset backlog threshold, an alarm indication is triggered.

4. The method according to claim 1, characterized in that: The current running state includes the number of executed tasks and the number of unexecuted tasks of the thread pool; the method further includes: According to the number of executed tasks and the number of unexecuted tasks, the values ​​of thread parameters in the thread pool service table are updated.

5. The method according to claim 1, characterized in that After executing the dynamically creating at least one thread pool, the method further includes: Assigning a unique identifier to each of the thread pools; The identifier of the thread pool and the value of the thread parameter are saved in a memory, so as to obtain the value of the thread parameter corresponding to the identifier in the memory through the identifier.

6. A thread pool management device, characterized in that: The device comprises: a business table creation module, a thread pool creation module, a state acquisition module and an alarm indication module; The service table creation module is used to create a thread pool service table, wherein the thread pool service table includes at least one thread parameter, wherein the thread parameter includes the thread pool name, the number of core threads, the maximum number of threads and the thread idle survival time, and the value of the thread parameter is updated in real time; The thread pool creation module is used to dynamically create at least one thread pool by reading the values ​​of the thread parameters in the thread pool business table; The state acquisition module obtains the current running state of the thread pool by monitoring the thread pool; The alarm indication module is used to trigger an alarm indication when the current operating state meets a preset alarm condition.

7. The device according to claim 6, characterized in that The state acquisition module includes: a first acquisition module and a second acquisition module; The first acquisition module is used to collect the operation data of the thread pool periodically or in real time, wherein the operation data includes at least one of the number of threads in the thread pool, the length of the task queue, the number of completed tasks, and the number of rejected tasks; The second acquisition module is used to obtain the current running state of the thread pool by analyzing the running data, and the current running state includes at least one of the load condition of the thread pool, the thread utilization rate and whether the configuration upper limit of the thread pool is reached.

8. The device according to claim 6, characterized in that The current running status includes the number of queue backlog tasks; The alarm indication module is specifically used to trigger an alarm indication when the number of queue backlog tasks in the thread pool is greater than a preset backlog threshold.

9. A thread pool management device, characterized in that: The device comprises: a memory and a processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the thread pool management method as described in any one of claims 1 to 5.

10. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the thread pool management method according to any one of claims 1 to 5 is implemented.