Thread management method and device, equipment and storage medium
By deploying a thread pool in the business execution system, directly encapsulating the objective function as a task and scheduling thread execution, the problems of low thread scheduling efficiency and lock occupation during task cancellation in the existing technology are solved, and efficient business execution is achieved.
Patent Information
- Application Number
- CN202411821222.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-03-18
AI Technical Summary
Existing software is less efficient when scheduling threads to execute tasks, and when tasks are cancelled, locks are prone to problems such as locks occupying a lot of memory and deadlocks.
By deploying a thread pool in the business execution system, the objective function is directly encapsulated as a target task, and the threads are scheduled to execute the target task from an idle thread. At the same time, the execution status of the target task is monitored, and when the status is cancelled, the execution of the target task is terminated.
Improve business execution efficiency, avoid problems such as locks occupying a lot of memory and deadlocks when tasks are cancelled, and ensure the efficiency of overall business execution.
Smart Images

Figure CN119645657A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a thread management method, apparatus, device and storage medium. Background Art
[0002] With the development of computer technology and the need for business integration, executing business through software has become one of the more common scenarios.
[0003] In the scenario of running software to execute business, it is usually necessary to generate multiple tasks according to the data to be loaded, and schedule multiple threads to execute the multiple tasks simultaneously to ensure business execution efficiency. However, the efficiency of software scheduling threads to execute tasks is low.
[0004] Based on this, the present application provides a thread management method. Summary of the invention
[0005] The present application provides a thread management method, apparatus, device and storage medium to partially solve the above-mentioned problems existing in the prior art.
[0006] This application adopts the following technical solutions:
[0007] The present application provides a thread management method, which is applied to a business execution system deployed with a thread pool, wherein the thread pool includes a task queue and a plurality of threads, and the thread management method includes:
[0008] From the task queue, determine the target task, which is built based on the target function, which is the function that needs to be called to execute the target task;
[0009] Determine a target thread from idle threads among a plurality of threads, and schedule the target thread to call a target function to execute a target task;
[0010] Monitor the execution status of the target task, and terminate the execution of the target task when the execution status is canceled.
[0011] Optionally, determine the target task from the task queue, including:
[0012] If there is no task in the task queue, a new target task is determined from the task queue again after a time corresponding to the interval time interval according to the preset time interval.
[0013] Optionally, the thread management method further includes:
[0014] If there is no task in the task queue, determine whether there is a sleep instruction in the business execution system;
[0015] When there is a sleep instruction, each thread corresponding to the control thread pool is put into sleep, and after waiting for a specified time, the step of determining the target task from the task queue is executed.
[0016] Optionally, the target task includes multiple associated tasks, and the thread management method further includes:
[0017] Determine the target function based on the function that needs to be called to execute the target business;
[0018] According to the objective function, multiple related tasks are generated;
[0019] The same execution status is set for multiple related tasks, and the multiple related tasks after the execution status is set are added to the task queue.
[0020] Optionally, monitoring the execution status of the target task, and terminating the execution of the target task when the execution status is canceled, includes:
[0021] For each checkpoint among the checkpoints pre-set in the execution process of the target task, when the execution process reaches the checkpoint, determining the execution state of the target task;
[0022] When the execution status is canceled, the execution of the target task is terminated.
[0023] Optionally, the task queue is a first-in-first-out queue or a priority-first queue.
[0024] Optionally, the sleep instruction is generated when the service execution system detects that the sleep condition is met.
[0025] The present application provides a thread management device, which is applied to a business execution system deployed with a thread pool, wherein the thread pool includes a task queue and a plurality of threads, and the thread management device includes:
[0026] A determination module is used to determine a target task from a task queue. The target task is constructed based on a target function. The target function is a function that needs to be called to execute the target task.
[0027] A scheduling module, used to determine a target thread from idle threads among a number of threads, and schedule the target thread to call a target function to execute a target task;
[0028] The monitoring module is used to monitor the execution status of the target task and terminate the execution of the target task when the execution status is canceled.
[0029] The present application provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned thread management method is implemented.
[0030] The present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned thread management method when executing the program.
[0031] At least one of the above technical solutions adopted in this application can achieve the following beneficial effects:
[0032] This specification provides a thread management method, which is applied to a business execution system with a thread pool deployed internally, and the thread pool includes a task queue and multiple threads. The tasks in the task queue are constructed based on the target function, such as being obtained by directly encapsulating the function pointer of the target function corresponding to the task. By determining the target task from the task queue and determining the target thread from the idle threads, the target thread is scheduled to execute the target task. In addition, the thread management method can monitor the execution status of the target task, and when it is detected that the execution status is canceled, the execution of the target task is terminated and a new target task is re-determined from the task queue.
[0033] In this way, by directly encapsulating the target function as a target task and scheduling the thread to execute the corresponding target task, the process of matching the operation language with the thread pool can be omitted, thereby improving the business execution efficiency to a certain extent and accurately scheduling the thread pool. In addition, by monitoring the execution status of the target task and terminating the execution of the target task when the execution status is canceled, it is possible to avoid the situation where a large amount of memory is required when the lock mechanism is used when the execution status of the target task is canceled, thereby further ensuring the overall business execution efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0035] Figure 1 A flowchart of a thread management method provided by this application;
[0036] Figure 2 A structural diagram of a thread management device provided by this application;
[0037] Figure 3 The corresponding Figure 1 Schematic diagram of electronic equipment. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. 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 making creative work are within the scope of protection of the present application.
[0039] It should be noted that all actions to obtain signals, information or data in this application are carried out in compliance with the relevant data protection laws and policies of the location and with the authorization given by the owner of the corresponding device.
[0040] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0041] When executing business, current business execution systems usually use a thread pool provided by a third party, and match the thread pool with their own business execution logic and operating language through the interface reserved by the thread pool to schedule the thread pool provided by the third party.
[0042] However, since the business execution system usually contains programs corresponding to multiple operating languages, the target functions required to be called by different businesses and the operating languages corresponding to the target functions are not exactly the same, which makes it difficult for the business execution system to adapt the thread pool to itself based on the business execution logic and the operating language. Usually, the thread pool cannot be perfectly matched with its own business execution logic, which reduces the efficiency of business execution. Among them, the operating language is the type of the program language corresponding to the target function, such as C++ language, C language, etc.
[0043] In addition, when faced with a task cancellation scenario, the method usually adopted is to lock each thread to handle it. In this scenario, not only does the lock as an object occupy a large amount of memory, and when the thread cannot obtain the lock, it is placed in a waiting queue and occupies a large amount of memory. There may also be various problems such as deadlock and lock nesting.
[0044] Based on this, the specification provides a thread management method, which is applied to a business execution system with a thread pool deployed internally, and the thread pool contains a task queue and multiple threads. Therefore, by determining the target task obtained by encapsulating the target function from the task queue, and determining the target thread from the idle threads, scheduling the target thread to execute the target task, and monitoring the execution status of the target task, when the execution status of the target task is monitored to be canceled, the execution of the target task is terminated, and the target task is continued to be determined from the task queue. In this way, by directly encapsulating the target function as the target task and scheduling the thread to execute the corresponding target task, the thread pool can be accurately scheduled without matching the operating language with the thread pool, and at the same time, it is avoided that the lock mechanism is used to occupy more memory when the execution status of the target task is canceled, thereby ensuring the efficiency of business execution.
[0045] Figure 1 A flowchart of a thread management method provided in this application.
[0046] S100: Determine a target task from a task queue, where the target task is constructed based on a target function, and the target function is a function that needs to be called when executing the target task.
[0047] The embodiment of the present application provides a thread management method, the execution process of which can be executed by a business execution system deployed with a thread pool. The business execution system can be deployed in electronic devices such as servers and terminals. The electronic device can be a terminal held by a user such as a mobile phone, a tablet computer, a smart device, or a device such as a display screen panel provided by a service provider to a user.
[0048] When executing business, the current business execution system usually uses a thread pool provided by a third party, and matches the thread pool with its own business execution logic and operating language through the interface reserved by the thread pool to schedule the thread pool provided by the third party. Different from the current business execution system, the business execution system in this specification has a thread pool containing a task queue and multiple threads deployed internally. The thread pool can generate target tasks based on the target function called to execute the business, and schedule the target thread to execute the target task. It can be seen that without matching the thread pool with the business execution system through an interface, the business execution system can also execute business by scheduling the thread pool.
[0049] Based on the above brief description of the thread management method in this specification, it is obvious that the server can first determine the target task from the task queue.
[0050] Specifically, the service execution system may determine in advance, based on the service identifier of the target service to be executed, the target function to be called to execute the target service from among the functions to be called.
[0051] In one example, the business execution system may pre-store associations between various business identifiers and various functions to be called, such as the association between business A and function B to be called, the association between business C and function D to be called, etc. Among them, function B to be called and function D to be called may correspond to different programs in the business execution system. Similarly, the operation languages and business execution logics corresponding to function B to be called and function D to be called may not be completely the same or may be completely different.
[0052] Afterwards, the business execution system can directly generate tasks that can be used to schedule threads for execution based on the target function, and add the generated tasks to the task queue.
[0053] Therefore, the business execution system can determine the target task from the task queue and execute subsequent steps according to the determined target task.
[0054] In one example, the business execution system may determine the function pointer of the target function, and encapsulate the function pointer of the target function to generate a task structure that can be used to schedule threads to execute the task.
[0055] In one example, the business execution system may predefine a specific class, which may include multiple objects, each of which may correspond to a target function. The business execution system may then encapsulate the object pointer and the function pointer based on the function pointer of the target function and the object pointer of the object allocated to the target function to generate a task that can be used to schedule a thread to execute.
[0056] In one example, the business execution system may call the postTask method to package the target function into a task and put it into a task queue.
[0057] In an example, the target function may be at least one of a C procedure function, a C++ member function, and a C++ functor.
[0058] In one example, the number of threads in the thread pool can be adaptively adjusted according to the hardware and the number of tasks.
[0059] S102: Determine a target thread from idle threads among a plurality of threads, and schedule the target thread to execute a target task.
[0060] In one or more embodiments provided in this specification, as described above, after determining the target task, the business execution system can schedule threads in the thread pool to execute the target task.
[0061] Specifically, the service execution system may monitor the status of each thread, and when a thread in an idle state is detected, any thread is selected from the threads in the idle state as the target thread.
[0062] In one example, the business execution system can also determine the computing resources corresponding to each idle thread, and at the same time, determine the computing resources required to execute the target task, and then select a thread from each idle thread whose computing resources are not less than the computing resources required to execute the target task based on the computing resources corresponding to each idle thread and the computing resources required to execute the target task, as the target thread.
[0063] In one example, each thread may have a corresponding identifier, and the service execution system may monitor the status of each thread according to the identifier of each thread, and when there is an idle thread, the idle thread is immediately used as the target thread. In this way, the service execution efficiency can be further guaranteed.
[0064] In one example, the service execution system may also determine multiple idle threads to execute the same task.
[0065] After determining the target thread, the business execution system can schedule the target thread to execute the target task, that is, schedule the target thread to access and execute the target function corresponding to the target task, and return the execution result. Of course, how to schedule threads to execute tasks is a relatively mature technology at present, and this specification will not repeat it.
[0066] It should be noted that the thread in this specification represents computing resources. As a schedulable computing unit, it relies on the processing power provided by the computer hardware system to execute a specific task sequence, thereby achieving effective utilization and allocation management of system computing resources.
[0067] S104: monitoring the execution status of the target task, and terminating the execution of the target task when the execution status is canceled.
[0068] In one or more embodiments provided in this specification, as described above, the thread management method can handle the scenario where a large number of tasks are canceled.
[0069] Specifically, the business execution system may determine the execution status of the target task. When the execution status is canceled, the business execution system may control the target thread to terminate the execution of the target task and release the computing resources occupied by the target thread.
[0070] In one example, the computing resources occupied by the target thread include memory resources.
[0071] Afterwards, the business execution system may re-execute step S100, redetermine a new target task from the task queue, and execute steps S100-S104 according to the redetermined target task.
[0072] like Figure 1 The thread management method shown is applied to a business execution system with a thread pool deployed internally, and the thread pool includes a task queue and multiple threads. The tasks in the task queue are constructed based on the target function, such as being obtained by directly encapsulating the function pointer of the target function corresponding to the task. By determining the target task from the task queue and determining the target thread from the idle threads, the target thread is scheduled to execute the target task. In this way, by directly encapsulating the target function as the target task and scheduling the thread to execute the corresponding target task, the process of matching the operating language with the thread pool can be omitted, and the thread pool can be accurately scheduled to ensure business execution efficiency.
[0073] At the same time, during the operation of the software, it is often necessary to repeatedly process or cancel the data. Taking the loading of image data as an example, during the operation of the software, it is often necessary to repeatedly load or cancel the loading of image data. When processing data, it is usually necessary to generate multiple tasks according to the data to be processed, and schedule multiple threads to perform the above tasks. When canceling the data, it is usually necessary to cancel the multiple tasks generated above. For generating multiple tasks, it is undoubtedly necessary to schedule more computing resources. For canceling multiple tasks, the more common task cancellation processing method currently requires setting different locks for each task. In this case, if multiple tasks are canceled at the same time, not only will there be problems such as locks occupying a large amount of memory as objects and threads being placed in waiting queues when they cannot obtain locks and occupying a large amount of memory, but there may also be deadlocks, lock nesting and other problems.
[0074] Based on the thread management method provided in this specification, the execution status of the target task can be monitored, and when the execution status of the target task is detected to be canceled, the execution of the target task is terminated. In this way, the process of setting different locks for each task can be omitted, and the cancellation of a large number of tasks can be quickly processed without setting different locks for each task, thereby ensuring the efficiency of business execution.
[0075] In addition, in one example, the business execution system may predefine a specific class, which may contain multiple objects, each of which may correspond to a target function. Then, the business execution system may encapsulate the object pointer and the function pointer according to the function pointer of the target function and the object pointer of the object assigned to the target function, and generate a task that can be used to schedule threads for execution. In other words, the present application adopts a technical means of directly encapsulating the function pointer of the target function to obtain a task structure. Compared with determining a task structure containing multiple parameters and a target function according to the parameter transmission route in the program, the present application takes up less memory and requires less execution time when scheduling threads to execute the target task.
[0076] Furthermore, in step S100, it may happen that there is no task in the task queue. In this case, the business execution system may obtain a new task from the task queue again at a preset time interval after a time corresponding to the time interval, and use the obtained new task as the target task, and re-execute steps S100-S104 according to the target task.
[0077] In one example, after the above steps are repeated for a specified number of times, the business execution system may determine that there are no tasks in the task queue within a short period of time, and the business execution system may control each thread corresponding to the thread pool to sleep.
[0078] When there is no task in the task queue, the target task is determined from the task queue according to the preset time interval. In this way, each task in the task queue can be monitored, so that when a large number of tasks are generated, each thread in the thread pool can be scheduled in time to execute the task.
[0079] Furthermore, in step S100, the service execution system can also directly control each thread to sleep. Specifically, when there is no task in the task queue, the service execution system can also directly determine whether there is a sleep instruction. The sleep instruction can be issued by the service execution system when it detects that the sleep condition is met. The sleep condition can be the arrival of a preset time, the failure to receive a service execution request within a preset specific time, etc.
[0080] If there is a sleep instruction, the business execution system can control each thread corresponding to the thread pool to sleep, and after waiting for a specified time, re-obtain tasks from the task queue.
[0081] If there is no sleep instruction, the service execution system can obtain tasks from the task queue at a preset time interval.
[0082] In this way, when the sleep conditions are met, each thread corresponding to the thread pool can be controlled to sleep in time, thus avoiding the waste of computing resources.
[0083] In addition, for each target business, the number of target tasks corresponding to the target business may be one or more. In the case where the number of target tasks corresponding to the target business is multiple, in step S100, the business execution system may also determine the target function according to the function required to execute the target business, and generate multiple associated tasks according to the target function.
[0084] In one example, taking the target business as determining the business indicators of two users, Xiaohong and Xiaoming, as an example, the target function can be a function for determining the business indicators, and the multiple associated tasks can be a task corresponding to the business indicators of Xiaohong and a task corresponding to the business indicators of Xiaoming, or a task corresponding to the business data of the two users, Xiaohong and Xiaoming, and a task corresponding to the business indicators determined based on the business data. How to determine the target function, how to generate tasks based on the target function, and how many tasks are generated can be set as needed, and this specification does not limit this.
[0085] Afterwards, the business execution system can set the same execution state for each associated task, and add each associated task after the execution state is set to the task queue. In one example, the execution state can be a parameter such as a token that can be used to characterize the state of the task, and the parameter is stored in the memory.
[0086] In this way, multiple related tasks corresponding to a target business can be set with the same execution status. When the business is canceled, the business execution system can terminate multiple related tasks at the same time, avoiding the situation where the canceled tasks still occupy more computing resources, further ensuring the business execution efficiency.
[0087] Furthermore, during the task execution process, the service execution system may also preset multiple checkpoints for the task execution process. For each checkpoint, when the service execution reaches the checkpoint, the service execution system may determine the execution status of the target task. When the determined execution status is canceled, the service execution system may terminate the execution of the target task, and when the determined execution status is not canceled, the service execution system may continue to execute the target task.
[0088] In one example, taking a data processing task as an example, the task may have multiple stages, such as data reading, data cleaning, data analysis, and data storage. The end point of each stage can be set as a checkpoint.
[0089] In addition, in step S100, the task queue preset in the service execution system may be a first-in-first-out queue, a priority-first queue, or a queue set according to user needs.
[0090] Based on the same idea, the present application provides a structural diagram of a thread management device, such as Figure 2 shown.
[0091] Figure 2 A schematic diagram of a thread management device provided in this application, which is applied to a business execution system deployed with a thread pool, wherein the thread pool includes a task queue and a plurality of threads, wherein:
[0092] The determination module 200 is used to determine a target task from the task queue. The target task is constructed based on a target function, and the target function is a function that needs to be called to execute the target task.
[0093] The scheduling module 202 is used to determine a target thread from idle threads among a plurality of threads, and schedule the target thread to call a target function to execute a target task.
[0094] The monitoring module 204 is used to monitor the execution status of the target task and terminate the execution of the target task when the execution status is canceled.
[0095] Optionally, the determination module 200 is used to: if there is no task in the task queue, then according to a preset time interval, after a time corresponding to the interval time interval, re-determine a new target task from the task queue.
[0096] Optionally, the determination module 200 is used to: if there is no task in the task queue, determine whether there is a sleep instruction in the business execution system; when there is a sleep instruction, control each thread corresponding to the thread pool to sleep, and after waiting for a specified time, execute the step of determining the target task from the task queue.
[0097] Optionally, the determination module 200 is used to: determine the target function according to the function called to execute the target business; generate multiple related tasks according to the target function; set the same execution state for the multiple related tasks, and add the multiple related tasks after the execution state is set to the task queue.
[0098] Optionally, the monitoring module 204 is used to: for each checkpoint in the checkpoints pre-set during the execution of the target task, when the execution process reaches the checkpoint, determine the execution status of the target task; when the execution status is canceled, terminate the execution of the target task.
[0099] Optionally, the task queue is a first-in-first-out queue or a priority-first queue.
[0100] Optionally, the sleep instruction is generated when the service execution system detects that the sleep condition is met.
[0101] The present application also provides a computer-readable storage medium, which stores a computer program, which can be used to execute the above Figure 1 The thread management method shown.
[0102] This application also provides Figure 3 The schematic structure diagram of the electronic device shown in FIG. Figure 3 As mentioned above, in terms of hardware units, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include other hardware required for the business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to achieve the above Figure 1 Of course, in addition to the software implementation, this application does not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0103] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. 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 in 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 such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, 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 are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0104] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.
[0105] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may 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 a combination of any of these devices.
[0106] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0107] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0108] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0109] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0110] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0111] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0112] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0113] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0114] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0115] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0116] The present application may 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. The present application may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0117] Each embodiment in this application is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0118] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A thread management method, the thread management method is applied to a business execution system deployed with a thread pool, the thread pool includes a task queue and a plurality of threads, the thread management method includes: Determine a target task from the task queue, wherein the target task is constructed based on a target function, and the target function is a function required to be called to execute the target task; Determine a target thread from idle threads among the plurality of threads, and schedule the target thread to call the target function to execute the target task; The execution status of the target task is monitored, and when the execution status is canceled, the execution of the target task is terminated.
2. The method according to claim 1, wherein determining the target task from the task queue comprises: If there is no task in the task queue, a new target task is determined from the task queue again after a time corresponding to the time interval according to a preset time interval.
3. The method of claim 1, further comprising: If there is no task in the task queue, determining whether there is a sleep instruction in the service execution system; When there is a sleep instruction, each thread corresponding to the thread pool is controlled to sleep, and after waiting for a specified time, the step of determining the target task from the task queue is executed.
4. The method according to claim 1, wherein the target task includes a plurality of associated tasks, and the thread management method further comprises: Determine the target function according to the function called to execute the target business; generating the plurality of associated tasks according to the objective function; The same execution state is set for the multiple associated tasks, and the multiple associated tasks after the execution state is set are added to the task queue.
5. The method according to claim 1, wherein monitoring the execution status of the target task and terminating the execution of the target task when the execution status is canceled comprises: For each checkpoint preset in the execution process of the target task, when the execution process reaches the checkpoint, determining the execution state of the target task; When the execution status is canceled, the execution of the target task is terminated.
6. The method according to claim 3, wherein the sleep instruction is generated when the service execution system detects that a sleep condition is met.
7. The method according to any one of claims 1 to 6, wherein the task queue is a first-in-first-out queue or a priority-first queue.
8. A thread management device, the thread management device is applied to a business execution system deployed with a thread pool, the thread pool includes a task queue and a plurality of threads, the thread management device includes: A determination module, used to determine a target task from the task queue, wherein the target task is constructed based on a target function, and the target function is a function required to be called to execute the target task; A scheduling module, used for determining a target thread from idle threads among the plurality of threads, and scheduling the target thread to call the target function to execute the target task; The monitoring module is used to monitor the execution status of the target task and terminate the execution of the target task when the execution status is canceled.
9. A computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
10. 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 method according to any one of claims 1 to 7 when executing the program.
Citation Information
Cited By
Service execution method and management controller
CN121579244A
Business execution method and management controller
CN121579244B