Method and device for thread resource allocation

By receiving task processing requests and reallocating thread resources in the server program, the problem of low system efficiency caused by frequent thread creation and destruction is solved, and flexible adjustment of thread resources and priority processing of important business are achieved.

CN109783229BInactive Publication Date: 2024-10-01CHINA MOBILE M2M
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN201811541874.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-12-17
Publication Date
2024-10-01
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In server programs based on the client/server model, frequent creation and destruction of threads will greatly reduce system efficiency. The thread pool technology has a single reuse form, poor flexibility, and low applicability.

Method used

By receiving task processing requests, the task priority is determined and the thread pool is divided. If there are no idle threads in the target sub-resource thread pool, the thread resources of other tasks are reallocated to perform important business tasks to achieve flexible adjustment and tilt of thread resources.

Benefits of technology

It improves the flexibility and applicability of thread resource allocation, realizes real-time resource adjustment for important businesses, and improves system efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN109783229B_ABST
    Figure CN109783229B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a method and device for thread resource allocation, which is suitable for business process optimization, and the method includes: receiving a task processing request triggered by a target business, determining the task identifier and task priority of the target task requested for processing; if the task priority of the target task is the first priority, determining the target sub-resource thread pool corresponding to the target task according to the task identifier; if there are no idle thread resources for executing the target task in the target sub-resource thread pool, reallocating thread resources for executing other tasks in the target sub-resource thread pool to obtain target thread resources for executing the target task; and executing the target task based on the target thread resources. The embodiment of the present application adopts the embodiment of the present application, which has the advantage of being able to achieve a tilt towards important businesses when allocating thread resources, thereby improving the flexibility of thread resource allocation.
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 method and device for allocating thread resources. Background Art

[0002] With the development of science and technology and the popularization of network technology, people have a growing demand for various types of services, and have put forward higher and higher requirements for the processing level of computers. In server programs based on the client / server model, in order to make full use of existing hardware resources, people have proposed multi-threading technology to solve the problem of concurrent execution of multiple threads. However, if there are a large number of concurrent threads, and each thread executes a very short task and then ends, such frequent thread creation will greatly reduce the efficiency of the system, because frequent thread creation and destruction takes time. Based on this, in order to reduce the creation time and destruction time of threads, people have proposed thread pool technology, which allows threads to be reused, that is, after executing a task, they are not destroyed, but can continue to execute other tasks. However, this method has a single form of thread reuse, poor flexibility, and low applicability. Summary of the invention

[0003] The embodiments of the present application provide a method and device for allocating thread resources, which can realize the inclination of thread resources to important businesses, improve the flexibility of thread resource allocation, and have high applicability.

[0004] In a first aspect, an embodiment of the present application provides a method for thread resource allocation, the method comprising:

[0005] Receive a task processing request triggered by a target business, and determine a task identifier and a task priority of the target task requested to be processed by the task processing request;

[0006] If the task priority of the target task is the first priority, determining the target sub-resource thread pool corresponding to the target task according to the task identifier;

[0007] If there are no idle thread resources for executing the target task in the target sub-resource thread pool, thread resources for executing other tasks in the target sub-resource thread pool are reallocated to obtain target thread resources for executing the target task, the task priorities of the other tasks include the second priority, and the processing order of tasks corresponding to the first priority takes precedence over the processing order of tasks corresponding to the second priority;

[0008] The target task is executed based on the target thread resources.

[0009] In combination with the first aspect, in a possible implementation manner, before receiving the task processing request triggered by the target service, the method further includes:

[0010] Dividing a resource thread pool including multiple thread resources into multiple sub-resource thread pools, wherein one sub-resource thread pool includes at least one thread resource, and the multiple sub-resource thread pools include at least the target sub-resource thread pool;

[0011] Setting the thread pool identifier of each sub-resource thread pool in the above multiple sub-resource thread pools;

[0012] The thread pool identifier of any sub-resource thread pool is used to determine the tasks that the thread resources in any sub-resource thread pool are used to execute.

[0013] In combination with the first aspect, in a possible implementation manner, determining the target sub-resource thread pool corresponding to the target task according to the task identifier includes:

[0014] The target thread pool identifier corresponding to the task identifier is determined from the thread pool identifiers of the above-mentioned sub-resource thread pools, and the sub-resource thread pool corresponding to the above-mentioned target thread pool identifier is determined as the target sub-resource thread pool corresponding to the above-mentioned target task.

[0015] In combination with the first aspect, in a possible implementation manner, before determining the task identifier and task priority of the target task requested to be processed by the task processing request, the method further includes:

[0016] Acquire at least two task types, wherein tasks of the same task type in the at least two task types are marked by the same task identifier;

[0017] The task priorities corresponding to the various task types among the at least two task types are set, wherein the task priorities at least include the first priority and the second priority, and the task priorities corresponding to the various task types are used to determine the processing order of the tasks of the various task types.

[0018] In combination with the first aspect, in a possible implementation manner, the method further includes:

[0019] A group of semaphores corresponding to the above-mentioned sub-resource thread pools is set, wherein one semaphore in the group of semaphores corresponding to any sub-resource thread pool is used to indicate the number of thread resources used to execute tasks of a task type in any of the above-mentioned sub-resource thread pools;

[0020] When it is found that the number of thread resources indicated by the first semaphore corresponding to the target sub-resource thread pool is empty, it is determined that there are no idle thread resources in the target sub-resource thread pool for executing the target task;

[0021] The first semaphore is used to indicate the number of thread resources in the target sub-resource thread pool used to execute tasks of the first task type, and the tasks of the first task type include the target task.

[0022] In combination with the first aspect, in a possible implementation manner, the above-mentioned thread resource reallocation of the thread resources used to execute other tasks in the above-mentioned target sub-resource thread pool includes:

[0023] Modifying the first semaphore to increase the number of thread resources indicated by the first semaphore;

[0024] Modify a second semaphore other than the first semaphore in a group of semaphores corresponding to the target sub-resource thread pool to reduce the number of thread resources indicated by the second semaphore;

[0025] The second semaphore is used to indicate the number of thread resources in the target sub-resource thread pool used to execute tasks of a second task type, and the tasks of the second task type include the other tasks.

[0026] In a second aspect, an embodiment of the present application provides a thread resource allocation device, the device comprising:

[0027] A receiving unit, configured to receive a task processing request triggered by a target business, and determine a task identifier and a task priority of a target task requested to be processed by the task processing request;

[0028] a matching unit, configured to determine a target sub-resource thread pool corresponding to the target task according to the task identifier when the receiving unit determines that the task priority of the target task is the first priority;

[0029] an allocation unit, configured to reallocate thread resources for executing other tasks in the target sub-resource thread pool to obtain target thread resources for executing the target task when there are no idle thread resources for executing the target task in the target sub-resource thread pool, wherein the task priority of the other task also includes a second priority, and a processing order of tasks corresponding to the first priority takes precedence over a processing order of tasks corresponding to the second priority;

[0030] An execution unit is used to execute the target task based on the target thread resources reallocated by the allocation unit.

[0031] In conjunction with the second aspect, in a possible implementation manner, the above device further includes:

[0032] A division unit, used for dividing a resource thread pool including a plurality of thread resources into a plurality of sub-resource thread pools, wherein a sub-resource thread pool includes at least one thread resource, and the plurality of sub-resource thread pools include at least the target sub-resource thread pool;

[0033] The partitioning unit is further used to set the thread pool identifier of each sub-resource thread pool in the above-mentioned multiple sub-resource thread pools;

[0034] The thread pool identifier of any sub-resource thread pool is used to determine the tasks that the thread resources in any sub-resource thread pool are used to execute.

[0035] In combination with the second aspect, in a possible implementation, the above-mentioned matching unit is specifically used to determine the target thread pool identifier corresponding to the above-mentioned task identifier from the thread pool identifiers of the above-mentioned sub-resource thread pools, and determine the sub-resource thread pool corresponding to the above-mentioned target thread pool identifier as the target sub-resource thread pool corresponding to the above-mentioned target task.

[0036] In conjunction with the second aspect, in a possible implementation manner, the above device further includes:

[0037] An acquisition unit, used for acquiring at least two task types, wherein tasks of the same task type in the at least two task types are marked by the same task identifier;

[0038] The acquisition unit is also used to set the task priorities corresponding to various task types among the above-mentioned at least two task types, and the above-mentioned task priorities include at least the above-mentioned first priority and the above-mentioned second priority. The task priorities corresponding to the above-mentioned various task types are used to determine the processing order of tasks of the above-mentioned various task types.

[0039] In conjunction with the second aspect, in a possible implementation manner, the allocation unit is specifically configured to:

[0040] A group of semaphores corresponding to the above-mentioned sub-resource thread pools is set, wherein one semaphore in the group of semaphores corresponding to any sub-resource thread pool is used to indicate the number of thread resources used to execute tasks of a task type in any of the above-mentioned sub-resource thread pools;

[0041] When it is found that the number of thread resources indicated by the first semaphore corresponding to the target sub-resource thread pool is empty, it is determined that there are no idle thread resources in the target sub-resource thread pool for executing the target task;

[0042] The first semaphore is used to indicate the number of thread resources in the target sub-resource thread pool used to execute tasks of the first task type, and the tasks of the first task type include the target task.

[0043] In conjunction with the second aspect, in a possible implementation manner, the allocation unit is specifically configured to:

[0044] Modifying the first semaphore to increase the number of thread resources indicated by the first semaphore;

[0045] Modify a second semaphore other than the first semaphore in a group of semaphores corresponding to the target sub-resource thread pool to reduce the number of thread resources indicated by the second semaphore;

[0046] The second semaphore is used to indicate the number of thread resources in the target sub-resource thread pool used to execute tasks of a second task type, and the tasks of the second task type include the other tasks.

[0047] In a third aspect, an embodiment of the present application provides a terminal device, the terminal device includes a processor and a memory, the processor and the memory are connected to each other. The memory is used to store a computer program that supports the terminal device to execute the method provided by the first aspect and / or any possible implementation of the first aspect, the computer program includes program instructions, and the processor is configured to call the program instructions to execute the method provided by the first aspect and / or any possible implementation of the first aspect.

[0048] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and the computer program includes program instructions, which, when executed by a processor, enable the processor to execute the method provided by the above-mentioned first aspect and / or any possible implementation method of the first aspect.

[0049] Implementing the embodiments of the present application has the following beneficial effects:

[0050] The method provided in the embodiment of the present application can monitor the usage of thread resources allocated to the tasks triggered by executing each business, and then can achieve the inclination towards important businesses when reallocating thread resources, and can flexibly adjust the thread resources in real time, and has high applicability. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] 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 work.

[0052] Figure 1 It is a flowchart of a method for thread resource allocation provided in an embodiment of the present application;

[0053] Figure 2 is another flowchart of the method for thread resource allocation provided by an embodiment of the present application;

[0054] Figure 3 It is a structural diagram of a device for thread resource allocation provided in an embodiment of the present application;

[0055] Figure 4 It is a schematic diagram of the structure of the terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0056] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions 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.

[0057] The method and device for thread resource allocation provided in the embodiments of the present application can be applied to terminal devices such as smart phones, desktop computers, laptops, tablet computers, and wearable devices, and the specific application scenarios can be determined according to the actual application scenarios, and are not limited here. For the convenience of description, the embodiments of the present application will be described by taking the terminal device as an example.

[0058] The thread resource allocation method provided by the embodiment of the present application can be widely applied to various online business handling systems. The user selects the target business to be handled through the business operation interface of the client. After receiving the task processing request triggered by the target business to be handled by the above user, the server can determine the task identification and task priority of the target task by parsing the information carried by the key fields in the above task processing request. Then, the target sub-resource thread pool responsible for executing the above target task is determined by the correspondence between the established task identification and the thread pool identification of the sub-resource thread pool. When there are idle thread resources for executing the above target task in the above target sub-resource thread pool, the above target task is directly executed using the idle thread resources; when there are no idle thread resources for executing the above target task in the above target sub-resource thread pool and the above target task belongs to the first priority task triggered by the important business, the thread resource reallocation operation is performed in the target sub-resource thread pool, and a part of the thread resources used to execute other tasks are allocated to the execution of the above target task. The method provided by the embodiment of the present application can monitor the usage of the thread resources allocated to the tasks triggered by executing each business, and can achieve the inclination to the important business when reallocating the thread resources, and can make flexible adjustments to the thread resources in real time, and has high applicability.

[0059] The following will be combined Figures 1 to 4The method and device provided in the embodiments of the present application are described in detail. The method provided in the embodiments of the present application can be used for data processing stages including thread pool division, task type acquisition, task processing request reception, determination of the target sub-resource thread pool corresponding to the target task, thread resource allocation, and target task execution. The implementation methods of the above-mentioned data processing stages can be found as follows Figure 1 to Figure 2 The implementation shown.

[0060] See also Figure 1 , Figure 1 A flowchart of a method for thread resource allocation provided in an embodiment of the present application. Figure 1 As shown, the method provided in the embodiment of the present application may include the following steps:

[0061] S1. Receive a task processing request triggered by a target business, and determine a task identifier and a task priority of the target task requested to be processed by the task processing request.

[0062] In some feasible implementations, multi-threaded concurrency is commonly seen in application scenarios including background multi-task parallel processing of web servers and / or other various dedicated servers. For example, common multi-threaded concurrency application scenarios include background multi-task parallel processing of various types of servers, such as scheduled sending of emails to a large number (more than 1 million) of users, multi-task asynchronous processing, multi-task data distributed computing, etc.

[0063] In some feasible implementations, the terminal device receives a task processing request triggered by a user when handling a business, wherein the task processing request includes a processing task and a key field. Generally, the user sends a task processing request to the server by using the application software installed on the terminal device. Among them, the application software includes but is not limited to instant messaging software, shopping software, search software, mailbox client, leisure and entertainment software, etc., which can be determined according to the actual application scenario and are not limited here. The above-mentioned task identifier is used to uniquely mark the task type, and the above-mentioned task type may include a computing task, a communication task, a query task, a search task, etc., which can be determined according to the actual application scenario and are not limited here. The above-mentioned task identifier can be a key character extracted from the characteristics of the task type or the algorithm for executing the task or a character without special meaning. Among them, the above-mentioned task type also corresponds to a task priority, and the above-mentioned task priority includes at least a first priority and a second priority. The task priorities of various task types are used to determine the processing order of the tasks corresponding to the above-mentioned various task types, and the processing order of the tasks corresponding to the above-mentioned first priority takes precedence over the processing order of the tasks corresponding to the above-mentioned second priority. For example, assuming there are only two types of tasks, when the task is triggered by an important business or a business with high timeliness requirements, the task priority of the above task is set to the first priority; when the above task is not triggered by an important business or a business with high timeliness requirements, the task priority of the above task is set to the second priority. After receiving the task processing request triggered by the above target business, the server can obtain the information about the task identification and task priority of the target task carried in the key fields of the task processing request by parsing the above task processing request, and then determine the task identification and task priority of the above target task through the above information.

[0064] For example, suppose a user sends a voice call task processing request through an instant messaging software on a terminal device. The voice call task processing request includes a voice call task and a key field, where the voice call task is the target task. When the server receives the voice call task processing request, it parses the voice call task processing request and obtains information about the task identifier and task priority of the voice call task carried in the key field of the voice call task processing request. Based on the information obtained, the task identifier and task priority of the voice call task are determined to be "communication" and "first priority" respectively.

[0065] S2. If the task priority of the target task is the first priority, determine the target sub-resource thread pool corresponding to the target task according to the task identifier.

[0066] In some feasible implementations, a resource thread pool including N thread resources is divided into n sub-resource thread pools according to business needs and a thread pool identifier of each sub-resource thread pool is set, wherein each of the above n sub-resource thread pools includes at least one thread resource, and the thread resource is used to execute the received task. It is understandable that, in order to facilitate the unified management of resources, there is a uniquely determined correspondence between the task identifier and the thread pool identifier and this correspondence is one-to-one. That is, a task identifier can only correspond to one thread pool identifier, and the correspondence can be established by the identifier matching between the task identifier and the thread pool identifier. Therefore, after receiving the target task, according to the task identifier of the target task, a thread pool identifier that meets the identifier matching relationship with the task identifier of the target task can be found from the n thread pool identifiers, and the sub-resource thread pool corresponding to the thread pool identifier that meets the matching relationship is determined as the target sub-resource thread pool corresponding to the above target task.

[0067] S3. If there are no idle thread resources in the target sub-resource thread pool for executing the target task, thread resources in the target sub-resource thread pool for executing other tasks are reallocated to obtain target thread resources for executing the target task.

[0068] In some feasible implementations, after the target task enters the target sub-resource thread pool, it can be determined by query whether there are available idle thread resources for executing the target task in the target sub-resource thread pool. It is understandable that when it is found that there are available idle thread resources for executing the target task, the target task is executed using the idle thread resources; and when it is found that there are no available idle thread resources for executing the target task, that is, when the thread resources for executing the target task are all occupied at the current moment, the thread resources are reallocated. When the thread resources are reallocated, the number of thread resources used by other tasks in the target sub-resource thread pool is reduced by a certain proportion, and the number of target thread resources used for executing the target task is increased.

[0069] S4. Execute the target task based on the target thread resources.

[0070] In some feasible implementations, after the thread resources are reallocated, the target task is executed based on the target thread resources. Since starting a task thread will occupy certain thread resources, in order to avoid waste of resources, after the target task is executed, the occupied thread resources are released to complete resource recycling, and the recycled thread resources are waiting for next use in the thread pool.

[0071] In the embodiment of the present application, the user first sends a task processing request to the server through the application software installed on the terminal device. After receiving the task processing request triggered by the target business, the server can obtain the information about the task identification and task priority carried in the key field in the task processing request by parsing the above-mentioned task processing request, and the task identification and task priority of the target task can be determined by the above-mentioned information. Then, the thread pool identification corresponding to the task identification of the above-mentioned target task is found through the identification matching relationship between the task identification and the thread pool identification, and the sub-resource thread pool corresponding to the above-mentioned thread pool identification is determined as the target sub-resource thread pool corresponding to the above-mentioned target task. If the task priority of the above-mentioned target task is the first priority, when it is found that there is no idle thread resource for executing the above-mentioned target task in the above-mentioned target sub-resource thread pool, the operation of thread resource reallocation is performed in the target sub-resource thread pool, and a part of the thread resources used to execute other tasks are allocated to the execution of the above-mentioned target task and finally execute the target task. The method provided in the embodiment of the present application can monitor the usage of the thread resources allocated to the tasks triggered by the execution of each business, and can achieve the inclination of important businesses when reallocating thread resources, and can make flexible adjustments to thread resources in real time, and has high applicability.

[0072] Figure 2 Another flowchart of the method for thread resource allocation provided by an embodiment of the present application is as follows: Figure 2 As shown, the method provided in the embodiment of the present application may include the following steps:

[0073] S21. Divide a resource thread pool including multiple thread resources into multiple sub-resource thread pools, and set a thread pool identifier of each of the multiple sub-resource thread pools.

[0074] In some feasible implementations, since the tasks triggered by a certain identical or similar business or business with similar processing flow are divided into a sub-resource thread pool as much as possible to achieve the maximum utilization of resources and the centralized management of resources, the resource thread pool containing N thread resources can be divided into n sub-resource thread pools according to business parameters, and the above-mentioned business parameters include but are not limited to business types or business processing flows or execution algorithms, which can be determined according to actual application scenarios and are not limited here. Among them, the above-mentioned n sub-resource thread pools include the above-mentioned target sub-resource thread pool and each sub-resource thread pool in the n sub-resource thread pools includes at least 1 thread resource. Then set the thread pool identifier of each sub-resource thread pool in the above-mentioned n sub-resource thread pools, wherein the thread pool identifier can be a key character or a character without special meaning extracted from the characteristics or algorithms of a series of tasks executed by the above-mentioned sub-resource thread pools, and the thread pool identifier is used to uniquely distinguish the sub-resource thread pools responsible for processing different tasks. For example, the thread pool identifier can be the key character "calculation", "communication", "query", "search" or the character "a", "b", "c", "d" without special meaning.

[0075] S22: Acquire at least two task types, and set task priorities corresponding to each task type in the at least two task types.

[0076] In some feasible implementations, at least two task types are obtained from a task database, and tasks of the same task type in the at least two task types are marked by the same task identifier. For example, the task types may include computing tasks, communication tasks, query tasks, search tasks, etc. Among them, the task identifier may be a key character extracted from the characteristics of the task type or the algorithm for executing the task, or a character without special meaning. For example, the task identifier may be the key characters "computing", "communication", "query", "search" extracted from the above task types, or characters without special meaning "1", "2", "3", "4".

[0077] Among them, the task priorities corresponding to various task types in the above-mentioned at least two task types are set, and the above-mentioned task priorities include at least a first priority and a second priority. The task priorities corresponding to the above-mentioned various task types are used to determine the processing order of the tasks of the above-mentioned various task types. Among them, the processing order of the tasks corresponding to the above-mentioned first priority takes precedence over the processing order of the tasks corresponding to the above-mentioned second priority. For example, it is assumed that there are two types of tasks, namely communication tasks and query tasks. Among them, in instant messaging software, communication tasks are usually tasks with high timeliness requirements or important tasks, while query tasks are not tasks with high timeliness requirements or important tasks. Therefore, when setting the task priority, the above-mentioned communication tasks are set to the first priority and the query tasks are set to the second priority. For another example, in a search engine, query tasks are usually tasks with high timeliness requirements or important tasks, while communication tasks are not tasks with high timeliness requirements or important tasks. Therefore, when setting the task priority, the above-mentioned query tasks are set to the first priority and the communication tasks are set to the second priority. When the server receives task processing requests for tasks of the first priority and tasks of the second priority at the same time, it will respond to the processing request of the task of the first priority first. At this time, the task of the second priority can be temporarily shelved in the cache library and started at a scheduled time later.

[0078] S23: Receive a task processing request triggered by a target business, and determine a task identifier and a task priority of the target task requested to be processed by the task processing request.

[0079] In some feasible implementations, the terminal device receives a task processing request triggered by a user when handling a business, wherein the task processing request includes a processing task and a key field. Usually, the user sends a task processing request to the server by using the application software installed on the terminal device. After receiving the task processing request triggered by the target business, the server can obtain the information about the task identification and task priority of the target task carried in the key field of the task processing request by parsing the task processing request, and then determine the task identification and task priority of the target task through the obtained information.

[0080] For example, suppose a user sends a voice call task processing request through an instant messaging software on a terminal device. The voice call task processing request includes a voice call task and a key field, where the voice call task is the target task. When the server receives the voice call task processing request, it parses the voice call task processing request and obtains information about the task identifier and task priority of the voice call task carried in the key field of the voice call task processing request. Based on the information obtained, the task identifier and task priority of the voice call task are determined to be "communication" and "first priority" respectively.

[0081] S24: If the task priority of the target task is the first priority, determine the target sub-resource thread pool corresponding to the target task according to the corresponding relationship between the task identifier and the thread pool identifier.

[0082] In some feasible implementations, when the above-mentioned task identifier and thread pool identifier are key characters extracted from the characteristics or algorithms of the task, after receiving the above-mentioned target task, in order to determine the target sub-resource thread pool corresponding to the above-mentioned target task, it is necessary to traverse all thread pool identifiers, and then match the traversed thread pool identifier with the task identifier of the target task, and finally determine the sub-resource thread pool corresponding to the successfully matched thread pool identifier as the target sub-resource thread pool corresponding to the target task.

[0083] For example, suppose there are only two types of tasks in instant messaging software, namely query tasks and communication tasks, and the above two types of tasks will be executed in two sub-resource thread pools respectively. According to the characteristics or algorithms of the tasks, the key characters "query" and "communication" are extracted as the task identifiers of the above query tasks and communication tasks respectively. Correspondingly, the thread pool identifiers of the sub-resource thread pools responsible for processing these two types of tasks are also set to "query" and "communication" respectively. Therefore, after receiving a new communication task, all thread pool identifiers can be traversed to obtain "query" and "communication" respectively, and then the task identifier "communication" of the above new communication task is used to match the thread pool identifiers "query" and "communication" obtained by traversal. It can be understood that when the task identifier "communication" of the above new communication task matches the traversed thread pool identifier "query", the match will fail; when the task identifier "communication" of the above new communication task matches the traversed thread pool identifier "communication", the match is successful, so the sub-resource thread pool referred to by the thread pool identifier "communication" is determined as the target sub-resource thread pool of the above new communication task.

[0084] Optionally, in some feasible implementations, the series of tasks that the sub-resource thread pool is responsible for executing may not have similar features. Therefore, when the above-mentioned task identifier and thread pool identifier are characters without special meaning, in order to determine the target sub-resource thread pool corresponding to the target task, it is necessary to establish a mapping table of task identifiers and thread pool identifiers in advance, and then after receiving the target task, search the above-mentioned mapping table according to the task identifier of the above-mentioned target task to find the corresponding thread pool identifier, and finally determine the sub-resource thread pool corresponding to the above-mentioned thread pool identifier as the target sub-resource thread pool corresponding to the above-mentioned target task.

[0085] For example, suppose there are three types of tasks, namely type 1, type 2, and type 3, and the above three types of tasks will be executed in three sub-resource thread pools respectively. Therefore, the task identifiers of the three types of tasks are set to 1, 2, and 3 respectively, and the thread pool identifiers of the sub-resource thread pools responsible for executing the three types of tasks are set to a, b, and c respectively. In order to establish the relationship between the task identifier and the thread pool identifier, a mapping table is set. In the mapping table, thread pool identifier a corresponds to task identifier 1, thread pool identifier b corresponds to task identifier 2, and thread pool identifier c corresponds to task identifier 3. Among them, both the thread pool identifier and the task identifier are used to uniquely identify the sub-resource thread pool and the task type. Therefore, when a new task belonging to type 1 is received, the mapping table established above is queried according to the task identifier 1 of type 1, and the thread pool identifier a corresponding to the task identifier 1 can be found, thereby determining that the sub-resource thread pool referred to by the thread pool identifier a is the target sub-resource thread pool for the task of type 1.

[0086] S25. Set a group of semaphores corresponding to the above-mentioned sub-resource thread pools. In the target sub-resource thread pool, when it is found that the number of target thread resources indicated by the semaphore corresponding to the task type corresponding to the above-mentioned target task is empty, modify the various semaphores in the above-mentioned target sub-resource thread pool to adjust the allocation of the above-mentioned target thread resources.

[0087] In some feasible implementations, in response to increasingly abundant business needs, each sub-resource thread pool will correspond to processing tasks of multiple task types in most cases. In order to avoid the task processing request of a task of the same and / or similar task type occupying a large number of thread resources at the same time, thereby causing the task processing request of tasks of other task types to be in a long waiting period, a corresponding set of semaphores can be set for the above-mentioned n sub-resource thread pools. Among them, one semaphore in a set of semaphores corresponding to any sub-resource thread pool is used to indicate the number of thread resources used to execute a task of a task type in any of the above-mentioned sub-resource thread pools. In the target sub-resource thread pool, when the number of target thread resources indicated by the semaphore corresponding to the task type corresponding to the above-mentioned target task is emptied, it is determined that there is no idle thread resource for executing the above-mentioned target task in the above-mentioned target sub-resource thread pool. Therefore, by modifying the semaphore corresponding to the task type corresponding to the above-mentioned target task to increase the number of target thread resources indicated by the semaphore corresponding to the task type corresponding to the above-mentioned target task, modify the other semaphores in a set of semaphores corresponding to the above-mentioned target sub-resource thread pool except the semaphore corresponding to the task type corresponding to the above-mentioned target task to reduce the number of thread resources indicated by the above-mentioned other semaphores. The other semaphore is used to indicate the number of thread resources in the target sub-resource thread pool used to execute tasks of other task types.

[0088] In some feasible implementations, the above-mentioned method of modifying the semaphore includes modifying according to a modification instruction or modifying according to a preset adjustment parameter. Among them, modifying according to a modification instruction means that at each modification, the adjustment amount of each semaphore in each group of semaphores is entered in the modification instruction, and this modification method is more flexible. Modifying according to a preset adjustment parameter means that an adjustment parameter is preset in a machine instruction, for example, the adjustment parameter is set to 1, and the amplitude of the semaphore adjusted each time is added by 1 or subtracted by 1 on the original basis.

[0089] For example, in order to make effective use of thread resources, it is assumed that tasks triggered by insurance-related businesses are processed by a sub-resource thread pool, then the above sub-resource thread pool is the target sub-resource thread pool. Among them, insurance includes life insurance, property insurance, car insurance, travel insurance, etc. Tasks triggered by different insurance businesses include insurance purchase, policy inquiry, insurance claims, etc. For the above target sub-resource thread pool, it is assumed that its maximum number of concurrent threads is 15, that is, there are 15 available thread resources, so a set of semaphores can be set to control the number of thread resources that can be used for each type of insurance to complete various tasks. For example, semaphore 5 is set to indicate that 5 threads are used for life insurance, semaphore 3 is set to indicate that 3 threads are used for property insurance, semaphore 4 is set to indicate that 4 threads are used for car insurance, semaphore 2 is set to indicate that 2 threads are used for travel insurance, and semaphore 1 is set to indicate that 1 thread is used for other types of insurance. It is understandable that when a holiday comes, the number of people planning to travel during the holiday is the largest, and the business handling of travel insurance will be busier than during weekdays. Therefore, before a legal holiday, the task priority of all tasks triggered by the travel insurance business can be set to the first priority. Therefore, before and after the holiday, when a travel insurance purchase request is received, the semaphore set for the travel insurance is queried. When the semaphore is not empty, that is, the current number of thread resources occupied is less than 2 threads, it means that there are available idle threads for executing the purchase request of the travel insurance, so the idle thread resources are used to execute the purchase task. When it is found that the semaphore set for the travel insurance is empty, that is, the current number of thread resources occupied is equal to 2 threads, it means that there are no available idle threads for executing the purchase task request of the travel insurance. Therefore, the thread resources are reallocated, and when the method of modifying the semaphore is selected to modify it by modifying the instruction, the semaphore 4 can be modified to indicate that 4 threads are used for life insurance, the semaphore 3 can be modified to indicate that 3 threads are used for property insurance, the semaphore 4 can be modified to indicate that 4 threads are used for car insurance, the semaphore 3 can be modified to indicate that 3 threads are used for travel insurance, and the semaphore 1 can be modified to indicate that 1 thread is used for other types of insurance.

[0090] Optionally, in some feasible implementations, in order to achieve maximum utilization of thread resources, a borrowing flag is also set for each semaphore, and the borrowing flag includes a flag indicating whether borrowing is required and a flag indicating whether borrowing is allowed. For example, the flag indicating whether borrowing is required is set to 00, the flag indicating whether borrowing is not required is set to 01, the flag indicating whether borrowing is allowed is set to 10, and the flag indicating whether borrowing is not allowed is set to 11. The borrowing condition is met only when the borrower needs to borrow and the borrowee allows borrowing. For example, when it is found that the semaphore of the target task is empty, a borrowing request is made to the semaphore of other tasks with the borrowing mark 00 as needed. When the semaphore of other tasks is not saturated and borrowing is allowed (that is, there is a borrowing mark 10), the borrowing is successful. At this time, the idle thread resources of other tasks are used to execute the target task. When it is found that the semaphore of other tasks is also empty or borrowing is not allowed (that is, there is a borrowing mark 11 that does not allow borrowing), the target task is added to the blocking waiting queue, and an observation signal is set to monitor the blocking waiting time or queue number of the target task, and a blocking waiting time threshold or queue number threshold is set at the same time. The numerical value of the blocking waiting time threshold or queue number threshold is related to the developer's performance requirements for the server. When the blocking waiting time or the number of queues of the above-mentioned target task is less than the blocking waiting time threshold or the queue number threshold, it will wait until the thread resources are released after the execution of the previous task is completed, and then use the released thread resources to execute the above-mentioned target task; when the blocking waiting time or the number of queues of the above-mentioned target task is greater than or equal to the blocking waiting time threshold or the queue number threshold but there are still no idle thread resources, the thread resources will be reallocated, and the allocation method is as mentioned above and will not be repeated here.

[0091] S26. Execute the target task based on the target thread resources.

[0092] In some feasible implementations, after the thread resources are reallocated, the target task is executed based on the target thread resources. Since starting a task thread will occupy certain thread resources, in order to avoid waste of resources, after the target task is executed, the occupied thread resources are released to complete resource recycling, and the recycled thread resources are waiting for next use in the thread pool.

[0093] Optionally, in some feasible implementations, a certain type of high-demand tasks may be parallel tasks, that is, there is no priority level. In this case, services can be provided by adding machines, that is, each machine has an independent semaphore configuration that is only responsible for executing a certain type of high-demand tasks. For details, please refer to the implementation method under the above single machine, which will not be repeated here.

[0094] In an embodiment of the present application, first, at least two types of tasks are obtained in the task database, and the task identifier and task priority of each type of task are set, and the resource thread pool containing N thread resources is divided into n sub-resource thread pools and the thread pool identifier of each sub-resource thread pool is set. Among them, the task identifier and the thread pool identifier are established through identifier matching and / or mapping tables. Then the user sends a task processing request to the server through the application software installed on the terminal device. After receiving the task processing request triggered by the target business, the server can obtain the information carried in the key field in the task processing request by parsing the above task processing request, so as to determine the task identifier and task priority of the target task through the above information. Then, the corresponding relationship between the established task identifier and the thread pool identifier is used to determine the target sub-resource thread pool responsible for executing the above target task. In an embodiment of the present application, in order to avoid the task processing request of a task of the same and / or similar task type occupying a large number of thread resources at the same time, a corresponding set of semaphores is set for the above n sub-resource thread pools. Among them, one semaphore in a set of semaphores corresponding to any sub-resource thread pool is used to indicate the number of thread resources used to execute a task of a task type in any sub-resource thread pool. In the target sub-resource thread pool, when it is found that the number of target thread resources indicated by the semaphore corresponding to the task type corresponding to the above target task is empty, the semaphore is modified to adjust the number of thread resources indicated by the semaphore, and then the reallocated thread resources are used to execute the above target task. The method provided in the embodiment of the present application can monitor the usage of thread resources allocated to the tasks triggered by executing each business, and can achieve inclination to important businesses when reallocating thread resources, and can flexibly adjust thread resources in real time, and has high applicability.

[0095] See also Figure 3 , Figure 3 This is a structural diagram of a device for thread resource allocation provided in the present application. The device for thread resource allocation provided in an embodiment of the present application includes:

[0096] A receiving unit 31 is used to receive a task processing request triggered by a target business, and determine a task identifier and a task priority of a target task requested to be processed by the task processing request;

[0097] A matching unit 32 is configured to determine a target sub-resource thread pool corresponding to the target task according to the task identifier when the receiving unit 31 determines that the task priority of the target task is the first priority;

[0098] The allocation unit 33 is used for reallocating thread resources for executing other tasks in the target sub-resource thread pool to obtain target thread resources for executing the target task when there are no idle thread resources for executing the target task in the target sub-resource thread pool, the task priority of the other tasks also includes a second priority, and the processing order of the tasks corresponding to the first priority takes precedence over the processing order of the tasks corresponding to the second priority;

[0099] The execution unit 34 is used to execute the target task based on the target thread resources reallocated by the allocation unit 33 .

[0100] In some feasible implementations, the thread resource allocation device further includes:

[0101] A dividing unit 35 is used to divide a resource thread pool including multiple thread resources into multiple sub-resource thread pools, wherein one sub-resource thread pool includes at least one thread resource, and the multiple sub-resource thread pools include at least the target sub-resource thread pool;

[0102] The division unit 35 is further used to set the thread pool identifier of each sub-resource thread pool in the above-mentioned multiple sub-resource thread pools;

[0103] The thread pool identifier of any sub-resource thread pool is used to determine the tasks that the thread resources in any sub-resource thread pool are used to execute.

[0104] In some feasible implementations, the matching unit 32 is used to:

[0105] The target thread pool identifier corresponding to the task identifier is determined from the thread pool identifiers of the above-mentioned sub-resource thread pools, and the sub-resource thread pool corresponding to the above-mentioned target thread pool identifier is determined as the target sub-resource thread pool corresponding to the above-mentioned target task.

[0106] In some feasible implementations, the thread resource allocation device further includes:

[0107] An acquiring unit 36 ​​is used to acquire at least two task types, wherein tasks of the same task type in the at least two task types are marked by the same task identifier;

[0108] The acquisition unit 36 ​​is also used to set the task priorities corresponding to various task types among the above-mentioned at least two task types, and the above-mentioned task priorities at least include the above-mentioned first priority and the above-mentioned second priority. The task priorities corresponding to the above-mentioned various task types are used to determine the processing order of tasks of the above-mentioned various task types.

[0109] In some feasible implementations, the allocation unit 33 is used to:

[0110] A group of semaphores corresponding to the above-mentioned sub-resource thread pools is set, wherein one semaphore in the group of semaphores corresponding to any sub-resource thread pool is used to indicate the number of thread resources used to execute tasks of a task type in any of the above-mentioned sub-resource thread pools;

[0111] When it is found that the number of thread resources indicated by the first semaphore corresponding to the target sub-resource thread pool is empty, it is determined that there are no idle thread resources in the target sub-resource thread pool for executing the target task;

[0112] The first semaphore is used to indicate the number of thread resources in the target sub-resource thread pool used to execute tasks of the first task type, and the tasks of the first task type include the target task.

[0113] In some feasible implementations, the allocation unit 33 is used to:

[0114] Modifying the first semaphore to increase the number of thread resources indicated by the first semaphore;

[0115] Modify a second semaphore other than the first semaphore in a group of semaphores corresponding to the target sub-resource thread pool to reduce the number of thread resources indicated by the second semaphore;

[0116] The second semaphore is used to indicate the number of thread resources in the target sub-resource thread pool used to execute tasks of a second task type, and the tasks of the second task type include the other tasks.

[0117] In a specific implementation, the thread resource allocation device can execute the above-mentioned various function modules built in it. Figure 1 to Figure 2The implementation methods provided in each step of the above. For example, the above-mentioned receiving unit 31 can be used to perform the above-mentioned steps of receiving the task processing request triggered by the target business, and determining the task identification and task priority of the target task requested to be processed by the above-mentioned task processing request. For details, please refer to the implementation methods provided in the above-mentioned steps, which will not be repeated here. The above-mentioned matching unit 32 can be used to perform the implementation methods described in the relevant steps of determining the target sub-resource thread pool corresponding to the above-mentioned target task according to the above-mentioned task identification in the above-mentioned steps. For details, please refer to the implementation methods provided in the above-mentioned steps, which will not be repeated here. The above-mentioned allocation unit 33 can be used to perform the implementation methods of setting a group of semaphores corresponding to the above-mentioned sub-resource thread pools, querying the number of thread resources indicated by the first semaphore corresponding to the above-mentioned target sub-resource thread pool, and modifying the above-mentioned first semaphore to increase the number of thread resources indicated by the above-mentioned first semaphore in the above-mentioned steps. For details, please refer to the implementation methods provided in the above-mentioned steps, which will not be repeated here. The above-mentioned execution unit 34 can be used to perform the implementation methods described in the relevant steps of executing the above-mentioned target task based on the above-mentioned target thread resources reallocated by the above-mentioned allocation unit 33 in the above-mentioned steps. For details, please refer to the implementation methods provided in the above-mentioned steps, which will not be repeated here. The above-mentioned division unit 35 can be used to execute the implementation methods such as the division of the thread pool and the setting of the thread pool identifier in the above-mentioned various embodiments. For details, please refer to the implementation methods provided by the above-mentioned various embodiments, which will not be repeated here. The above-mentioned acquisition unit 36 ​​can be used to execute the implementation methods such as obtaining the task type and setting the task identifier and task priority of the above-mentioned task type in the above-mentioned various embodiments. For details, please refer to the implementation methods provided by the above-mentioned various embodiments, which will not be repeated here.

[0118] In an embodiment of the present application, the device for thread resource allocation can obtain at least two task types based on the task database, and then set the task identifier and task priority of any task type, and divide the resource thread pool containing N thread resources into n sub-resource thread pools based on business parameters, set the thread pool identifier of each sub-resource thread pool in the above n sub-resource thread pools, and establish the corresponding relationship between the task identifier and the thread pool identifier. When receiving a task processing request triggered by a target business, the task identifier and priority of the target task are determined based on the information carried in the key field in the task processing request, and the target sub-resource thread pool is found from the n sub-resource thread pools according to the matching relationship between the task identifier and the thread identifier, and the thread resources in the target sub-resource thread pool are reallocated by querying the thread resources responsible for executing the target task in the above target sub-resource thread pool, and finally the target task is executed. The device provided in the embodiment of the present application can monitor the usage of the thread resources allocated to the tasks triggered by executing each business, and can achieve the inclination to important businesses when reallocating thread resources, and can make flexible adjustments to thread resources in real time, and has a wide range of applications.

[0119] See also Figure 4 , Figure 4 Schematic diagram of the structure of the terminal device provided in the embodiment of the present application. Figure 4 As shown, the terminal device in this embodiment may include: one or more processors 401 and a memory 402. The processor 401 and the memory 402 are connected via a bus 403. The memory 402 is used to store a computer program, which includes program instructions. The processor 401 is used to execute the program instructions stored in the memory 402 to perform the following operations:

[0120] Receive a task processing request triggered by a target business, and determine a task identifier and a task priority of the target task requested to be processed by the task processing request;

[0121] If the task priority of the target task is the first priority, determining the target sub-resource thread pool corresponding to the target task according to the task identifier;

[0122] If there are no idle thread resources for executing the target task in the target sub-resource thread pool, thread resources for executing other tasks in the target sub-resource thread pool are reallocated to obtain target thread resources for executing the target task, and the task priority of the other tasks also includes a second priority, and the processing order of tasks corresponding to the first priority takes precedence over the processing order of tasks corresponding to the second priority;

[0123] The target task is executed based on the target thread resources.

[0124] In some feasible implementations, the processor 401 is configured to:

[0125] Dividing a resource thread pool including multiple thread resources into multiple sub-resource thread pools, wherein one sub-resource thread pool includes at least one thread resource, and the multiple sub-resource thread pools include at least the target sub-resource thread pool;

[0126] Setting the thread pool identifier of each sub-resource thread pool in the above multiple sub-resource thread pools;

[0127] The thread pool identifier of any sub-resource thread pool is used to determine the tasks that the thread resources in any sub-resource thread pool are used to execute.

[0128] In some feasible implementations, the processor 401 is configured to:

[0129] The target thread pool identifier corresponding to the task identifier is determined from the thread pool identifiers of the above-mentioned sub-resource thread pools, and the sub-resource thread pool corresponding to the above-mentioned target thread pool identifier is determined as the target sub-resource thread pool corresponding to the above-mentioned target task.

[0130] In some feasible implementations, the processor 401 is configured to:

[0131] Acquire at least two task types, wherein tasks of the same task type in the at least two task types are marked by the same task identifier;

[0132] The task priorities corresponding to the various task types among the at least two task types are set, wherein the task priorities at least include the first priority and the second priority, and the task priorities corresponding to the various task types are used to determine the processing order of the tasks of the various task types.

[0133] In some feasible implementations, the processor 401 is configured to:

[0134] A group of semaphores corresponding to the above-mentioned sub-resource thread pools is set, wherein one semaphore in the group of semaphores corresponding to any sub-resource thread pool is used to indicate the number of thread resources used to execute tasks of a task type in any of the above-mentioned sub-resource thread pools;

[0135] When it is found that the number of thread resources indicated by the first semaphore corresponding to the target sub-resource thread pool is empty, it is determined that there are no idle thread resources in the target sub-resource thread pool for executing the target task;

[0136] The first semaphore is used to indicate the number of thread resources in the target sub-resource thread pool used to execute tasks of the first task type, and the tasks of the first task type include the target task.

[0137] In some feasible implementations, the processor 401 is configured to:

[0138] Modifying the first semaphore to increase the number of thread resources indicated by the first semaphore;

[0139] Modify a second semaphore other than the first semaphore in a group of semaphores corresponding to the target sub-resource thread pool to reduce the number of thread resources indicated by the second semaphore;

[0140] The second semaphore is used to indicate the number of thread resources in the target sub-resource thread pool used to execute tasks of a second task type, and the tasks of the second task type include the other tasks.

[0141] It should be understood that in some feasible implementations, the processor 401 may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The memory 402 may include a read-only memory and a random access memory, and provide instructions and data to the processor 401. A portion of the memory 402 may also include a non-volatile random access memory. For example, the memory 402 may also store information about the device type.

[0142] In a specific implementation, the above terminal device can execute the above-mentioned functions through its built-in functional modules. Figure 1 to Figure 2 For the implementation methods provided in each step, please refer to the implementation methods provided in the above steps for details, which will not be repeated here.

[0143] In an embodiment of the present application, the terminal device can obtain at least two task types based on the task database, and then set the task identifier and task priority of any task type, and divide the resource thread pool containing N thread resources into n sub-resource thread pools based on the business parameters, set the thread pool identifier of each sub-resource thread pool in the above n sub-resource thread pools, and establish the corresponding relationship between the task identifier and the thread pool identifier. When receiving a task processing request triggered by a target business, the task identifier and priority of the target task are determined based on the information carried in the key field in the task processing request, and the target sub-resource thread pool is found from the n sub-resource thread pools according to the matching relationship between the task identifier and the thread identifier, and the thread resources in the target sub-resource thread pool are reallocated by querying the thread resources responsible for executing the target task in the above target sub-resource thread pool, and finally the target task is executed. The device provided in the embodiment of the present application can monitor the usage of the thread resources allocated to the tasks triggered by executing each business, and can achieve the inclination to important businesses when reallocating thread resources, and can flexibly adjust the thread resources in real time, and has a wide range of applications.

[0144] The present application also provides a computer-readable storage medium storing a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, Figure 1 to Figure 2For the thread resource allocation method provided in each step, please refer to the implementation method provided in the above steps, which will not be repeated here.

[0145] The computer-readable storage medium may be the thread resource allocation device provided in any of the aforementioned embodiments or the internal storage unit of the terminal device, such as a hard disk or memory of an electronic device. The computer-readable storage medium may also be an external storage device of the electronic device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device. Further, the computer-readable storage medium may also include both an internal storage unit and an external storage device of the electronic device. The computer-readable storage medium is used to store the computer program and other programs and data required by the electronic device. The computer-readable storage medium may also be used to temporarily store data that has been output or is to be output.

[0146] The terms "first", "second", "third", "fourth", etc. in the claims, specification and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices. Mentioning "embodiment" in this article means that the specific features, structures or characteristics described in conjunction with the embodiment may be included in at least one embodiment of the present application. The term "and / or" used in the specification and the attached claims of the present application refers to any combination of one or more of the items listed in the association and all possible combinations, and includes these combinations. The method and related device provided in the embodiment of the present application are described with reference to the method flow chart and / or structural schematic diagram provided in the embodiment of the present application, and each process and / or box of the method flow chart and / or structural schematic diagram, as well as the combination of the process and / or box in the flow chart and / or block diagram can be implemented by computer program instructions.

[0147] The above disclosure is only the preferred embodiment of the present invention, which certainly cannot be used to limit the scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.

Claims

1. A method for thread resource allocation, It is characterized in that include: Acquire at least two task types, wherein tasks of the same task type in the at least two task types are marked by the same task identifier; Setting task priorities corresponding to various task types among the at least two task types, wherein the task priorities include at least a first priority and a second priority, and the task priorities corresponding to the various task types are used to determine a processing order of tasks of the various task types; Receive a task processing request triggered by a target business, and determine a task identifier and a task priority of a target task requested to be processed by the task processing request; If the task priority of the target task is the first priority, determining the target sub-resource thread pool corresponding to the target task according to the task identifier; A group of semaphores corresponding to each sub-resource thread pool is set, wherein one semaphore in the group of semaphores corresponding to any sub-resource thread pool is used to indicate the number of thread resources used to execute tasks of a task type in any sub-resource thread pool; When it is queried that the number of thread resources indicated by the first semaphore corresponding to the target sub-resource thread pool is empty, it is determined that there are no idle thread resources in the target sub-resource thread pool for executing the target task, wherein the first semaphore is used to indicate the number of thread resources in the target sub-resource thread pool for executing tasks of a first task type, and the tasks of the first task type include the target task; If there are no idle thread resources for executing the target task in the target sub-resource thread pool, thread resources for executing other tasks in the target sub-resource thread pool are reallocated to obtain target thread resources for executing the target task, the task priority of the other tasks also includes a second priority, and the processing order of tasks corresponding to the first priority takes precedence over the processing order of tasks corresponding to the second priority, wherein, when thread resources are reallocated, the number of thread resources used by other tasks in the target sub-resource thread pool is reduced proportionally, and the number of target thread resources used for executing the target task is increased; The target task is executed based on the target thread resources.

2. The method according to claim 1, It is characterized in that Before receiving the task processing request triggered by the target business, the method further includes: Dividing a resource thread pool including multiple thread resources into multiple sub-resource thread pools, wherein one sub-resource thread pool includes at least one thread resource, and the multiple sub-resource thread pools include at least the target sub-resource thread pool; Setting a thread pool identifier of each sub-resource thread pool in the multiple sub-resource thread pools; The thread pool identifier of any sub-resource thread pool is used to determine the tasks that the thread resources in any sub-resource thread pool are used to execute.

3. The method according to claim 2, It is characterized in that Determining the target sub-resource thread pool corresponding to the target task according to the task identifier includes: A target thread pool identifier corresponding to the task identifier is determined from thread pool identifiers of each sub-resource thread pool, and the sub-resource thread pool corresponding to the target thread pool identifier is determined as the target sub-resource thread pool corresponding to the target task.

4. The method according to claim 3, It is characterized in that The thread resource reallocation of the thread resources in the target sub-resource thread pool for executing other tasks includes: modifying the first semaphore to increase the number of thread resources indicated by the first semaphore; Modify a second semaphore other than the first semaphore in a group of semaphores corresponding to the target sub-resource thread pool to reduce the number of thread resources indicated by the second semaphore; The second semaphore is used to indicate the number of thread resources in the target sub-resource thread pool used to execute tasks of a second task type, and the tasks of the second task type include the other tasks.

5. A thread resource allocation device, the device being used to execute the method according to any one of claims 1 to 4, It is characterized in that include: A receiving unit, configured to receive a task processing request triggered by a target business, and determine a task identifier and a task priority of a target task requested to be processed by the task processing request; a matching unit, configured to determine a target sub-resource thread pool corresponding to the target task according to the task identifier when the receiving unit determines that the task priority of the target task is the first priority; an allocation unit, configured to reallocate thread resources used to execute other tasks in the target sub-resource thread pool to obtain target thread resources used to execute the target task when there are no idle thread resources used to execute the target task in the target sub-resource thread pool, wherein the task priority of the other tasks also includes a second priority, and the processing order of tasks corresponding to the first priority takes precedence over the processing order of tasks corresponding to the second priority, wherein, when thread resources are reallocated, the number of thread resources used by other tasks in the target sub-resource thread pool is proportionally reduced, and the number of target thread resources used for executing the target task is increased; An execution unit is used to execute the target task based on the target thread resources reallocated by the allocation unit.

6. The device according to claim 5, It is characterized in that The device also includes: A division unit, used for dividing a resource thread pool including a plurality of thread resources into a plurality of sub-resource thread pools, wherein a sub-resource thread pool includes at least one thread resource, and the plurality of sub-resource thread pools include at least the target sub-resource thread pool; The partitioning unit is further used to set the thread pool identifier of each sub-resource thread pool in the multiple sub-resource thread pools; The thread pool identifier of any sub-resource thread pool is used to determine the tasks that the thread resources in any sub-resource thread pool are used to execute.

7. A terminal device, It is characterized in that comprising a processor and a memory, wherein the processor and the memory are connected to each other; The memory is used to store a computer program, the computer program includes program instructions, and the processor is configured to call the program instructions to execute the method according to any one of claims 1 to 4.

8. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Task information processing method and scheduling control processing device

    CN102207890A

  • Multi-core and multi-threading processor-based functional macropipeline implementing method

    CN102331923A

  • Thread flow control method and thread flow control device

    CN104572277A

  • Task distribution method and device for controlling network crawlers

    CN107305548A

  • Dynamic task prioritization for in-memory databases

    US20150058858A1