Task processing method and device
By introducing binary tree data structures and lock objects into the thread pool, complex tasks are processed in a targeted manner based on task nature and number, which solves the problem of low processing efficiency of the existing thread pool and achieves efficient processing of long-process tasks.
Patent Information
- Application Number
- CN202311404047.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-26
- Publication Date
- 2024-10-18
AI Technical Summary
The existing thread pool cannot efficiently handle long and complex tasks, resulting in low task processing efficiency.
Using a hybrid thread pool combined with a binary tree data structure, the target thread is determined by the nature and number of the task, and the lock object is used to wake up the thread to achieve directional processing of complex tasks.
It improves the processing efficiency of complex tasks, alleviates the thread pool congestion problem, and ensures efficient processing of long-process tasks.
Smart Images

Figure CN118796371A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a task processing method and device. Background Art
[0002] With the development of the Internet + industry, operators' business acceptance systems are also transforming towards the Internet. The back-end of the business acceptance system uses Docker containers to process multiple tasks concurrently and make full use of CPU (Central Processing Unit) resources.
[0003] In the related technology, the large order business submitted by the business acceptance system is mixed with a large number of short-process businesses and long-process businesses, and the currently used thread pool is mainly used to process stateless, assembly line-like tasks, and cannot handle long and complex tasks, resulting in low processing efficiency of complex tasks. Summary of the invention
[0004] The embodiments of the present application provide a task processing method and device to solve the technical problem that the currently used thread pool cannot process long and complex tasks, resulting in low task processing efficiency.
[0005] In a first aspect, an embodiment of the present application provides a task processing method, which is applied to a hybrid thread pool, wherein the hybrid thread pool includes a thread pool and a binary tree data structure, wherein the thread pool includes multiple task threads, and the binary tree data structure includes thread attributes corresponding to the multiple task threads, wherein the thread attributes include multiple lock objects, and the method includes:
[0006] Obtaining a task to be processed, wherein the task to be processed includes multiple subtasks, and different subtasks correspond to different task attributes. The task attributes include task properties and task numbers, and the task properties are used to indicate the complexity of the subtasks;
[0007] In the case where the task nature of the target subtask is determined to be a complex task through the thread pool, a first task thread is determined from the multiple task threads according to the task number of the target subtask based on the binary tree data structure, and a target lock object is determined from the multiple lock objects of the thread attributes according to the first task thread, and the target subtask belongs to the multiple subtasks;
[0008] The first task thread is awakened according to the target lock object to process the target subtask.
[0009] In one embodiment, the task attributes further include context attributes of the subtask;
[0010] The determining of the target lock object from the plurality of lock objects of the thread attribute according to the first task thread comprises:
[0011] The lock object corresponding to the task thread of the previous task of the target subtask is determined according to the context attribute of the target subtask, and the lock object corresponding to the task thread of the previous task is determined as the target lock object.
[0012] In one embodiment, the binary tree data structure further includes a plurality of sorting key values, and different sorting key values correspond to different task threads;
[0013] The determining the first task thread according to the task number of the target subtask includes:
[0014] A hash calculation is performed on the task number of the target subtask to obtain a target sort key value, and the first task thread is determined according to the target sort key value, where the target sort key value is one of the multiple sort key values.
[0015] In one embodiment, before obtaining the task to be processed, the method further includes:
[0016] Splitting the large task to be processed into multiple subtasks;
[0017] The multiple subtasks are stored in a task queue in sequence, and the task queue is used to extract the target subtask from the multiple subtasks when the task processing thread is started.
[0018] In one embodiment, the method of storing the plurality of subtasks in the task queue in order includes:
[0019] When the first subtask is stored in the task queue, the number of the current task thread of the thread pool is determined to be the transaction number of the task to be processed, and the summary point number of the task to be processed and the node number of the first subtask are stored in the binary tree data structure; the lock object of the current task thread is written into the binary tree data structure through the open addressing method.
[0020] In one embodiment, the method further comprises:
[0021] When it is determined through the thread pool that the task property of the target subtask is a simple task, a second task thread is randomly awakened from the multiple task threads, and the target subtask is processed according to the second task thread.
[0022] In a second aspect, an embodiment of the present application provides a task processing device, including:
[0023] A task acquisition module is used to acquire a task to be processed, wherein the task to be processed includes a plurality of subtasks, and different subtasks correspond to different task attributes. The task attributes include task properties and task numbers, and the task properties are used to indicate the complexity of the subtasks;
[0024] An analysis module, for determining a first task thread from a plurality of task threads based on a binary tree data structure according to a task number of the target subtask when the task nature of the target subtask is determined to be a complex task through a thread pool, and determining a target lock object from a plurality of lock objects of thread attributes according to the first task thread, the target subtask belonging to the plurality of subtasks, wherein the thread pool includes the plurality of task threads, the binary tree data structure includes the thread attributes, and the thread attributes include the plurality of lock objects;
[0025] An execution module is used to wake up the first task thread according to the target lock object to process the target subtask.
[0026] In a third aspect, the present application also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the task processing method described in the first aspect when executing the program.
[0027] In a fourth aspect, the present application further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the task processing method described in the first aspect.
[0028] In a fifth aspect, the present application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the task processing method described in the first aspect.
[0029] The task processing method and device provided in the embodiment of the present application, when determining through a thread pool that the task nature of a target subtask is a complex task, uses a binary tree data structure to determine a first task thread from multiple task threads according to the task number of the target subtask, and determines a target lock object from multiple lock objects of thread attributes based on the first task thread, and then wakes up the first task thread according to the target lock object to process the target subtask, thereby realizing directional processing of complex tasks with long processes and improving the processing efficiency of complex tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solutions in the present application or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0031] Figure 1 This is one of the flowcharts of the task processing method provided in the embodiment of the present application;
[0032] Figure 2 This is the second flowchart of the task processing method provided in the embodiment of the present application;
[0033] Figure 3 It is a flowchart of the thread pool initialization method provided in an embodiment of the present application;
[0034] Figure 4 It is a structural diagram of a thread binary tree data structure provided in an embodiment of the present application;
[0035] Figure 5 is a structural diagram of a task processing device provided in an embodiment of the present application;
[0036] Figure 6 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application; DETAILED DESCRIPTION
[0037] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0038] Figure 1 This is one of the flowcharts of the task processing method provided in the embodiment of the present application. Figure 1 The embodiment of the present application provides a task processing method, which is applied to a hybrid thread pool. The hybrid thread pool includes a thread pool and a binary tree data structure. The thread pool includes multiple task threads. The binary tree data structure includes thread attributes corresponding to the multiple task threads. The thread attributes include multiple lock objects, including the following steps:
[0039] Step 110: Obtain the pending task, which includes multiple subtasks. Different subtasks correspond to different task attributes. The task attributes include task nature and task number. The task nature is used to indicate the complexity of the subtask.
[0040] In this step, the mixed thread pool ThreadPoolMixChain creates a work thread WorkThread according to the preset parameter poolSize, that is, a task queue, which is used to store and retrieve multiple subtasks to be processed.
[0041] In this step, the binary tree data structure may be a tree structure constructed by a pre-order algorithm, for example, the binary tree data structure may be a pre-order binary tree Tree; the binary tree data structure is used to manage thread attributes of working threads in the thread pool, and context attributes for addressing and processing transaction chains.
[0042] In this embodiment, the binary tree data structure is used to store the synchronization object Lock_object of the task thread, that is, the lock object.
[0043] In this embodiment, the nature of the task can be represented by a preset identifier, for example, Task_Type is used to represent the nature of the task. Since the multiple subtasks include not only simple tasks but also complex tasks, and the complex tasks have richer context information, the different types of subtasks can be marked in the following manner:
[0044] (1) Simple tasks are not marked, but complex tasks are marked. Complex tasks can be marked with the same identifier, for example, ComplexTask; different complex tasks can also be marked with different identifiers, for example, ComplexTask1 or ComplexTask2.
[0045] (2) Simple tasks and complex tasks are uniformly marked, for example, simple tasks are uniformly marked as 0 and complex tasks are uniformly marked as 1, so as to avoid multiple task type determinations when adding the nature of each task.
[0046] In this embodiment, the task number is a unique number of different subtasks, for example, the task number of the current subtask is TransId.
[0047] Step 120: When it is determined through the thread pool that the task nature of the target subtask is a complex task, a first task thread is determined from multiple task threads based on the task number of the target subtask based on the binary tree data structure, and a target lock object is determined from multiple lock objects of thread attributes based on the first task thread, and the target subtask belongs to multiple subtasks.
[0048] In this step, the type of each task is determined by the task properties of each subtask. When the target subtask is a complex task, the task number corresponding to the target task is read through the thread pool, and based on the association between the task number and multiple task threads in the binary tree data structure, the first task thread that uniquely corresponds to the task number is determined.
[0049] In this embodiment, when the binary tree data structure presets key values respectively associated with different task threads, the task thread corresponding to the task number can be determined by performing a hash calculation on the task number.
[0050] In this embodiment, the binary tree data structure reads a subtask whose task property is ComplexTask, and the subtask is a complex task, and reads the first task thread T1 from multiple task threads according to the number TransId of the subtask.
[0051] In this embodiment, if the binary tree data structure determines that the target subtask is a simple task by reading the task property, there is no need to determine the first task thread by the corresponding task number, and any task thread can be called from multiple task threads to process the target subtask.
[0052] In this embodiment, the thread attributes also include the Handle address (Thread_Address) of each thread. By caching the reference address of the processing thread corresponding to the complex task, the targeted awakening of the lock object can be quickly achieved.
[0053] Step 130: wake up the first task thread according to the target lock object to process the target subtask.
[0054] In this step, through the targeted awakening of the target lock object, the first task thread is accurately awakened without affecting the normal operation or sleep of other threads, and the subtask is continued to be processed according to the task context.
[0055] Figure 2 This is the second flowchart of the task processing method provided in the embodiment of the present application. Figure 2 In the illustrated embodiment, after obtaining the lock object of the previously processed thread (corresponding locked object), an attempt is made to acquire the thread lock, and the waiting sub-thread (first target thread) is awakened according to the thread lock, and then the subsequent sub-tasks read from the task queue are continued to be processed according to the context attributes of the first sub-task, until the processing node of the last sub-task is processed, the thread attributes are cleared, and the pre-order binary tree is removed from the hybrid thread pool.
[0056] In this embodiment, when the node processing of the last subtask in the task to be processed is completed, the thread attributes are reset and cleared, and the binary tree data structure is removed.
[0057] The task processing method provided in the embodiment of the present application determines that the task nature of the target subtask is a complex task through a thread pool, uses a binary tree data structure to determine the first task thread from multiple task threads according to the task number of the target subtask, and determines the target lock object from multiple lock objects of thread attributes according to the first task thread, and then wakes up the first task thread according to the target lock object to process the target subtask. By using synchronous locking objects and directed wake-up threads, directed processing of complex tasks with long processes is achieved, thereby improving the processing efficiency of complex tasks.
[0058] In some embodiments, the task attributes also include context attributes of the subtask; determining the target lock object from multiple lock objects of the thread attributes according to the first task thread includes: determining the lock object corresponding to the task thread of the previous task of the target subtask according to the context attributes of the target subtask, and determining the lock object corresponding to the task thread of the previous task as the target lock object.
[0059] In this embodiment, the binary tree data structure is also used to store context attributes of subtasks, for example, context attribute Task_content of a complex task.
[0060] In this embodiment, when the task nature of the target subtask is a complex task ComplexTask, the task number TransId is first obtained from the task attributes, and the task thread T1 dedicated to the task to be processed is obtained from the binary tree according to the task number, and the lock object of the thread T0 of the previous task of ComplexTask is determined through the context attributes of ComplexTask as the target lock object of the task thread T1, that is, the context attributes of the previous node are added to the context attributes of the subtask of the current node to realize the forward and backward handover of business processing.
[0061] exist Figure 2 In the illustrated embodiment, the thread attributes are read from the binary tree data structure according to the hash value of TransId, and the lock object of the previous processing thread of the current task thread is obtained as the target lock object, and the thread is awakened based on this.
[0062] The task processing method provided in the embodiment of the present application determines the lock object corresponding to the task thread of the previous task of the target subtask through the context attribute of the target subtask, and determines the lock object corresponding to the task thread of the previous task as the target lock object, thereby improving the business processing handover capability between multiple subtasks, and can achieve concurrent processing of time-consuming tasks and short-consuming tasks without losing the context state of complex tasks, thereby improving the processing efficiency of time-consuming tasks and alleviating the problem of thread pool congestion.
[0063] In some embodiments, the binary tree data structure also includes multiple sorting key values, different sorting key values correspond to different task threads; determining the first task thread according to the task number of the target subtask includes: performing a hash calculation on the task number of the target subtask to obtain the target sorting key value, and determining the first task thread according to the target sorting key value, the target sorting key value is one of the multiple sorting key values.
[0064] Figure 3 is a flowchart of a thread pool initialization method provided in an embodiment of the present application. Figure 3 In the illustrated embodiment, in the process of initializing the thread pool, a task queue WorkQueue is first created, each processing thread is initialized according to the preset poolSize (corresponding to the initialization sub-thread), and a sub-thread is created, and then the thread properties are initialized. Finally, it is determined whether the preset poolSize is reached. If the preset value is not reached, the sub-thread is initialized.
[0065] In this embodiment, each task thread initializes thread attributes. Since there are many context attributes that need to be stored between different tasks, a binary tree data structure can be created to store the context attribute Task_content of complex tasks and the lock object Lock_object of the task thread.
[0066] In this embodiment, the binary tree data structure includes a sorting key value key, and the hash values p1, p2, p3... and the corresponding task threads Thread1, Thread2, Thread3... can be obtained through the open addressing method key = f (transaction unique number TransId), and then stored in the binary tree data structure according to the pre-order algorithm. Since the hash value is obtained by hashing the task number, the association relationship between the task numbers of different subtasks and different task threads can be established.
[0067] In this embodiment, the thread attributes include the Handle address Thread_Address of the task thread, the lock object Thread_Lock_Object and the context attribute (Thread_Context); wherein, Thread_Context is initialized to empty and can save the TransId, current processing node CurNode and total number of nodes TotalNode of the complex task.
[0068] Figure 4 is a structural diagram of a thread binary tree data structure provided in an embodiment of the present application. Figure 4 In the illustrated embodiment, the binary tree data structure stores thread attributes of seven task threads (Thread 1 to Thread 7).
[0069] The task processing method provided in the embodiment of the present application obtains the target sorting key value by performing hash calculation on the task number of the target subtask, and determines the first task thread according to the target sorting key value. It can establish an association between the task numbers of different subtasks and different task threads, thereby improving the search efficiency for the task threads corresponding to complex tasks, and further improving the directional processing efficiency of complex tasks.
[0070] In one embodiment, a method for storing multiple subtasks in a task queue in sequence includes: when the first subtask is stored in the task queue, determining that the number of the current task thread of the thread pool is the transaction number of the task to be processed, and storing the summary point number of the task to be processed and the node number of the first subtask into a binary tree data structure; writing the lock object of the current task thread into the binary tree data structure through an open addressing method.
[0071] In this embodiment, the processing flow of a task with a transaction chain includes:
[0072] (1) The large task to be processed is split into multiple subtasks; the multiple subtasks are stored in a task queue in order. The task queue is used to extract the target subtask from the multiple subtasks when the task processing thread is started, thereby realizing the atomic processing of the large task splitting.
[0073] (2) When the first subtask enters the queue for processing, the thread pool will first update the thread properties of the current task thread, that is, update the transaction number of the current task thread to the large task number, and save the total number of nodes of the large task and the current number of processing nodes (the initial value can be set to 1), and at the same time store the lock object of the current thread for the thread wake-up process.
[0074] For example, using the open addressing method key=f(TransId), the lock object of the thread attribute is written into the binary tree data structure with the hash value key of TransId.
[0075] exist Figure 2In the illustrated embodiment, a task to be processed is obtained, and the task is split to obtain multiple subtasks, and the multiple subtasks are added to a task queue (corresponding to a processing queue), and processing is started. The task to be processed is taken out from the WorkQueue, such as a target subtask, and the type of the target subtask is determined according to the nature of the task. When the target subtask is a complex task ComplexTask, it is determined whether the processing node corresponding to the target subtask is the first processing node. If so, the thread attribute is updated first (including identifying the thread attribute as ComplexTask; storing the total number of nodes of the task to be processed in the pre-order binary tree, and updating the current processing node to the thread attribute, and finally generating a new synchronization locking object, i.e., a lock object), and the hash value of the task number TransId is written into the pre-order binary tree, and the thread attribute is read according to the hash value of TransId to obtain the locking object of the previous processing thread.
[0076] The task processing method provided in the embodiment of the present application determines that the number of the current task thread of the thread pool is the transaction number of the task to be processed when the first subtask is stored in the task queue, and stores the summary point number of the task to be processed and the node number of the first subtask into the binary tree data structure; writes the lock object of the current task thread into the binary tree data structure through the open addressing method. This method realizes stateful processing of sub-threads that process complex tasks through custom configuration of the binary tree data structure, thereby improving the performance of the thread pool.
[0077] In some embodiments, the method further includes: when it is determined through the thread pool that the task nature of the target subtask is a simple task, randomly waking up a second task thread from multiple task threads, and processing the target subtask according to the second task thread.
[0078] In this embodiment, when the task nature of the target subtask is a simple task, there is no need to search for the corresponding exclusive lock object by the task number of the target subtask, and a task thread can be randomly or arbitrarily called from the thread pool to process the target subtask.
[0079] exist Figure 2 In the illustrated embodiment, if the current task to be processed is determined to be a simple task (simpleTask) according to the nature of the task, the waiting sub-thread is directly awakened and subsequent processing is performed.
[0080] The task processing method provided in the embodiment of the present application can support fast processing of simple tasks and improve the processing efficiency of the hybrid thread pool for tasks of different complexity by randomly waking up a second task thread from multiple task threads when the task nature of the target subtask is determined to be a simple task through the thread pool, and processing the target subtask according to the second task thread.
[0081] The task processing device provided in the embodiment of the present application is described below. The task processing device described below and the task processing method described above can be referenced to each other.
[0082] Figure 5 is a schematic diagram of the structure of the task processing device provided in the embodiment of the present application, such as Figure 5 As shown, the task processing device includes a task acquisition module 510 , an analysis module 520 and an execution module 530 .
[0083] The task acquisition module 510 is used to acquire a task to be processed. The task to be processed includes multiple subtasks. Different subtasks correspond to different task attributes. The task attributes include task properties and task numbers. The task properties are used to indicate the complexity of the subtasks.
[0084] The analysis module 520 is used to determine, based on the binary tree data structure, a first task thread from multiple task threads according to the task number of the target subtask when the task nature of the target subtask is determined to be a complex task through the thread pool, and determine a target lock object from multiple lock objects of thread attributes according to the first task thread, wherein the target subtask belongs to multiple subtasks, wherein the thread pool includes multiple task threads, the binary tree data structure includes thread attributes, and the thread attributes include multiple lock objects;
[0085] The execution module 530 is used to wake up the first task thread according to the target lock object to process the target subtask.
[0086] The task processing device provided in the embodiment of the present application determines that the task nature of the target subtask is a complex task through a thread pool, and uses a binary tree data structure to determine the first task thread from multiple task threads according to the task number of the target subtask, and determines the target lock object from multiple lock objects of thread attributes based on the first task thread, and then wakes up the first task thread according to the target lock object to process the target subtask. By using synchronous locking objects and directed wake-up threads, directed processing of complex tasks with long processes is achieved, thereby improving the processing efficiency of complex tasks.
[0087] Figure 6 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Figure 6As shown, the electronic device may include: a processor (processor) 610, a communication interface (Communication Interface) 620, a memory (memory) 630 and a communication bus 640, wherein the processor 610, the communication interface 620, and the memory 630 communicate with each other through the communication bus 640. The processor 610 can call the computer program in the memory 630 to execute the steps of the task processing method, which is applied to a hybrid thread pool, the hybrid thread pool includes a thread pool and a binary tree data structure, the thread pool includes multiple task threads, the binary tree data structure includes thread attributes corresponding to the multiple task threads, the thread attributes include multiple lock objects, and include the following steps: obtaining a task to be processed, the task to be processed includes multiple subtasks, different subtasks correspond to different task attributes, the task attributes include task properties and task numbers, and the task properties are used to indicate the complexity of the subtask; when the task property of the target subtask is determined to be a complex task through the thread pool, a first task thread is determined from multiple task threads based on the binary tree data structure according to the task number of the target subtask, and a target lock object is determined from multiple lock objects of the thread attributes according to the first task thread, and the target subtask belongs to multiple subtasks; thread wake-up of the first task thread is performed according to the target lock object to process the target subtask.
[0088] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk.
[0089] On the other hand, an embodiment of the present application also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the steps of the processing method provided in the above embodiments. The method is applied to a hybrid thread pool, which includes a thread pool and a binary tree data structure. The thread pool includes multiple task threads. The binary tree data structure includes thread attributes corresponding to the multiple task threads. The thread attributes include multiple lock objects, and include the following steps: obtaining a task to be processed, the task to be processed includes multiple subtasks, different subtasks correspond to different task attributes, the task attributes include task properties and task numbers, and the task properties are used to indicate the complexity of the subtask; when the task property of the target subtask is determined to be a complex task through the thread pool, a first task thread is determined from multiple task threads based on the binary tree data structure according to the task number of the target subtask, and a target lock object is determined from multiple lock objects of the thread attributes according to the first task thread, and the target subtask belongs to multiple subtasks; thread wake-up of the first task thread is performed according to the target lock object to process the target subtask.
[0090] On the other hand, an embodiment of the present application also provides a processor-readable storage medium, which stores a computer program, and the computer program is used to enable the processor to execute the steps of the processing method provided by the above embodiments. The method is applied to a hybrid thread pool, and the hybrid thread pool includes a thread pool and a binary tree data structure. The thread pool includes multiple task threads, and the binary tree data structure includes thread attributes corresponding to the multiple task threads. The thread attributes include multiple lock objects, including the following steps: obtaining a task to be processed, the task to be processed includes multiple subtasks, and different subtasks correspond to different task attributes. The task attributes include task properties and task numbers, and the task properties are used to indicate the complexity of the subtask; when the task property of the target subtask is determined to be a complex task through the thread pool, a first task thread is determined from multiple task threads based on the binary tree data structure according to the task number of the target subtask, and a target lock object is determined from multiple lock objects of the thread attributes according to the first task thread, and the target subtask belongs to multiple subtasks; thread wake-up of the first task thread is performed according to the target lock object to process the target subtask.
[0091] The processor-readable storage medium can be any available medium or data storage device that can be accessed by the processor, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (such as CD, DVD, BD, HVD, etc.), and semiconductor storage (such as ROM, EPROM, EEPROM, non-volatile memory (NANDFLASH), solid-state drive (SSD)), etc.
[0092] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0093] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0094] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A task processing method, characterized in that: Applied to a hybrid thread pool, the hybrid thread pool includes a thread pool and a binary tree data structure, the thread pool includes multiple task threads, the binary tree data structure includes thread attributes corresponding to the multiple task threads, the thread attributes include multiple lock objects, the method includes: Obtaining a task to be processed, wherein the task to be processed includes multiple subtasks, and different subtasks correspond to different task attributes. The task attributes include task properties and task numbers, and the task properties are used to indicate the complexity of the subtasks; In the case where the task nature of the target subtask is determined to be a complex task through the thread pool, a first task thread is determined from the multiple task threads according to the task number of the target subtask based on the binary tree data structure, and a target lock object is determined from the multiple lock objects of the thread attributes according to the first task thread, and the target subtask belongs to the multiple subtasks; The first task thread is awakened according to the target lock object to process the target subtask.
2. The task processing method according to claim 1, characterized in that: The task attributes also include context attributes of the subtask; The determining of the target lock object from the plurality of lock objects of the thread attribute according to the first task thread comprises: The lock object corresponding to the task thread of the previous task of the target subtask is determined according to the context attribute of the target subtask, and the lock object corresponding to the task thread of the previous task is determined as the target lock object.
3. The task processing method according to claim 1, characterized in that: The binary tree data structure also includes multiple sorting key values, and different sorting key values correspond to different task threads; The determining the first task thread according to the task number of the target subtask includes: A hash calculation is performed on the task number of the target subtask to obtain a target sort key value, and the first task thread is determined according to the target sort key value, where the target sort key value is one of the multiple sort key values.
4. The task processing method according to claim 1, characterized in that: Before obtaining the task to be processed, the method further includes: Splitting the large task to be processed into multiple subtasks; The multiple subtasks are stored in a task queue in sequence, and the task queue is used to extract the target subtask from the multiple subtasks when the task processing thread is started.
5. The task processing method according to claim 4, characterized in that: The method for storing the plurality of subtasks in the task queue in order comprises: When the first subtask is stored in the task queue, the number of the current task thread of the thread pool is determined to be the transaction number of the task to be processed, and the summary point number of the task to be processed and the node number of the first subtask are stored in the binary tree data structure; the lock object of the current task thread is written into the binary tree data structure through the open addressing method.
6. The task processing method according to claim 1, characterized in that: The method further comprises: When it is determined through the thread pool that the task property of the target subtask is a simple task, a second task thread is randomly awakened from the multiple task threads, and the target subtask is processed according to the second task thread.
7. A task processing device, characterized in that: include: A task acquisition module is used to acquire a task to be processed, wherein the task to be processed includes a plurality of subtasks, and different subtasks correspond to different task attributes. The task attributes include task properties and task numbers, and the task properties are used to indicate the complexity of the subtasks; An analysis module, for determining a first task thread from a plurality of task threads based on a binary tree data structure according to a task number of the target subtask when the task nature of the target subtask is determined to be a complex task through a thread pool, and determining a target lock object from a plurality of lock objects of thread attributes according to the first task thread, the target subtask belonging to the plurality of subtasks, wherein the thread pool includes the plurality of task threads, the binary tree data structure includes the thread attributes, and the thread attributes include the plurality of lock objects; An execution module is used to wake up the first task thread according to the target lock object to process the target subtask.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the task processing method according to any one of claims 1 to 6 are implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the task processing method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the task processing method according to any one of claims 1 to 6 are implemented.
