A method for resource isolation of multi-thread based on thread pool
By designing thread pool objects and filters, the problem of resource contention among different transaction channels was solved, independent resource processing was achieved, and the system's processing capacity and efficiency were improved.
Patent Information
- Application Number
- CN202311270253.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-27
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-09-27
AI Technical Summary
In non-financial transaction systems across different channels, resource constraints can lead to transaction query failures.
By using a thread pool-based resource isolation method, a task queue is created using a thread pool object, thread pool isolation switches and filters are defined, and different serviceID lists and thread pool configuration strategies are defined according to channel resources to achieve resource isolation and control.
This enables independent resource processing for transactions from different channels, avoiding resource contention and improving the system's processing capacity and efficiency.
Smart Images

Figure CN117311969B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of multi-threaded resource isolation technology, specifically a method for resource isolation of multiple threads based on a thread pool. Background Technology
[0002] In our frequently used non-financial trading systems, we often need to process transactions from different channels. Because transactions from different channels compete for resources, transaction queries may fail due to resource shortages. Therefore, we need a method to isolate the resources of different channels in our system to ensure that transactions from different channels have independent resources for processing, so that transactions are not affected. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this invention provides a method for resource isolation of multiple threads based on a thread pool, which solves the problems of resource contention between transactions from different channels and transaction query failures due to resource shortages between non-financial transactions from different channels.
[0004] To achieve the above objectives, the present invention provides the following technical solution: a method for resource isolation of multiple threads based on a thread pool, comprising the following steps: S1: First, use the thread pool functionality provided by the programming language or framework to create a thread pool object. The thread pool can pre-create a certain number of threads and provide a task queue to store tasks to be executed. S2: By defining a thread pool isolation switch, when the switch is on and the transaction is a non-financial XML transaction, tasks are distributed through the thread pool. Then, by defining service names for different resources, one service name corresponds to one channel, requiring configuration of service names for all channels and defining resource service list enumeration values. By defining service ID list parameters for different resources, one service ID corresponds to one non-financial transaction, with different service ID lists defined for different channel resources. The service ID list then needs to be initialized to the corresponding resource service name. Different thread pool XML configuration strategies are defined for services of different resources, requiring the number of threads in the thread pool to be configured according to the actual needs of the service, thereby improving system processing capacity and efficiency. A filter is defined to configure the thread pool service ID list, used to match the corresponding thread pool for transaction forwarding. S3: By defining the task to be executed, you can identify the task by adapting it to a thread or runnable object; then submit the task to the thread pool, which will select a suitable thread to execute the task based on its own configuration and status. You can then use the task submission method provided by the thread pool to add the task to the task queue. S4: Thread pools can limit the number of threads, CPU usage, memory quota, etc., according to configured parameters. By limiting these resources, resource isolation and control can be achieved during multi-threaded execution. S5: Receives non-financial XML transaction messages via a non-financial front-end. Then, by parsing the non-financial transaction message, it obtains the message's serviceID. The thread pool isolation switch is enabled, and the transaction is a non-financial XML transaction. This allows it to enter the thread pool isolation service's routing strategy. It searches for the thread pool service name to which the non-financial transaction belongs based on the serviceID list, and then enters the filter based on the thread pool service name to find the corresponding thread pool service. If the thread pool service exists, it enters the corresponding thread pool for service processing and forwarding. If the thread pool service processing fails, it enters the exception policy, assembles the return message, and returns the message. S6: Different non-financial transactions enter different thread pool services, thereby ensuring the isolation of thread pool resources. Different non-financial transactions are independent of each other and are not affected.
[0005] A system for resource isolation of multiple threads based on a thread pool includes a resource isolation class. The resource isolation class includes a variable definition module. The output of the variable definition module is electrically connected to a transaction processing module. The output of the transaction processing module is electrically connected to an execution task module. The purpose of this design is to control the overall flow of data and to implement corresponding functions through the variable definition module, transaction processing module, and execution task module.
[0006] Preferably, the variable definition module includes a switch definition unit, the output of which is electrically connected to a service name definition unit, the output of which is electrically connected to a list parameter definition unit, the output of which is electrically connected to an initialization unit, the output of which is electrically connected to a configuration strategy definition unit, and the output of which is electrically connected to a filter definition unit. By defining a thread pool isolation switch, when the switch is enabled and the transaction is a non-financial XML transaction, tasks are distributed through the thread pool. Then, by defining service names for different resources, one service name corresponds to one channel, and the service names for all channels need to be configured. Define a resource service list enumeration value; define a service ID list parameter for different resources, with one service ID corresponding to one non-financial transaction, and define different service ID lists for resources from different channels; then initialize the service ID list to the service name of the corresponding resource; define different thread pool XML configuration strategies for services of different resources, and configure the number of threads in the thread pool according to the actual needs of the service to improve the system's processing capacity and efficiency; define a filter to configure the thread pool service ID list, which is used to match the corresponding thread pool for transaction forwarding.
[0007] Preferably, the defined configuration strategy unit includes a defined service ID unit, the output of which is electrically connected to a defined minimum maintenance unit, the output of which is electrically connected to a defined maximum maintenance unit, and the output of which is electrically connected to a defined buffer queue quantity unit. By defining the minimum and maximum number of thread pools and the number of thread pool buffer queues, these resources can be limited, enabling resource isolation and control during multi-threaded execution. By defining the tasks to be executed, tasks can be identified by threads or runnable objects. The tasks are then submitted to the thread pool, which selects appropriate threads to execute the tasks based on its own configuration and status. The task submission method provided by the thread pool can then be used to add tasks to the task queue.
[0008] Preferably, the transaction processing unit module includes a receiving unit, the output of which is electrically connected to a parsing unit, the output of which is electrically connected to a judgment switch unit, the output of which is electrically connected to a resource name judgment unit, the output of which is electrically connected to a filter matching unit, and the output of which is electrically connected to a corresponding thread pool service processing unit. The process involves receiving non-financial XML transaction messages through a non-financial front-end, then parsing the non-financial transaction messages to obtain the message's serviceID, enabling the thread pool isolation switch, and confirming that the transaction is a non-financial XML transaction. This allows for the implementation of a thread pool isolation service's traffic distribution strategy. By searching the list of non-financial transaction service IDs, the system finds the thread pool service name to which the non-financial transaction belongs. Then, based on the thread pool service name, it enters a filter to find the corresponding thread pool service. If the thread pool service exists, the transaction is processed and forwarded within that service. If the thread pool service fails, an exception handling strategy is implemented, assembling and returning a response message. Different non-financial transactions enter different thread pool services, thus ensuring the isolation of thread pool resources. Different non-financial transactions are independent and unaffected by each other.
[0009] Working Principle: First, using the thread pool functionality provided by the programming language or framework, a thread pool object is created. The thread pool can pre-create a certain number of threads and provide a task queue to store tasks to be executed. By defining a thread pool isolation switch, when the switch is on and the transaction is a non-financial XML transaction, tasks are distributed through the thread pool. Then, by defining service names for different resources (one service name per channel, requiring configuration of service names for all channels) and defining resource service list enumeration values, and by defining service ID list parameters for different resources (one service ID corresponds to one non-financial transaction), different service ID lists are defined based on the resources of different channels. The service ID list then needs to be initialized to the corresponding resource service name. Different thread pool XML configuration strategies are defined for services of different resources, and the number of threads in the thread pool needs to be configured according to the actual needs of the service to improve system processing capacity and efficiency. A filter is defined to configure the thread pool service ID list, used to match the corresponding thread pool for transaction forwarding. By defining the tasks to be executed, tasks can be identified by threads or runnable objects. Then... Tasks are submitted to the thread pool, which selects appropriate threads to execute the tasks based on its configuration and status. Tasks can be added to the task queue using the thread pool's submission method. The thread pool can limit the number of threads, CPU usage, memory quotas, etc., according to configured parameters, achieving resource isolation and control during multi-threaded execution. Non-financial XML transaction messages are received by a non-financial front-end. The message's serviceID is obtained by parsing the non-financial transaction message. The thread pool isolation switch is enabled, and the transaction is a non-financial XML transaction, thus entering the thread pool's isolation service's routing strategy. The service ID list of non-financial transactions is used to find the corresponding thread pool service name. The service name is then used to enter a filter to find the appropriate thread pool service. If the thread pool service exists, it is processed and forwarded. If the thread pool service fails, an exception policy is implemented, and a return message is assembled and returned. Different non-financial transactions enter different thread pool services, ensuring the isolation of thread pool resources. Different non-financial transactions are independent and unaffected by each other.
[0010] This invention provides a method for resource isolation of multiple threads based on a thread pool. It has the following beneficial effects: This invention creates an independent task queue for each task in a thread pool. Each task's queue is specifically used to store the subtasks or operations that the task needs to execute. When a task is added to the task queue, each task is associated with the thread that executes it. Thread-local storage can be used to implement the association between threads and tasks, ensuring that each task is only executed by its associated thread. Furthermore, during the execution of a task, the task can independently manage its own resources, thereby enabling each task to function like an independent process with its own resource space. Attached Figure Description
[0011] Figure 1 This is a schematic diagram of the method framework of the present invention; Figure 2 This is a system framework diagram of the present invention; Figure 3 This is a system diagram of the variable definition module of the present invention; Figure 4 This is a system diagram of the configuration strategy unit defined in this invention; Figure 5 This is a system diagram of the transaction processing module of the present invention. Detailed Implementation
[0012] 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.
[0013] Example: Please see the appendix Figure 1 - Appendix Figure 5 This invention provides a method for resource isolation of multiple threads based on a thread pool, comprising the following steps: S1: First, use the thread pool functionality provided by the programming language or framework to create a thread pool object. The thread pool can pre-create a certain number of threads and provide a task queue to store tasks to be executed. S2: By defining a thread pool isolation switch, when the switch is on and the transaction is a non-financial XML transaction, tasks are distributed through the thread pool. Then, by defining service names for different resources, one service name corresponds to one channel, requiring configuration of service names for all channels and defining resource service list enumeration values. By defining service ID list parameters for different resources, one service ID corresponds to one non-financial transaction, with different service ID lists defined for different channel resources. The service ID list then needs to be initialized to the corresponding resource service name. Different thread pool XML configuration strategies are defined for services of different resources, requiring the number of threads in the thread pool to be configured according to the actual needs of the service, thereby improving system processing capacity and efficiency. A filter is defined to configure the thread pool service ID list, used to match the corresponding thread pool for transaction forwarding. S3: By defining the task to be executed, you can identify the task by adapting it to a thread or runnable object; then submit the task to the thread pool, which will select a suitable thread to execute the task based on its own configuration and status. You can then use the task submission method provided by the thread pool to add the task to the task queue. S4: Thread pools can limit the number of threads, CPU usage, memory quota, etc., according to configured parameters. By limiting these resources, resource isolation and control can be achieved during multi-threaded execution. S5: Receives non-financial XML transaction messages via a non-financial front-end. Then, by parsing the non-financial transaction message, it obtains the message's serviceID. The thread pool isolation switch is enabled, and the transaction is a non-financial XML transaction. This allows it to enter the thread pool isolation service's routing strategy. It searches for the thread pool service name to which the non-financial transaction belongs based on the serviceID list, and then enters the filter based on the thread pool service name to find the corresponding thread pool service. If the thread pool service exists, it enters the corresponding thread pool for service processing and forwarding. If the thread pool service processing fails, it enters the exception policy, assembles the return message, and returns the message. S6: Different non-financial transactions enter different thread pool services, thereby ensuring the isolation of thread pool resources. Different non-financial transactions are independent of each other and are not affected.
[0014] A system for resource isolation of multiple threads based on a thread pool includes a resource isolation class, which includes a variable definition module. The output of the variable definition module is electrically connected to a transaction processing module, and the output of the transaction processing module is electrically connected to an execution task module. The purpose of this design is to control the overall flow of data and to implement corresponding functions through the variable definition module, transaction processing module, and execution task module.
[0015] The variable definition module includes a switch definition unit, whose output is electrically connected to a service name definition unit, whose output is electrically connected to a list parameter definition unit, whose output is electrically connected to an initialization unit, whose output is electrically connected to a configuration strategy definition unit, and whose output is electrically connected to a filter definition unit. By defining a thread pool isolation switch, when the switch is on and the transaction is a non-financial XML transaction, tasks are distributed through the thread pool. Then, by defining service names for different resources (one service name per channel), the service names for all channels need to be configured, and resource service list enumeration values need to be defined. By defining service ID list parameters for different resources (one service ID corresponds to one non-financial transaction), different service ID lists are defined based on the resources of different channels. The service ID list then needs to be initialized to the corresponding resource service name. Different thread pool XML configuration strategies are defined for services of different resources, and the number of threads in the thread pool needs to be configured according to the actual needs of the service to improve system processing capacity and efficiency. Finally, a filter is defined to configure the thread pool service ID list, used to match the corresponding thread pool for transaction forwarding.
[0016] The configuration strategy definition unit includes a service ID definition unit. The output of the service ID definition unit is electrically connected to a minimum maintenance unit, the output of the minimum maintenance unit is electrically connected to a maximum maintenance unit, and the output of the maximum maintenance unit is electrically connected to a buffer queue size unit. By defining the minimum and maximum number of threads in the thread pool and the number of thread pool buffer queues, these resources can be limited, enabling resource isolation and control during multi-threaded execution. By defining the tasks to be executed, tasks can be identified by threads or runnable objects. The tasks are then submitted to the thread pool, which selects appropriate threads to execute the tasks based on its own configuration and state. Tasks can then be added to the task queue using the task submission methods provided by the thread pool.
[0017] The transaction processing unit module includes a receiving unit, whose output is electrically connected to a parsing unit. The output of the parsing unit is electrically connected to a judgment switch unit, whose output is electrically connected to a resource name judgment unit, whose output is electrically connected to a filter matching unit, and whose output is electrically connected to a corresponding thread pool service processing unit. It receives non-financial XML transaction messages from a non-financial front-end, then parses the non-financial transaction message to obtain the message's serviceID. The thread pool isolation switch is then activated, and since the transaction is a non-financial XML transaction, it can enter the thread pool isolation service's routing strategy. The system searches for the thread pool service name to which the non-financial transaction belongs based on the non-financial transaction's serviceID list, and then uses the filter to find the corresponding thread pool service. If the thread pool service exists, it enters the corresponding thread pool for processing and forwarding. If the thread pool service processing fails, an exception policy is implemented, and a return message is assembled and returned. Different non-financial transactions enter different thread pool services, thus ensuring the isolation of thread pool resources. Different non-financial transactions are independent and unaffected by each other.
[0018] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method for resource isolation of multithreading based on thread pool, characterized in that, Includes the following steps: S1: First, use the thread pool functionality provided by the programming language or framework to create a thread pool object. The thread pool can pre-create a certain number of threads and provide a task queue to store tasks to be executed. S2: By defining a thread pool isolation switch, when the switch is on and the transaction is a non-financial XML transaction, tasks are distributed through the thread pool. Then, by defining service names for different resources, one service name corresponds to one channel, requiring configuration of service names for all channels and defining resource service list enumeration values. By defining service ID list parameters for different resources, one service ID corresponds to one non-financial transaction, with different service ID lists defined for different channel resources. The service ID list then needs to be initialized to the corresponding resource service name. Different thread pool XML configuration strategies are defined for services of different resources, requiring the number of threads in the thread pool to be configured according to the actual needs of the service, thereby improving system processing capacity and efficiency. A filter is defined to configure the thread pool service ID list, used to match the corresponding thread pool for transaction forwarding. S3: By defining the task to be executed, you can identify the task by adapting it to a thread or runnable object; then submit the task to the thread pool, which will select a suitable thread to execute the task based on its own configuration and status. You can then use the task submission method provided by the thread pool to add the task to the task queue. S4: Thread pools can limit the number of threads, CPU usage, and memory quotas according to configured parameters. By limiting these resources, resource isolation and control can be achieved during multi-threaded execution. S5: Receives non-financial XML transaction messages via a non-financial front-end. Then, by parsing the non-financial transaction message, it obtains the message's serviceID. The thread pool isolation switch is enabled, and the transaction is a non-financial XML transaction. This allows it to enter the thread pool isolation service's routing strategy. It searches for the thread pool service name to which the non-financial transaction belongs based on the serviceID list, and then enters the filter based on the thread pool service name to find the corresponding thread pool service. If the thread pool service exists, it enters the corresponding thread pool for service processing and forwarding. If the thread pool service processing fails, it enters the exception policy, assembles the return message, and returns the message. S6: Different non-financial transactions enter different thread pool services, thereby ensuring the isolation of thread pool resources. Different non-financial transactions are independent of each other and are not affected.
Citation Information
Patent Citations
Transaction channel management method and device, server and storage medium
CN110175830A
Method for improving high availability of in-line front-end system based on distributed current limiting of sentinel
CN113806096A
Scheduling system and method for resource service applications in enterprise digital middle station
CN114036031A
