Task processing method, thread pool management method, device and computing device
By monitoring the timeout of tasks and the number of tasks in the thread pool and selecting the appropriate timeout processing method, the problem of task execution timeout in the thread pool is solved, and automatic processing and task processing efficiency is achieved.
Patent Information
- Application Number
- CN202110324105.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-26
- Publication Date
- 2025-06-17
- Estimated Expiration
- 2041-03-26
AI Technical Summary
Threads in the thread pool may experience task execution timeout and other exceptions during processing tasks, and the prior art is difficult to effectively handle these exceptions.
By monitoring whether the tasks being executed by each thread in the thread pool are timed out, we judge whether the number of tasks corresponding to the thread pool meets the preset conditions (the number of tasks is greater than or equal to the number of threads), and select the matching processing method from the timeout processing method to process the timeout task.
Automatic handling of abnormal situations such as task execution timeout is realized, avoiding manual intervention and improving the stability and efficiency of task processing.
Smart Images

Figure CN112835704B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of computer technology, and particularly to a task processing method, a thread pool management method, an apparatus, and a computing device. Background Art
[0002] With the rapid development of computer application technology, most computer devices use thread pools to process tasks, that is, the resources of computer devices are fully utilized through the parallel processing of multiple threads in the thread pool to improve the task processing efficiency.
[0003] However, during the process of task processing by threads in the thread pool, abnormal situations such as task execution timeouts may occur. Summary of the Invention
[0004] The embodiments of this specification provide a task processing method, a thread pool management method, an apparatus, and a computing device, which can handle abnormal situations such as task execution timeouts. The technical solutions of the embodiments of this specification are as follows.
[0005] In a first aspect of the embodiments of this specification, a task processing method is provided, including:
[0006] Monitoring whether the tasks being executed by each thread in the thread pool time out;
[0007] If it times out, determining whether the number of tasks corresponding to the thread pool meets a preset condition; the preset condition includes: the number of tasks corresponding to the thread pool is greater than or equal to the number of threads in the thread pool;
[0008] If the preset condition is met, selecting a timeout handling method that matches the type of the timeout task from a timeout handling method set, where the timeout handling method set includes at least one timeout handling method, and each timeout handling method corresponds to a task type;
[0009] Processing the timeout task according to the selected timeout handling method.
[0010] In a second aspect of the embodiments of this specification, a thread pool management method is provided, including:
[0011] Monitoring the time consumption of threads in the thread pool when executing tasks;
[0012] Comparing the time consumption with a reference time consumption;
[0013] Adjusting the thread pool according to the comparison result.
[0014] In a third aspect of the embodiments of this specification, a task processing method is provided, including:
[0015] Setting multiple task groups, where each task group includes a type of task;
[0016] Set up a thread pool for each task group;
[0017] Assign the target task to the target thread pool so that the threads in the target thread pool execute the target task, and the target thread pool corresponds to the task group to which the target task belongs.
[0018] In a fourth aspect of the embodiments of this specification, a task processing device is provided, including:
[0019] A monitoring unit, configured to monitor whether the tasks being executed by each thread in the thread pool time out;
[0020] A judgment unit, configured to, if it times out, judge whether the number of tasks corresponding to the thread pool meets a preset condition; the preset condition includes: the number of tasks corresponding to the thread pool is greater than or equal to the number of threads in the thread pool;
[0021] An obtaining unit, configured to, if the preset condition is met, select a timeout handling method that matches the type of the timeout task from a set of timeout handling methods, where the set of timeout handling methods includes at least one timeout handling method, and each timeout handling method corresponds to a task type;
[0022] A processing unit, configured to process the timeout task according to the selected timeout handling method.
[0023] In a fifth aspect of the embodiments of this specification, a thread pool management device is provided, including:
[0024] A monitoring unit, configured to monitor the time taken by the threads in the thread pool when executing tasks;
[0025] A comparison unit, configured to compare the time taken with a reference time taken;
[0026] An adjustment unit, configured to adjust the thread pool according to the comparison result.
[0027] In a sixth aspect of the embodiments of this specification, a task processing device is provided, including:
[0028] A first setting unit, configured to set up a plurality of task groups, and each task group includes a type of task;
[0029] A second setting unit, configured to set up a thread pool for each task group;
[0030] An assignment unit, configured to assign the target task to the target thread pool so that the threads in the target thread pool execute the target task, and the target thread pool corresponds to the task group to which the target task belongs.
[0031] A seventh aspect of the embodiments of this specification provides a computing device, including:
[0032] At least one processor;
[0033] A memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, and the program instructions include instructions for executing the methods described in the first aspect, the second aspect, or the third aspect.
[0034] The technical solution provided by the embodiments of this specification can monitor whether the tasks being executed by each thread in the thread pool time out; if they time out, it can be determined whether the number of tasks corresponding to the thread pool meets a preset condition; the preset condition includes: the number of tasks corresponding to the thread pool is greater than or equal to the number of threads in the thread pool; if the preset condition is met, a timeout handling method matching the type of the timeout task is selected from a set of timeout handling methods, the set of timeout handling methods includes at least one timeout handling method, and each timeout handling method corresponds to a task type; the timeout task can be processed according to the selected timeout handling method. In this way, the processing of timeout tasks can be realized without manual intervention. In addition, the technical solution of the embodiments of this specification can also manage the thread pool. In addition, the technical solution of the embodiments of this specification can set multiple thread pools, and each thread pool is independent of each other, avoiding the competition of different types of tasks for threads and improving the execution speed of tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the technical solutions in the embodiments of this specification or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. The following drawings are only some embodiments recorded in this specification. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained according to these drawings.
[0036] Figure 1 It is a schematic diagram of the producer-consumer model in the embodiments of this specification;
[0037] Figure 2 It is a schematic diagram of using a thread pool to execute tasks in the embodiments of this specification;
[0038] Figure 3 It is a schematic flowchart of the task processing method in the embodiments of this specification;
[0039] Figure 4 It is a schematic flowchart of the task processing method in the embodiments of this specification;
[0040] Figure 5 It is a schematic flowchart of the thread pool management method in the embodiments of this specification;
[0041] Figure 6 It is a schematic structural diagram of the task processing device in the embodiments of this specification;
[0042] Figure 7 It is a schematic structural diagram of the task processing device in the embodiments of this specification;
[0043] Figure 8 It is a schematic structural diagram of the thread pool management device in the embodiments of this specification;
[0044] Figure 9 It is a schematic structural diagram of the computing device in the embodiments of this specification. Detailed implementation manners
[0045] Next, the technical solutions in the embodiments of this specification will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of this specification. Obviously, the described embodiments are only a part of the embodiments of this specification, rather than all the embodiments. Based on the embodiments in this specification, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this specification.
[0046] A batch processing task refers to a task that is executed on a computer without manual intervention.
[0047] A thread pool is a form of multithreaded processing.
[0048] Using a thread pool to execute tasks actually constructs a producer-consumer model. Through the producer-consumer model, the threads and tasks are decoupled, so that the threads and tasks are not directly associated, thereby buffering tasks well and reusing threads. Please refer to Figure 1 . The operation of the thread pool can include two parts: task management and thread management. The task management part acts as the producer. When a task is submitted, the task management part will have several transfers according to the judgment: (1) Apply for a thread to execute the task; (2) Buffer it in the queue and wait for execution; (3) Reject the task. The thread management part acts as the consumer. The thread management part assigns threads in the thread pool to tasks. When a thread finishes executing a task, it will continue to obtain a new task to execute. When a thread cannot obtain a task, the thread will be recycled.
[0049] In the related art, usually only one thread pool is set, and various types of tasks are all assigned to the thread pool. This will reduce the execution speed of the tasks. For example, in actual business, there can be various types of tasks. Some types of tasks (such as file parsing, encryption, decryption, etc.) take a long time to execute and may occupy all the threads in the thread pool, resulting in the delay of tasks with high real-time requirements. To this end, the embodiments of this specification provide a task processing method. The task processing method can be applied to a server. The server can be a single server, a server cluster composed of multiple servers, or a server deployed in the cloud.
[0050] Please refer to Figure 2 and Figure 3 , the task processing method may include the following steps.
[0051] Step S11: Set multiple task groups, and each task group includes one type of task.
[0052] In some embodiments, the server can analyze the types of tasks in actual business; and can set multiple task groups according to the types of tasks. Each task group can include one type of task. Different task groups can include different types of tasks. The tasks can include batch processing tasks.
[0053] For example, the server can set a first task group and a second task group. The first task group can include tasks of the first type, and the second task group can include tasks of the second type. The tasks of the first type can be tasks that take a long time to execute, such as file parsing, encryption, decryption, etc. The tasks of the second type can be tasks with high real-time requirements and short execution time, such as calculation tasks.
[0054] Another example, the server can set a first task group, a second task group, and a third task group. The first task group can include tasks of the first type, the second task group can include tasks of the second type, and the third task group can include tasks of the third type. The tasks of the first type can be tasks with high importance level and high real-time requirements. The tasks of the second type can be tasks with high importance level and low real-time requirements. The tasks of the third type can be tasks with low importance level.
[0055] Step S13: Set a thread pool for each task group.
[0056] In some embodiments, the server can set a thread pool for each task group, and the threads in the thread pool are used to execute the tasks in the task group. For the multiple task groups set in step S11, the server can set multiple thread pools.
[0057] In some embodiments, the server may also perform initialization processing on the set thread pool. Different initialization processing methods may be adopted for different thread pools. Specifically, the server may initialize the thread pool according to the types of tasks included in the task group corresponding to the thread pool. For example, if the task group corresponding to the thread pool includes tasks of the first type. The tasks of the first type may be tasks that take a relatively long time to execute. Then, the server may set the number of threads in the thread pool to the number of CPU cores × 2. Another example, if the task group corresponding to the thread pool includes tasks of the second type, and the tasks of the second type may be tasks with high real-time requirements and relatively short execution time. Then, the server may set the number of threads in the thread pool to the number of CPU cores + 1.
[0058] Step S15: Assign the target task to the target thread pool so that the threads in the target thread pool execute the target task, and the target thread pool corresponds to the task group to which the target task belongs.
[0059] In some embodiments, the target task may be a task to be executed. The target thread pool corresponds to the task group to which the target task belongs. After obtaining the target task, the server may assign the target task to the target thread pool so that the threads in the target thread pool execute the target task.
[0060] The task processing method according to the embodiments of this specification may set multiple task groups; a thread pool may be set for each task group; the target task may be assigned to the target thread pool so that the threads in the target thread pool execute the target task, and the target thread pool corresponds to the task group to which the target task belongs. Each thread pool is independent of each other, avoiding competition for threads among different types of tasks and improving the execution speed of tasks.
[0061] In some scenario examples, occupational annuity refers to a supplementary endowment insurance system established by the staff of government agencies and public institutions on the basis of participating in the basic endowment insurance for government agencies and public institutions. Institutions such as banks act as trustees, and there are document interfaces with custodians, investment managers, and other trustees. The generation, parsing, encryption, and decryption of documents are all executed through regular batch processing, and business programs involving a large amount of calculations are also executed through regular batch processing.
[0062] For the occupational annuity business, the server may set a first task group and a second task group. The first task group may include tasks of a first type, and the second task group may include tasks of a second type. The tasks of the first type may be tasks that take a relatively long time to execute, such as file parsing, encryption, decryption, etc. The tasks of the second type may be tasks with high real-time requirements and relatively short execution time, such as computing tasks.
[0063] The server may set a thread pool for the first task group; and may set a thread pool for the second task group. When a target batch task needs to be executed, the target batch task may be assigned to a target thread pool so that the threads in the target thread pool execute the target batch task. The target thread pool corresponds to the task group to which the target batch task belongs. The thread pools of the first task group and the second task group are independent of each other, thus avoiding competition for threads among different types of tasks and improving the execution speed of tasks.
[0064] During the process of threads in the thread pool executing tasks, abnormal situations such as task execution timeouts may occur, and it is necessary to handle abnormal situations such as task execution timeouts. For this reason, the embodiments of this specification also provide another task processing method. The task processing method may be applied to a server. The server may be a single server, a server cluster composed of multiple servers, or a server deployed in the cloud.
[0065] Please refer to Figure 2 and Figure 4 , the task processing method may include the following steps.
[0066] Step S21: Monitor whether the tasks being executed by each thread in the thread pool time out.
[0067] In some embodiments, the thread pool may include Figure 2 the thread pool set in the corresponding embodiments. The thread pool may include at least one thread. The tasks being executed by the thread may include batch tasks.
[0068] In some embodiments, the thread pool may correspond to a task queue. The task queue may include tasks assigned to the thread pool. The threads in the thread pool may obtain tasks from the task queue; and may execute the obtained tasks.
[0069] Alternatively, the thread pool may also correspond to a first task set. The first task set may include tasks that are delayed and then resumed. The threads in the thread pool may obtain tasks from the first task set; and may execute the obtained tasks. Among them, the delayed execution will be introduced in detail in the subsequent process.
[0070] In some embodiments, the server may set a time threshold. The server may obtain the time consumption of each thread in the thread pool when executing a task; if the time consumption is greater than or equal to the time threshold, it may be determined that the task being executed by the thread times out; if the time consumption is less than the time threshold, it may be determined that the task being executed by the thread does not time out.
[0071] Step S23: If it times out, determine whether the number of tasks corresponding to the thread pool meets a preset condition.
[0072] In some embodiments, the number of tasks corresponding to the thread pool may include at least one of the following: the number of tasks being executed by each thread in the thread pool, the number of tasks in the task queue, the number of tasks in the first task set. For example, the number of tasks corresponding to the thread pool may be N1 + N2 + N3. Wherein, N1 represents the number of tasks being executed by each thread in the thread pool, N2 represents the number of tasks in the task queue, and N3 represents the number of tasks in the first task set.
[0073] In some embodiments, the preset condition may include: the number of tasks corresponding to the thread pool is greater than or equal to the number of threads in the thread pool. In this way, if it times out, the server may obtain the number of tasks corresponding to the thread pool; may obtain the number of threads in the thread pool; if the number of tasks corresponding to the thread pool is greater than or equal to the number of threads in the thread pool, it may be determined that the number of tasks corresponding to the thread pool meets the preset condition; if the number of tasks corresponding to the thread pool is less than the number of threads in the thread pool, it may be determined that the number of tasks corresponding to the thread pool does not meet the preset condition.
[0074] In some embodiments, if it times out, the server may further generate an alarm message. The alarm message may be used to remind project personnel of a timeout exception. In practice, the server may use methods such as sending text messages, emails, and sending messages in instant messaging to remind project personnel of a timeout exception.
[0075] Step S25: If the preset condition is met, obtain a timeout handling method.
[0076] In some embodiments, the server may be pre-set with a set of timeout handling methods. The set of timeout handling methods may include multiple timeout handling methods. The timeout handling methods may include continuing execution, discarding, delaying execution, etc. Each timeout handling method may correspond to a task type. For example, continuing execution may correspond to a first task type, delaying execution may correspond to a second task type, and discarding may correspond to a third task type. The first task type may be important tasks with high real-time requirements. The second task type may be important tasks with low real-time requirements. The third task type may be less important tasks. In this way, if a preset condition is met, the server may select a timeout handling method from the set of timeout handling methods that matches the task type of the timeout task.
[0077] Step S27: Process the timeout task according to the selected timeout handling method.
[0078] In some embodiments, the server may process the timeout task according to the timeout handling method.
[0079] If the selected timeout handling method is continuing execution, the server may cause the thread to continue executing the timeout task.
[0080] If the selected timeout handling method is discarding, the server may cause the thread to discard the currently executing timeout task so that the thread can obtain a new task from the task queue or the first task set for execution.
[0081] If the selected timeout handling method is delaying execution, the server may cause the thread to stop executing the timeout task so that the thread can obtain a new task from the task queue or the first task set for execution. Additionally, the server may also add the timeout task to the second task set. The second task set may include tasks with delayed execution. When the number of tasks corresponding to the thread pool does not meet the preset condition, the server may obtain tasks from the second task set as tasks in the first task set. Alternatively, the server may also obtain tasks from the second task set whose delay time is greater than or equal to the longest delay time at each preset time period as tasks in the first task set.
[0082] In some embodiments, if there is no timeout, the server may cause the thread to continue executing the task.
[0083] In some embodiments, if the preset condition is not met, the server may cause the thread to continue executing the task.
[0084] The task processing method according to the embodiments of this specification can monitor whether the tasks being executed by the threads in the thread pool time out; if it times out, it can determine whether the number of tasks corresponding to the thread pool meets a preset condition; if it meets the preset condition, it can obtain the timeout handling method; and it can process the timeout tasks according to the timeout handling method. In this way, the server can implement the processing of timeout tasks without manual intervention.
[0085] To ensure the execution speed of tasks and at the same time avoid excessive number of threads causing excessive load on the device and resulting in exceptions such as memory overflow, it is necessary to manage the thread pool. For this purpose, the embodiments of this specification provide a thread pool management method. The thread pool management method can be applied to a server. The server can be a single server, a server cluster composed of multiple servers, or a server deployed in the cloud.
[0086] Please refer to Figure 2 and Figure 5 , the thread pool management method may include the following steps.
[0087] Step S31: Monitor the time taken for the threads in the thread pool to execute tasks.
[0088] In some embodiments, the thread pool may include Figure 2 the thread pool set in the corresponding embodiments. The thread pool may include at least one thread. The tasks being executed by the threads may include batch processing tasks.
[0089] In some embodiments, the thread pool may correspond to a task queue. The task queue may include the tasks assigned to the thread pool. The threads in the thread pool may obtain tasks from the task queue; and may execute the obtained tasks.
[0090] Alternatively, the thread pool may also correspond to a first task set. The first task set may include tasks that are resumed after delayed execution. The threads in the thread pool may obtain tasks from the first task set; and may execute the obtained tasks. Among them, the first task set is introduced in detail in Figure 3 the corresponding embodiments and will not be elaborated here.
[0091] In some embodiments, the server may monitor the start time and end time of each thread in the thread pool when executing tasks; and may obtain the execution time of the tasks based on the start time and end time. In practice, the server may use a preset number of tasks as a group of tasks, for example, 10 tasks as a group of tasks. The server may monitor the average time taken for the threads in the thread pool to execute the most recent group of tasks. Among them, the most recent group of tasks may be jointly executed by the threads in the thread pool, and each thread may execute part of the tasks in the most recent group of tasks.
[0092] Step S33: Compare the time consumption with the reference time consumption.
[0093] Step S35: Adjust the thread pool according to the comparison result.
[0094] In some embodiments, the reference time consumption may include: the average time consumption of the threads in the thread pool when executing the previous set of tasks. The execution order of the previous set of tasks is adjacent to that of the most recent set of tasks and the execution time is earlier than that of the most recent set of tasks.
[0095] In some embodiments, the server may calculate the growth rate of the time consumption relative to the reference time consumption; and may adjust the thread pool according to the growth rate. Specifically, if the growth rate is less than or equal to a preset threshold, the server may consider that the execution time consumption of the most recent set of tasks has not increased significantly compared with that of the previous set of tasks; may consider that its own load is small; and may perform at least one of the following: increase the number of threads in the thread pool, increase the number of threads that the thread pool can accommodate. This can improve the execution speed of tasks. The preset threshold may be 5%, or 4%, etc. For example, the server may start a new thread in the thread pool. If the growth rate is greater than the preset threshold, the server may consider that the execution time consumption of the most recent set of tasks has increased significantly compared with that of the previous set of tasks; may consider that its own load is large; and may perform at least one of the following: reduce the number of threads in the thread pool, reduce the number of threads that the thread pool can accommodate. For example, the server may reduce the number of threads in the thread pool by 2 / 3. This can avoid excessive load on the server and cause anomalies such as memory overflow.
[0096] The thread pool management method according to the embodiments of the present specification can monitor the time consumption of the threads in the thread pool when executing tasks; can compare the time consumption with the reference time consumption; and can adjust the thread pool according to the comparison result. This not only ensures the execution speed of tasks, but also avoids excessive load on the device caused by too many threads.
[0097] Please refer to Figure 6 ... The embodiments of the present specification also provide a task processing device. The device may include the following units.
[0098] A monitoring unit 41, configured to monitor whether the tasks being executed by each thread in the thread pool time out;
[0099] A judging unit 43, configured to, if it times out, judge whether the number of tasks corresponding to the thread pool meets a preset condition; the preset condition includes: the number of tasks corresponding to the thread pool is greater than or equal to the number of threads in the thread pool;
[0100] An obtaining unit 45, configured to select, from a set of timeout handling methods, a timeout handling method that matches the type of the timeout task if a preset condition is satisfied, where the set of timeout handling methods includes at least one timeout handling method, and each timeout handling method corresponds to a task type;
[0101] A processing unit 47, configured to process the timeout task according to the selected timeout handling method.
[0102] Please refer to Figure 7 . An embodiment of this specification further provides a thread pool management device. The device may include the following units.
[0103] A monitoring unit 51, configured to monitor the time consumed by a thread in the thread pool when executing a task;
[0104] A comparison unit 53, configured to compare the time consumed with a reference time;
[0105] An adjustment unit 55, configured to adjust the thread pool according to the comparison result.
[0106] Please refer to Figure 8 . An embodiment of this specification further provides a task processing device. The device may include the following units.
[0107] A first setting unit 61, configured to set a plurality of task groups, and each task group includes a type of task;
[0108] A second setting unit 63, configured to set a thread pool for each task group;
[0109] An allocation unit 65, configured to allocate a target task to a target thread pool so that a thread in the target thread pool executes the target task, and the target thread pool corresponds to the task group to which the target task belongs.
[0110] Please refer to Figure 9 . An embodiment of this specification further provides a computing device.
[0111] The computing device may include a memory and a processor.
[0112] In this embodiment, the memory includes, but is not limited to, a dynamic random access memory (DRAM) and a static random access memory (SRAM), etc. The memory may be used to store computer instructions.
[0113] In this embodiment, the processor may be implemented in any suitable manner. For example, the processor may take the form of, for example, a microprocessor or a processor, a computer-readable medium storing computer-readable program code (such as software or firmware) executable by the (micro)processor, logic gates, switches, an application specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller, and so on. The processor may be used to execute the computer instructions to implement Figure 3 , Figure 4 or Figure 5 the corresponding embodiments.
[0114] It should be noted that the embodiments in this specification are all described in a progressive manner. For the same or similar parts between the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the device embodiments and the computing device embodiments, since they are basically similar to the method embodiments, the description is relatively simple. For the relevant parts, reference can be made to the partial description of the method embodiments. In addition, it can be understood that after reading this specification document, those skilled in the art can, without creative work, think of arbitrarily combining some or all of the embodiments listed in this specification, and these combinations are also within the scope of disclosure and protection of this specification.
[0115] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to circuit structures such as diodes, transistors, switches, etc.) or software improvements (improvements to method flows). However, with the development of technology, many method flow improvements today can be regarded as direct improvements to hardware circuit structures. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement to a method flow cannot be implemented using a hardware entity module. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is an integrated circuit whose logic function is determined by the user programming the device. Designers can program themselves to "integrate" a digital system onto a single PLD, without having to ask a chip manufacturer to design and fabricate a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly implemented using "logic compiler" software, which is similar to the software compilers used in program development and writing. The original code before compilation also has to be written in a specific programming language, which is called a Hardware Description Language (HDL), and there is not just one type of HDL, but many types, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones currently are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also be aware that by simply performing a little logical programming on the method flow using the above-mentioned several hardware description languages and programming it into an integrated circuit, it is easy to obtain the hardware circuit that implements the logical method flow.
[0116] The systems, devices, modules or units illustrated in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer can be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.
[0117] From the description of the above embodiments, those skilled in the art can clearly understand that this specification can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of this specification, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing 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 of this specification.
[0118] This specification can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet-type devices, multi-processor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, and so on.
[0119] This specification can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification can also be practiced in a distributed computing environment, where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0120] Although this specification is depicted through embodiments, those of ordinary skill in the art know that this specification has many variations and changes without departing from the spirit of this specification. It is hoped that the appended claims will cover these variations and changes without departing from the spirit of this specification.
Claims
1. A task processing method, comprising: Set multiple task groups, each task group including one type of task; Set a thread pool for each task group; Assign a target task to a target thread pool so that the threads in the target thread pool execute the target task, and the target thread pool corresponds to the task group to which the target task belongs; Monitor whether the tasks being executed by each thread in the target thread pool time out; If it times out, determine whether the number of tasks corresponding to the target thread pool meets a preset condition; The preset condition includes: the number of tasks corresponding to the thread pool is greater than or equal to the number of threads in the thread pool; If the preset condition is met, select a timeout handling method that matches the type of the timeout task from a set of timeout handling methods, and the set of timeout handling methods includes at least one timeout handling method, and each timeout handling method corresponds to one task type; Process the timeout task according to the selected timeout handling method; If the preset condition is not met, let the thread continue to execute the timeout task.
2. The method according to claim 1, wherein the number of tasks corresponding to the target thread pool includes at least one of the following: The number of tasks being executed by each thread in the target thread pool; The number of tasks in the task queue, where the task queue includes tasks assigned to the target thread pool; The number of tasks in the first task set, where the first task set includes tasks that are resumed after being delayed.
3. The method according to claim 1, wherein the timeout handling mode set includes at least one of the following timeout handling modes: Continue execution, discard, delay execution.
4. The method according to claim 1, wherein the selected timeout handling mode is delay execution; Processing the timeout task includes: Record the timeout task in a second task set, and the second task set includes tasks to be executed later.
5. The method according to claim 4, further comprising: When the number of tasks corresponding to the target thread pool does not meet the preset condition, obtain a task from the second task set as a task in a first task set, and the first task set includes tasks that resume execution after being executed later.
6. The method according to claim 4, further comprising: Obtain a task whose delay time is greater than or equal to the longest delay time from the second task set as a task in the first task set, and the first task set includes tasks that resume execution after being executed later.
7. The method according to claim 1, if timeout occurs, further comprising: Generate an alarm message for reminding project personnel that a timeout exception has occurred.
8. A thread pool management method, comprising: Set multiple task groups, each task group including one type of task; Set a thread pool for each task group; Assign a target task to a target thread pool so that the threads in the target thread pool execute the target task, and the target thread pool corresponds to the task group to which the target task belongs; Monitor the time consumption of the threads in the target thread pool when executing tasks; Compare the time consumption with a reference time consumption; wherein, the comparing the time consumption with the reference time consumption includes: calculating the growth rate of the time consumption relative to the reference time consumption; Adjust the target thread pool according to the comparison result; wherein, the adjusting the target thread pool includes: if the growth rate is less than or equal to a preset threshold, perform at least one of the following: increase the number of threads in the target thread pool, increase the number of threads that the target thread pool can accommodate; if the growth rate is greater than the preset threshold, perform at least one of the following: reduce the number of threads in the target thread pool, reduce the number of threads that the target thread pool can accommodate.
9. The method according to claim 8, wherein monitoring the time taken by a thread in the monitored target thread pool to execute a task includes: Monitor the average time consumption of the threads in the target thread pool when executing the most recent group of tasks; The reference time consumption includes: the average time consumption of the threads in the target thread pool when executing the previous group of tasks.
10. A task processing device, comprising: A first setting unit for setting multiple task groups, each task group including one type of task; A second setting unit for setting a thread pool for each task group; An allocation unit for allocating a target task to a target thread pool so that threads in the target thread pool execute the target task, where the target thread pool corresponds to the task group to which the target task belongs; A monitoring unit for monitoring whether the tasks being executed by each thread in the target thread pool time out; A judgment unit for judging, if it times out, whether the number of tasks corresponding to the target thread pool meets a preset condition; The preset condition includes: the number of tasks corresponding to the thread pool is greater than or equal to the number of threads in the thread pool; An acquisition unit for, if the preset condition is met, selecting a timeout handling method that matches the type of the timeout task from a set of timeout handling methods, where the set of timeout handling methods includes at least one timeout handling method, and each timeout handling method corresponds to a task type; if the preset condition is not met, causing the thread to continue executing the timeout task; A processing unit for processing the timeout task according to the selected timeout handling method.
11. A thread pool management device, comprising: A first setting unit for setting a plurality of task groups, each task group including a type of task; A second setting unit for setting a thread pool for each task group; An allocation unit for allocating a target task to a target thread pool so that threads in the target thread pool execute the target task, where the target thread pool corresponds to the task group to which the target task belongs; A monitoring unit for monitoring the time consumed by the threads in the target thread pool when executing tasks; A comparison unit for comparing the time consumed with a reference time; wherein, the comparing the time consumed with the reference time includes: calculating the growth rate of the time consumed relative to the reference time; An adjustment unit for adjusting the target thread pool according to the comparison result; wherein, the adjusting the target thread pool includes: if the growth rate is less than or equal to a preset threshold, performing at least one of the following: increasing the number of threads in the target thread pool, increasing the number of threads that the target thread pool can accommodate; if the growth rate is greater than the preset threshold, performing at least one of the following: reducing the number of threads in the target thread pool, reducing the number of threads that the target thread pool can accommodate.
12. A computing device, comprising: At least one processor; A memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, and the program instructions include instructions for executing the method according to any one of claims 1-9.
Citation Information
Patent Citations
Thread pool management method and system
CN101599027A
Uniform thread pool processing method, application server and computer readable storage medium
CN108345499A
Method and device for setting thread pool parameters, computer device and storage medium
CN110673876A
Data storage method and system, storage medium and electronic equipment
CN110688379A
Task execution using multiple pools of processing threads, each pool dedicated to execute different types of sub-tasks
US8209702B1