Task management method and system, device, electronic device, and storage medium
By obtaining the execution order in the target task information, the tasks are automatically added to the corresponding task queue, which solves the problem of cumbersome task scheduling and management in the existing technology, and improves the efficiency and convenience of task execution.
Patent Information
- Application Number
- CN202411931963.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-04-08
AI Technical Summary
In the prior art, task scheduling and management are relatively cumbersome, resulting in inefficient task execution.
By obtaining the execution order in the target task information, the tasks are automatically added to the corresponding serial or parallel task queue, and the tasks are scheduled to be executed in the thread in sequence or simultaneously.
It improves the efficiency and convenience of task scheduling management, reduces the difficulty of task execution, and avoids thread leakage problems.
Smart Images

Figure CN119781933A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a task management method and system, device, electronic device, and storage medium. Background Art
[0002] When detecting a task to be executed, the operating system of the electronic device (eg, Android system, etc.) usually schedules threads to execute the task according to certain scheduling rules to ensure that the task can be executed in a predetermined execution order.
[0003] However, it is found in practice that the current method of scheduling threads to execute tasks is rather cumbersome, thereby reducing the efficiency of task execution. Summary of the invention
[0004] The embodiments of the present application disclose a task management method and system, device, electronic device, and storage medium, which can automatically add target tasks to corresponding task queues for management and scheduling according to the execution order between multiple target tasks, thereby improving the efficiency of task scheduling management and thus improving the efficiency of task execution.
[0005] The first aspect of the embodiment of the present application discloses a task management method, the method comprising:
[0006] Acquire target task information, wherein the target task information includes an execution order between multiple target tasks to be executed, wherein the execution order includes a serial order or a parallel order;
[0007] When the execution order is a serial order, the multiple target tasks are added to a serial task queue, and the target tasks in the serial task queue are sequentially scheduled to threads for execution;
[0008] In the case where the execution order is a parallel order, the multiple target tasks are added to a parallel task queue, and the multiple target tasks are scheduled from the parallel task queue to different threads for execution.
[0009] The second aspect of the embodiment of the present application discloses a task management system, the system comprising: an application layer and a framework layer, the framework layer comprising an interface module and a task management module, wherein:
[0010] The application layer is used to call the target interface provided by the interface module and send target task information to the task management module, wherein the target task information includes an execution order between multiple target tasks to be executed, and the execution order includes a serial order or a parallel order;
[0011] The task management module is used to add the multiple target tasks to a serial task queue and schedule the target tasks in the serial task queue to the thread for execution in sequence when the execution order is a serial order; or
[0012] In the case where the execution order is a parallel order, the multiple target tasks are added to a parallel task queue, and the multiple target tasks are scheduled from the parallel task queue to different threads for execution.
[0013] A third aspect of an embodiment of the present application discloses a task management device, the device comprising:
[0014] An acquisition unit, used for acquiring target task information, wherein the target task information includes an execution order between a plurality of target tasks to be executed, wherein the execution order includes a serial order or a parallel order;
[0015] A first scheduling unit is used to add the multiple target tasks to a serial task queue when the execution order is a serial order, and sequentially schedule the target tasks in the serial task queue to threads for execution;
[0016] The second scheduling unit is used to add the multiple target tasks to a parallel task queue when the execution order is a parallel order, and schedule the multiple target tasks from the parallel task queue to different threads for execution.
[0017] A fourth aspect of the present application discloses an electronic device, including:
[0018] A memory storing executable program code;
[0019] a processor coupled to the memory;
[0020] The processor calls the executable program code stored in the memory to execute the task management method disclosed in the first aspect of the embodiment of the present application.
[0021] A fifth aspect of an embodiment of the present application discloses a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to execute the task management method disclosed in the first aspect of an embodiment of the present application.
[0022] A sixth aspect of the embodiments of the present application discloses a computer program product. When the computer program product runs on a computer, the computer executes part or all of the steps of any one of the methods of the first aspect of the embodiments of the present application.
[0023] A seventh aspect of an embodiment of the present application discloses an application publishing platform, which is used to publish a computer program product. When the computer program product runs on a computer, the computer executes part or all of the steps of any one of the methods of the first aspect of the embodiment of the present application.
[0024] Compared with the related art, the embodiments of the present application have the following beneficial effects:
[0025] In the embodiment of the present application, target task information can be obtained, wherein the target task information can include the execution order between multiple target tasks to be executed, and the execution order can include serial order or parallel order; and then when the execution order is serial order, multiple target tasks can be added to the serial task queue, and the target tasks in the serial task queue are sequentially scheduled to the thread for execution; when the execution order is parallel order, multiple target tasks are added to the parallel task queue, and multiple target tasks are scheduled from the parallel task queue to different threads for execution. It can be seen that in the embodiment of the present application, when the target task information is obtained, multiple target tasks can be added to the task queue corresponding to the execution order according to the execution order between multiple target tasks for management and scheduling, and the serial task queue and the parallel task queue respectively adopt different task scheduling logics, which improves the efficiency of task scheduling management; in addition, the upper-level application does not need to pay attention to the underlying thread creation and scheduling issues, and the upper-level application only needs to pass the execution order between multiple target tasks, which reduces the difficulty of task execution and improves the efficiency of task execution. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0027] Figure 1 It is a flowchart of a task management method disclosed in an embodiment of the present application;
[0028] Figure 2 is a schematic diagram of a target interface disclosed in an embodiment of the present application;
[0029] Figure 3 It is a flowchart of another task management method disclosed in an embodiment of the present application;
[0030] Figure 4 It is a scheduling diagram of a serial task queue disclosed in an embodiment of the present application;
[0031] Figure 5 It is a scheduling diagram of a parallel task queue disclosed in an embodiment of the present application;
[0032] Figure 6 It is a flowchart of another task management method disclosed in an embodiment of the present application;
[0033] Figure 7 It is a resource allocation schematic diagram disclosed in an embodiment of the present application;
[0034] Figure 8 It is a structural diagram of a task management system disclosed in an embodiment of the present application;
[0035] Fig. 9 It is a structural diagram of a task management device disclosed in an embodiment of the present application;
[0036] Fig.10 It is a structural schematic diagram of an electronic device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0037] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0038] It should be noted that the terms "first", "second", "third" and "fourth" in the specification and claims of the present application are used to distinguish different objects rather than to describe a specific order. The terms "including" and "having" in the embodiments of the present application and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device including a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0039] The embodiments of the present application disclose a task management method and system, device, electronic device, and storage medium, which can automatically add target tasks to corresponding task queues for management and scheduling according to the execution order between multiple target tasks, thereby improving the efficiency of task scheduling management and thus improving the efficiency of task execution.
[0040] The technical solution of the present application will be described in detail below in conjunction with specific embodiments.
[0041] In order to more clearly introduce the task management method and system, electronic device, and storage medium disclosed in the embodiment of the present application. First, the application scenarios suitable for the method are introduced. Optionally, the method can be applied to the task operation scheduling inside various electronic devices, and the electronic devices may include: portable electronic devices such as mobile phones and tablets, wearable devices such as smart watches and smart bracelets, or desktop devices such as desktop computers and desktop TVs, which are not limited here.
[0042] Optionally, the method may be applied to various operating systems for task execution scheduling, and the operating systems may include: Android operating system, IOS operating system or Windows operating system, etc., which are not limited here.
[0043] In the related art, when electronic devices perform task scheduling, they need to create a thread pool, and then schedule threads to execute corresponding tasks based on the threads in the thread pool as the basic scheduling unit. In this process, users (such as upper-level applications) need to pay attention to the management of various life cycle stages such as creation, scheduling and closing of each thread. When there are many threads, scheduling is more cumbersome, thereby reducing the efficiency of task scheduling.
[0044] In addition, when there are a large number of threads, the threads may continue to grow due to the user's failure to close the threads that have completed the task in time, which may lead to thread leakage problems and increase the memory space occupied by the electronic device.
[0045] In this regard, the embodiments of the present application disclose a task management method and system, an electronic device, and a storage medium to solve the technical problems in the related art. Optionally, the method can be applied to various electronic devices introduced above. Optionally, the method can be applied to an application or system service in an electronic device, which is not limited here.
[0046] Optionally, the electronic device may obtain target task information, wherein the target task information may include an execution order between multiple target tasks to be executed, and the execution order may include a serial order or a parallel order; and then, when the execution order is a serial order, the multiple target tasks may be added to a serial task queue, and the target tasks in the serial task queue may be scheduled to threads for execution in turn; when the execution order is a parallel order, the multiple target tasks may be added to a parallel task queue, and the multiple target tasks may be scheduled from the parallel task queue to different threads for execution.
[0047] It can be seen that the embodiment of the present application can automatically add the target task to the corresponding task queue for management and scheduling according to the execution order between multiple target tasks when the target task information is obtained, thereby improving the convenience and efficiency of task scheduling management; in addition, the user no longer needs to pay attention to the underlying thread creation and scheduling issues. The user only needs to input the execution order between multiple target tasks, which reduces the difficulty of task scheduling; and, since the user no longer needs to pay attention to the closing of threads, it can avoid the problem of continuous thread growth and thread leakage caused by the user's failure to close the thread that has completed the task in time.
[0048] Based on this, the task management method and system, electronic device, and storage medium disclosed in the embodiments of the present application are introduced below.
[0049] See also Figure 1 , Figure 1 1 is a flowchart of a task management method disclosed in an embodiment of the present application. Optionally, the method can be applied to various electronic devices introduced above, or other execution entities, which are not limited here. Optionally, the method can include the following steps:
[0050] 102. Obtain target task information, where the target task information includes an execution order between multiple target tasks to be executed, where the execution order includes a serial order or a parallel order.
[0051] In the embodiment of the present application, the target task information may include: application tasks issued by an upper-layer application program, and / or system tasks issued by an operating system of the electronic device, etc., which are not limited here.
[0052] Optionally, the task lower initiator (eg, an upper layer application, an operating system, etc.) may transmit the target task information by calling a target interface, and then the electronic device may acquire the target task information.
[0053] Optionally, the target interface may include an application programming interface (API), which may provide an interface for the task initiator to transmit target task information to the electronic device, thereby facilitating the electronic device to uniformly receive the target task information and further facilitate the electronic device to manage the target task information.
[0054] In the embodiment of the present application, the target task information may include: the execution order between multiple target tasks to be executed, the task content of multiple target tasks, etc., which are not limited here.
[0055] The execution order between multiple target tasks can include: serial order or parallel order. Serial order means that multiple target tasks are executed in sequence, and the next target task can be executed only after the previous task is executed. Parallel order means that multiple target tasks have no restrictions on the order of execution, and multiple target tasks can be executed at the same time.
[0056] In an optional embodiment, the target task information may also include name information, attribute information, and priority information of the target task, which are not limited here. The name information is used to distinguish different target tasks; the attribute information is used to indicate the source, business, data volume and format of the target task, which are not limited here; the priority information is used to indicate the resource allocation method of the thread corresponding to the target task.
[0057] See also Figure 2 , Figure 2 2 is a schematic diagram of a target interface disclosed in an embodiment of the present application. Optionally, the target interface may include: a task queue creation unit 210 , a task content unit 220 and a sending unit 230 .
[0058] Wherein, the task queue creation unit 210 is used to create a task queue, and the task queue can include a serial queue or a parallel queue. The execution order of the tasks in the serial queue is a serial order, and the execution order of the tasks in the parallel queue is a parallel order, which is not limited here. That is, the task queue can store the execution order between multiple target tasks. Optionally, the name information, attribute information and priority information of the task queue can also be stored in the task queue, which is not limited here.
[0059] Optionally, the task content unit 220 is used to store the task content of the target task, and the task content is used to indicate how to execute the target task.
[0060] Optionally, the sending unit 230 is used to send the created task queue and task content to the electronic device.
[0061] It should be noted that Figure 2 It is only an optional implementation manner and should not be construed as limiting the embodiments of the present application.
[0062] By implementing the above method, the target interface can be used to provide the task sender with an interface for transmitting target task information to the electronic device, thereby facilitating the electronic device to uniformly receive and manage the target task information, and facilitating the interaction of information data between the task sender and the electronic device.
[0063] 104. When the execution order is a serial order, multiple target tasks are added to a serial task queue, and the target tasks in the serial task queue are scheduled to the thread for execution in sequence.
[0064] In an embodiment of the present application, after a task queue is created in the target interface and sent to the electronic device, the electronic device can store the task queue. When the electronic device subsequently receives target task information, it can add multiple target tasks to the corresponding task queue according to the execution order between the multiple target tasks currently received.
[0065] Optionally, when the electronic device determines, based on the target task information, that the execution order of the multiple target tasks is a serial order, the multiple target tasks may be added to a serial task queue.
[0066] It should be noted that the target tasks in the serial task queue are in a serial order, that is, the next target task can be executed only after the previous task is executed. For this, the electronic device can dispatch the target tasks in the serial task queue to the thread for execution in a certain order. Among them, the certain order can include the order in which the target tasks enter the task queue, the order in which the target tasks are executed, etc., which is not limited here.
[0067] It should be further explained that the "sequentially" in the above text means that the electronic device only schedules one target task from the serial task queue to the thread for execution each time to avoid the situation where the next target task has already started execution when the previous target task has not been completed.
[0068] Optionally, there may be one or more serial task queues, and one business may correspond to one or more serial task queues. Multiple target tasks included in each serial task queue belong to the same business.
[0069] 106. When the execution order is a parallel order, multiple target tasks are added to a parallel task queue, and the multiple target tasks are scheduled from the parallel task queue to different threads for execution.
[0070] In the embodiment of the present application, the parallel task queue may be the task queue created by the target interface as described above. Optionally, the electronic device may add the multiple target tasks to the parallel task queue when determining that the execution order between the multiple target tasks is a parallel order according to the target task information.
[0071] It should be noted that there is no sequential execution order among the multiple target tasks included in the parallel task queue, and they can be executed simultaneously. Optionally, the electronic device can schedule multiple target tasks from the parallel task queue to different threads for simultaneous execution, so as to maximize the parallel execution of multiple target tasks and improve the execution efficiency of the target tasks.
[0072] Optionally, the number of the multiple target tasks to be scheduled may be less than or equal to the upper limit of threads that can exist simultaneously at present. The upper limit of threads that can exist simultaneously at present may include: the sum of currently idle threads and new threads that can be newly created.
[0073] In another optional embodiment, the number of the multiple target tasks to be scheduled may be less than or equal to a first number threshold, wherein the first number threshold may be set by a developer or user according to requirements, and the first number threshold is less than the upper limit of threads that can exist simultaneously.
[0074] By implementing the above method, developers or users can set the number of target tasks to be executed in parallel according to requirements, thereby improving the flexibility and controllability of the method.
[0075] Optionally, there may be one or more parallel task queues, and one business may correspond to one or more parallel task queues. Multiple target tasks included in each parallel task queue belong to the same business.
[0076] By implementing the methods disclosed in the above embodiments, target task information can be obtained, wherein the target task information can include the execution order between multiple target tasks to be executed, and the execution order can include serial order or parallel order; further, when the execution order is serial order, multiple target tasks can be added to the serial task queue, and the target tasks in the serial task queue are sequentially scheduled to the thread for execution; when the execution order is parallel order, multiple target tasks are added to the parallel task queue, and multiple target tasks are scheduled from the parallel task queue to different threads for execution. It can be seen that when the target task information is obtained, the embodiment of the present application can automatically add the target task to the corresponding task queue for management and scheduling according to the execution order between multiple target tasks, thereby improving the convenience and efficiency of task scheduling management; in addition, the user does not need to pay attention to the underlying thread creation and scheduling issues, and the user only needs to enter the execution order between multiple target tasks, thereby reducing the difficulty of task scheduling.
[0077] See also Figure 3 , Figure 3 1 is a flowchart of another task management method disclosed in an embodiment of the present application. Optionally, the method can be applied to various electronic devices introduced above, or other execution entities, which are not limited here. Optionally, the method can include the following steps:
[0078] 302. Obtain target task information, where the target task information includes an execution order between multiple target tasks to be executed, where the execution order includes a serial order or a parallel order.
[0079] 304. When the execution order is a serial order, multiple target tasks are added to a serial task queue, and the target tasks in the serial task queue are sequentially scheduled to the thread for execution.
[0080] As an optional implementation, before scheduling the target task from the serial task queue to the thread for execution, the electronic device may determine whether there are other tasks in the serial task queue that are in an execution state or a waiting state for execution;
[0081] If there are no other tasks in the serial task queue that are in the execution state or waiting for execution state, the electronic device can schedule the target task ranked first in the serial task queue to be executed in the thread; and when the execution of the first target task is completed, the next target task can be scheduled from the serial task queue to be executed in the thread.
[0082] The execution state refers to the state in which the target task is running in the thread; the waiting execution state refers to the state in which the target task is about to be scheduled to run in the thread.
[0083] For example, see Figure 4 , Figure 4 This is a scheduling diagram of a serial task queue disclosed in an embodiment of the present application.
[0084] When the electronic device schedules the first target task A1 from queue 1, since there are no other target tasks in the current queue 1 that are in the execution state or waiting for execution, the electronic device can create a new thread 1 and schedule the target task A1 to be executed in thread 1;
[0085] When the electronic device wants to schedule the second target task A2 from queue 1, it can determine whether the target task A1 is currently executed; if the target task A1 is executed and the current thread 1 is in an idle state, the electronic device can schedule the second target task A2 from queue 1 to thread 1 for execution.
[0086] In one embodiment, if there are other tasks in the serial task queue that are in the execution state or waiting for execution state, or the previous target task has not been completed, the electronic device does not schedule the target task from the serial task queue to the thread for execution.
[0087] Exemplarily, when the target task A1 is not completed, the electronic device does not schedule the target task A2.
[0088] By implementing the above method, the electronic device can schedule the target task from the serial task queue to the thread for execution only when there are no other tasks in the serial task queue that are in the execution state or waiting for execution state, thereby avoiding the situation where two or more target tasks are in the execution state in the same serial task queue at the same time, and further ensuring that the target tasks in the serial task queue are executed in serial order without disrupting the execution order, thereby improving the intelligence of the method.
[0089] It should be further explained that, in the embodiment of the present application, the target tasks in the same serial task queue are not necessarily executed in the same thread, that is, the target tasks in the same serial task queue can be executed in different threads. Figure 4 , target tasks A1, A2, A3 and A4 in the same serial task queue can be executed in different threads, but they are still executed in the serial order in queue 1.
[0090] By implementing the above method, idle threads can be flexibly reused to execute target tasks in the same serial task queue, thereby reducing the total number of threads while ensuring that the target tasks are executed in a normal serial order, thereby reducing the memory space occupied by the electronic device.
[0091] Optionally, since there is no dependency relationship between target tasks in different serial task queues, which means that the execution of a subsequent target task depends on the execution result of a previous target task, the target tasks in different serial task queues may not be executed in a serial order.
[0092] Please refer again Figure 4 For example, when the electronic device schedules target task A2 from queue 1 to thread 1 for execution, it can schedule target task C1 from queue 3 to thread 2 for execution, that is, target task A2 and target task C1 in different serial task queues can run simultaneously.
[0093] Optionally, when the electronic device schedules the target task from the serial task queue to the thread for execution, the target task may be preferentially scheduled to the idle thread for execution. For example, please refer again to Figure 4 When the electronic device schedules the target task B1 from queue 2, since thread 1 has completed executing target task A2 and is in an idle state, the electronic device can preferentially schedule the target task B1 in queue 2 to thread 1 for execution.
[0094] In the related art, when an electronic device executes the target tasks in queue 1, queue 2 and queue 3, it needs to create three threads to execute them respectively. However, by implementing the above method, idle threads can be reused as much as possible to execute the target tasks, thereby reducing the total number of threads (e.g. Figure 4 As shown, only 2 threads are needed), thereby reducing the memory space occupied by the electronic device.
[0095] It should be noted that Figure 4 This is only an optional example for the convenience of explanation, and the execution order of the target tasks, the structure of threads and queues should not constitute a limitation on the embodiments of the present application.
[0096] 306. When the execution order is a parallel order, multiple target tasks are added to a parallel task queue, and the multiple target tasks are scheduled from the parallel task queue to different threads for execution.
[0097] In an embodiment of the present application, there may be multiple parallel task queues, and the electronic device may add target tasks in multiple parallel task queues to the same target queue, and then the electronic device may subsequently schedule the target tasks from the target queue to the thread for execution.
[0098] It should be noted that the target tasks in the parallel task queues do not have the dependency relationship described above, and there is no restriction on the order of execution. For this reason, the electronic device can merge the target tasks in different parallel task queues into the same target queue, so that the subsequent electronic device only needs to schedule the target task from the target queue, without scheduling tasks from multiple parallel task queues, thereby making it more convenient for the electronic device to schedule the target task, and improving the efficiency of the electronic device to schedule the target task.
[0099] For example, see Figure 5 , Figure 5 This is a schematic diagram of scheduling a parallel task queue disclosed in an embodiment of the present application. The electronic device can merge the target tasks included in queues 4 and 5 in the parallel task queue into the target queue, and then the subsequent electronic device can schedule the target task directly from the target queue without scheduling the target task from queues 4 and 5 respectively, thereby simplifying the process of scheduling the target task by the electronic device.
[0100] Optionally, the electronic device may schedule the target task from the target queue to a thread for execution as described above, with the target task being preferentially scheduled to an idle thread for execution; if no idle thread currently exists, the target task is scheduled to a newly created thread for execution.
[0101] For example, please refer again to Figure 5In the related art, two threads are required to execute the target task in queue 4, and one thread is required to execute the target task in queue 5, so a total of three threads are required.
[0102] However, when implementing the method disclosed in the embodiment of the present application, when the electronic device schedules the target task A2 to be executed in the thread, since thread 3 is executing the target task A1 and there is no idle thread at present, the electronic device can create a new thread 4 and schedule the target task A2 to be executed in thread 4; and when scheduling the target task B1 to be executed in the thread, since thread 3 is in an idle state at this time, the electronic device can schedule the target task B1 to be executed in thread 3. Figure 5 As shown, compared with the related art which requires three threads, the method disclosed in the embodiment of the present application only requires the creation of two threads, thereby reducing the number of threads and the occupation of the memory space of the electronic device.
[0103] It should be noted that Figure 5 This is only an optional example for the convenience of explanation, and the execution order of the target tasks, the structure of threads and queues should not constitute a limitation on the embodiments of the present application.
[0104] In an optional implementation, the multiple target tasks may be tasks corresponding to the first business; the electronic device may add the multiple target tasks to the parallel task queue corresponding to the first business. The electronic device may add the multiple target tasks contained in the parallel task queue corresponding to the first business to the target queue, and the target queue may also include tasks in at least one parallel task queue corresponding to another business. That is, the electronic device may merge the target tasks in the parallel task queues corresponding to different businesses into the same target queue.
[0105] For example, please refer again to Figure 5 Assuming that queue 4 corresponds to the first business and queue 5 corresponds to the second business, the electronic device can merge the tasks corresponding to the first business and the second business into the same target queue, so that the target tasks corresponding to different businesses can be flexibly scheduled, instead of having to schedule the target tasks separately according to the business, thereby improving the flexibility of the method.
[0106] By implementing the above method, the electronic device can merge the target tasks in multiple parallel task queues belonging to different services into the same target queue. The subsequent electronic device only needs to schedule the target task from the target queue, without scheduling tasks from multiple parallel task queues, thereby making it more convenient for the electronic device to schedule the target task and improving the efficiency of the electronic device in scheduling the target task.
[0107] In another optional embodiment, each target task may correspond to a priority, and the priority is used to indicate a resource allocation method for a thread corresponding to the target task.
[0108] Optionally, each parallel task queue may have a corresponding priority, and the priority corresponding to the target task in the parallel task queue may be the same as or different from the priority of the parallel task queue in which it is located, that is, each target task may also correspond to a priority that is different from the queue in which it is located, which is not limited here. Optionally, the electronic device may add target tasks with the same priority in the parallel task queue to the same target queue.
[0109] In one embodiment, the priority may include multiple different levels, and each priority may correspond to a target queue. Optionally, the electronic device may add multiple target tasks included in the parallel task queue corresponding to the first service to the target queue corresponding to the priority of each target task, and the tasks included in the same target queue have the same priority.
[0110] Exemplarily, assuming that the five target tasks included in the parallel task queue corresponding to the first business all have corresponding priorities of the first priority, the five target tasks may be added to the target queue corresponding to the first priority.
[0111] Assume that the parallel task queue corresponding to the first business contains 5 target tasks; among them, 3 target tasks correspond to the first priority and 2 target tasks correspond to the second priority. The electronic device can add the 3 target tasks corresponding to the first priority to the target queue corresponding to the first priority, and add the 2 target tasks corresponding to the second priority to the target queue corresponding to the second priority, without limitation here.
[0112] By implementing the above method, the electronic device can add target tasks with the same priority in the parallel task queue to the same target queue, thereby facilitating the electronic device to subsequently schedule the target tasks in the target queue to the thread corresponding to the priority for execution, and also facilitating the electronic device to manage target tasks with the same priority.
[0113] It should be further explained that the target tasks in the target queue are all scheduled from the parallel task queue, so there is no dependency relationship between the target tasks in the target queue as described above, and there is no requirement to execute them one after another.
[0114] Optionally, the electronic device can schedule a target number of target tasks from the target queue to different threads for execution, so that as many target tasks in the target queue as possible can be scheduled to threads for simultaneous execution to improve the execution efficiency of the target tasks in the target queue. The target number can include a maximum number.
[0115] Optionally, the target number may be less than or equal to a thread number threshold; wherein the thread number threshold may include: the upper limit of the number of threads that can exist simultaneously in the electronic device as described above, or other values set by the developer or user, which are not limited here. Optionally, typical values of the thread number threshold may include 8, 16 or 32, etc., which are not limited here.
[0116] By implementing the above method, the electronic device can schedule as many target tasks in the target queue as possible to threads for simultaneous execution, so as to improve the execution efficiency of the target tasks in the target queue.
[0117] 308. If the current number of existing threads is less than the thread number threshold, a new thread is created, and the first target task is scheduled to be executed in the new thread, where the first target task is any target task; and, if the current number of existing threads is equal to the thread number threshold, the first target task is scheduled to be executed in the current idle thread.
[0118] In the embodiment of the present application, the thread quantity threshold may be the upper limit of threads that can currently exist simultaneously, or the first quantity threshold, which is not limited here.
[0119] Optionally, the electronic device may schedule the target task from the serial task queue or the parallel task queue to the thread for execution through the scheduling method introduced in step 308, which is not limited here.
[0120] Optionally, when an electronic device schedules the first target task to a thread from a serial task queue or a parallel task queue, it can first determine whether the number of currently existing threads is less than a thread number threshold. If so, it means that a new thread can still be created. In this case, the electronic device can give priority to creating a new thread and schedule the first target task to be executed in the new thread. The first target task is any target task.
[0121] Optionally, if the number of currently existing threads is equal to the thread number threshold, it means that no new thread can be created at present. In this case, the electronic device can schedule the first target task to be executed in the currently existing idle thread.
[0122] By implementing the above method, the electronic device can give priority to creating a new thread, and schedule the first target task that currently needs to be scheduled to be executed in the thread to be executed in the new thread, so as to execute more tasks in parallel as much as possible without affecting other threads that are currently being executed, thereby improving the execution efficiency of the tasks; in addition, when the number of currently existing threads is equal to the thread number threshold, the currently existing idle threads can be searched, and the first target task that currently needs to be scheduled to be executed in the thread can be scheduled to be executed in the idle thread, so that the first target task can be executed as soon as possible, thereby improving the execution efficiency of the tasks.
[0123] In another optional implementation, when the electronic device schedules the first target task to a thread from a serial task queue or a parallel task queue, it can determine whether there is an idle thread at present; if so, the first target task can be preferentially scheduled to be executed in the currently existing idle thread; if not, a new thread is created and the first target task is scheduled to be executed in the new thread.
[0124] By implementing the above method, the electronic device can preferentially schedule the first target task to be executed in an idle thread to reduce the creation of new threads, thereby reducing the total number of threads. The reduction in the number of threads can reduce the memory usage of the electronic device.
[0125] By implementing the methods disclosed in the above-mentioned embodiments, when the target task information is obtained, the target task can be automatically added to the corresponding task queue for management and scheduling according to the execution order between multiple target tasks, thereby improving the convenience and efficiency of task scheduling management; in addition, the user no longer needs to pay attention to the underlying thread creation and scheduling issues, and the user only needs to input the execution order between multiple target tasks, thereby reducing the difficulty of task scheduling; and, the target task can be scheduled from the serial task queue to the thread for execution only when there are no other tasks in the serial task queue that are in the execution state or waiting for execution state, thereby avoiding the existence of two or more target tasks in the same serial task queue in the execution state at the same time, thereby ensuring that the target tasks in the serial task queue are executed in serial order and the execution order is not disrupted, thereby improving the intelligence of the method; and the electronic device can combine target tasks in multiple parallel task queues belonging to different businesses After being merged into the same target queue, the subsequent electronic device only needs to schedule the target task from the target queue, without scheduling tasks from multiple parallel task queues, thereby making it more convenient for the electronic device to schedule the target task and improving the efficiency of the electronic device in scheduling the target task; and, the target tasks with the same priority in the parallel task queue can be added to the same target queue, so that it is convenient for the electronic device to subsequently schedule the target task in the target queue to the thread corresponding to the priority for execution, and it is also convenient for the electronic device to manage the target tasks with the same priority; and, as many target tasks in the target queue as possible can be scheduled to the thread for simultaneous execution to improve the execution efficiency of the target tasks in the target queue; and, a new thread can be created first, and the first target task that currently needs to be scheduled to the thread for execution can be scheduled to the new thread for execution, so as to execute more tasks in parallel as much as possible without affecting other threads currently being executed, thereby improving the execution efficiency of the tasks.
[0126] See also Figure 6 , Figure 6 This is a flowchart of another task management method disclosed in the embodiment of the present application. Optionally, the method can be applied to various electronic devices introduced above, or other execution entities, which are not limited here. Optionally, the method can include the following steps:
[0127] 602. Obtain target task information, where the target task information includes an execution order between multiple target tasks to be executed, where the execution order includes a serial order or a parallel order.
[0128] 604. When the execution order is a serial order, multiple target tasks are added to a serial task queue, and the target tasks in the serial task queue are sequentially scheduled to the thread for execution.
[0129] 606. When the execution order is a parallel order, multiple target tasks are added to a parallel task queue, and the multiple target tasks are scheduled from the parallel task queue to different threads for execution.
[0130] In the embodiment of the present application, when the electronic device executes step 604 and step 606, the method of scheduling the target task to be executed in the thread may include:
[0131] The electronic device may schedule the first target task to be executed in a thread corresponding to the first priority according to the first priority corresponding to the first target task, where the first target task is any target task.
[0132] In an embodiment of the present application, the electronic device can create one or more threads corresponding to each priority level, and schedule the target task to be executed in the thread of the corresponding priority level according to its corresponding priority level, so that the subsequent execution process of the target task can obtain the resource allocation corresponding to its priority level, making the execution of the target task controllable.
[0133] By implementing the above method, the electronic device can schedule the target task to execute in a thread of corresponding priority according to the priority of the target task, so that the subsequent execution process of the target task can obtain resource allocation corresponding to its priority, making the execution of the target task controllable.
[0134] In an optional embodiment, the electronic device may schedule the first target task to be executed in a thread corresponding to the first priority level by:
[0135] Determine whether there is an idle thread corresponding to the first priority level at present;
[0136] If there is currently an idle thread corresponding to the first priority, the first target task is scheduled to be executed in the idle thread;
[0137] If there is no idle thread corresponding to the first priority level at present, a new thread corresponding to the first priority level is created, and the first target task is scheduled to be executed in the new thread corresponding to the first priority level.
[0138] As described above, there may be multiple threads corresponding to the first priority, that is, when the number of threads corresponding to the first priority is insufficient, a new thread corresponding to the first priority may be newly created.
[0139] By implementing the above method, the electronic device can give priority to reusing idle threads corresponding to the first priority level to reduce the number of threads corresponding to the first priority level, thereby reducing the memory space occupied by the electronic device; in addition, if there is no idle thread corresponding to the first priority level, a new thread corresponding to the first priority level can be created to meet the need to run the first target task in a timely manner, thereby improving the flexibility of the method.
[0140] 608. Determine resource scheduling parameters according to the first priority corresponding to the first target task and the running state of the target process, the target process is the process to which the thread executing the first target task belongs, and allocate resources to the thread executing the first target task according to the resource scheduling parameters.
[0141] In the embodiment of the present application, the running state of the target process can be used to reflect the priority of the thread executing the first target task to allocate resources. It should be noted that the thread is the basic scheduling unit in the process and shares the resources of the process. Optionally, the thread executing the first target task can be any thread in the target process.
[0142] Optionally, the running state of the target process may include: running scene information and / or sleep information, etc., which are not limited here. The running scene information may include: foreground running, background running, etc., and the sleep information may include: sleep state, non-sleep state, etc., which are not limited here.
[0143] Optionally, if the target process is running in the foreground and / or in a non-sleeping state, the electronic device allocates more resources to the thread executing the first target task; if the target process is running in the background and / or in a sleeping state, the electronic device allocates fewer resources to the thread executing the first target task, which is not limited here.
[0144] Optionally, the resource may include: one or more of the CPU occupancy rate, the use rights of the output / input ports, and the memory space, which are not limited here.
[0145] Optionally, the electronic device may include a resource scheduling module, and the resource scheduling module may include: a kernel of the electronic device, etc., which is not limited here.
[0146] Optionally, the electronic device may determine the resource scheduling parameters according to the first priority corresponding to the first target task and the running status of the target process through the resource scheduling module.
[0147] Optionally, the resource allocation method may include a resource allocation priority, which refers to the priority of resource allocation. The higher the resource allocation priority, the higher the priority of resource allocation. Optionally, the resource allocation priority may be determined according to a resource scheduling parameter, and the resource allocation priority may be positively correlated with the resource scheduling parameter.
[0148] Optionally, the resource allocation method may include a resource allocation quantity; optionally, the resource allocation quantity may be determined based on a resource scheduling parameter; the resource allocation quantity may be positively correlated with the resource scheduling parameter, which is not limited here.
[0149] For example, see Figure 7 , Figure 7 This is a resource allocation schematic diagram disclosed in an embodiment of the present application. Optionally, when the first target task is executed, the electronic device can select a corresponding thread according to the priority of the first target task, and send the priority of the first target task to the resource scheduling module;
[0150] In addition, the electronic device may also determine the running state of the target process according to the switching information of the target process, and send the running state of the target process to the resource scheduling module;
[0151] Then, the resource scheduling module may determine the resource scheduling parameters according to the priority of the first target task and the running state of the target process.
[0152] By implementing the above method, the electronic device can determine the resource allocation strategy of the thread executing the first target task based on the priority of the first target task and the running status of the target process, so that the resources allocated to the thread executing the first target task meet the actual usage requirements, thereby improving the intelligence of the method.
[0153] By implementing the methods disclosed in the above embodiments, when the target task information is obtained, the target task can be automatically added to the corresponding task queue for management and scheduling according to the execution order between multiple target tasks, thereby improving the convenience and efficiency of task scheduling management; in addition, the user does not need to pay attention to the underlying thread creation and scheduling issues, and the user only needs to input the execution order between multiple target tasks, thereby reducing the difficulty of task scheduling; and the electronic device can schedule the target task to the thread of the corresponding priority for execution according to the priority of the target task, so that the subsequent execution process of the target task can obtain the resource allocation corresponding to its priority, so that the execution of the target task is controllable; and the electronic device can preferentially reuse the idle thread corresponding to the first priority to reduce the number of threads corresponding to the first priority, thereby reducing the occupation of the memory space of the electronic device; in addition, if there is no idle thread corresponding to the first priority, a new thread corresponding to the first priority can be created to meet the demand of timely running the first target task, thereby improving the flexibility of the method; and the electronic device can determine the resource allocation strategy of the thread executing the first target task based on the priority of the first target task and the running state of the target process, so that the resources allocated to the thread executing the first target task meet the actual usage requirements, thereby improving the intelligence of the method.
[0154] See also Figure 8 , Figure 8 is a schematic diagram of the structure of a task management system disclosed in an embodiment of the present application. Optionally, the task management method disclosed in an embodiment of the present application can be applied to Figure 8A task management system 800 is shown.
[0155] Optionally, the task management system 800 may include an application layer 810 and a framework layer 820 ; wherein the framework layer 820 may include: an interface module 830 and a task management module 840 .
[0156] Optionally, the application layer 810 may be used to call the target interface provided by the interface module 830 to send target task information to the task management module 840, where the target task information includes the execution order between the multiple target tasks to be executed, and the execution order may include a serial order or a parallel order;
[0157] The task management module 840 is used to add multiple target tasks to the serial task queue and schedule the target tasks in the serial task queue to the thread for execution in sequence when the execution order is a serial order; or
[0158] When the execution order is a parallel order, multiple target tasks are added to a parallel task queue, and the multiple target tasks are scheduled from the parallel task queue to different threads for execution.
[0159] In one embodiment, the task management system 800 may also include a third-party interface, and the third-party interface is used to connect to a third-party application program, so that the third-party application program can also use the method, thereby expanding the use scenarios of the method.
[0160] It should be noted that Figure 8 This is just an optional example for the convenience of explanation. The task management system may also include other modules and / or units, wherein the connection between the modules and / or units may also be the same as Figure 8 Not the same, Figure 8 This should not be construed as limiting the embodiments of the present application.
[0161] See also Fig. 9 , Fig. 9 90 is a schematic diagram of a task management device disclosed in an embodiment of the present application. Optionally, the device can be applied to various electronic devices introduced above, or other execution entities, which are not limited here. Optionally, the device may include an acquisition unit 902, a first scheduling unit 904 and a second scheduling unit 906, wherein:
[0162] An acquisition unit 902 is used to acquire target task information, where the target task information includes an execution order between multiple target tasks to be executed, where the execution order includes a serial order or a parallel order;
[0163] The first scheduling unit 904 is used to add multiple target tasks to the serial task queue when the execution order is a serial order, and schedule the target tasks in the serial task queue to the thread for execution in sequence;
[0164] The second scheduling unit 906 is used to add multiple target tasks to the parallel task queue when the execution order is a parallel order, and schedule the multiple target tasks from the parallel task queue to different threads for execution.
[0165] By implementing the above-mentioned device, target task information can be obtained, wherein the target task information can include the execution order between multiple target tasks to be executed, and the execution order can include serial order or parallel order; further, when the execution order is serial order, multiple target tasks can be added to the serial task queue, and the target tasks in the serial task queue are sequentially scheduled to the thread for execution; when the execution order is parallel order, multiple target tasks are added to the parallel task queue, and multiple target tasks are scheduled from the parallel task queue to different threads for execution. It can be seen that, when the target task information is obtained, the embodiment of the present application can automatically add the target task to the corresponding task queue for management and scheduling according to the execution order between multiple target tasks, thereby improving the convenience and efficiency of task scheduling management; in addition, the user does not need to pay attention to the underlying thread creation and scheduling issues, and the user only needs to enter the execution order between multiple target tasks, thereby reducing the difficulty of task scheduling.
[0166] As an optional implementation, the first scheduling unit 904 is also used to schedule the target task ranked first in the serial task queue to be executed in the thread when there are no other tasks in the serial task queue in the execution state or the waiting execution state; and, when the execution of the first target task is completed, schedule the next target task from the serial task queue to be executed in the thread.
[0167] By implementing the above-mentioned device, the electronic device can schedule the target task from the serial task queue to the thread for execution only when there are no other tasks in the serial task queue that are in the execution state or waiting for execution state, thereby avoiding the situation where two or more target tasks are in the execution state in the same serial task queue at the same time, and further ensuring that the target tasks in the serial task queue are executed in serial order without disrupting the execution order, thereby improving the intelligence of the method.
[0168] As an optional implementation, multiple target tasks are tasks corresponding to the first business; the second scheduling unit 906 is also used to add the multiple target tasks to the parallel task queue corresponding to the first business; and, add the multiple target tasks contained in the parallel task queue corresponding to the first business to the target queue, the target queue also includes tasks in at least one parallel task queue corresponding to other businesses; and, schedule multiple tasks from the target queue to different threads for execution.
[0169] By implementing the above-mentioned device, the electronic device can merge the target tasks in multiple parallel task queues belonging to different services into the same target queue. The subsequent electronic device only needs to schedule the target task from the target queue, without scheduling tasks from multiple parallel task queues, thereby making it more convenient for the electronic device to schedule the target task and improving the efficiency of the electronic device in scheduling the target task.
[0170] As an optional implementation, the target task information also includes the priorities corresponding to each target task; the second scheduling unit 906 is also used to add the multiple target tasks contained in the parallel task queue corresponding to the first business to the target queues corresponding to the priorities of each target task, and the tasks contained in the same target queue have the same priority.
[0171] By implementing the above device, the electronic device can add target tasks with the same priority in the parallel task queue to the same target queue, thereby facilitating the electronic device to subsequently schedule the target tasks in the target queue to the thread corresponding to the priority for execution, and also facilitating the electronic device to manage the target tasks with the same priority.
[0172] As an optional implementation, the second scheduling unit 906 is further configured to schedule a target number of target tasks from the target queue to different threads for execution, where the target number is less than or equal to a thread number threshold.
[0173] By implementing the above device, the electronic device can schedule as many target tasks in the target queue as possible to threads for simultaneous execution, so as to improve the execution efficiency of the target tasks in the target queue.
[0174] As an optional implementation, Fig. 9 The device shown may also include a third scheduling unit and a fourth scheduling unit not shown in the figure, wherein:
[0175] A third scheduling unit is used to create a new thread when the number of currently existing threads is less than the thread number threshold, and schedule the first target task to be executed in the new thread, where the first target task is any target task;
[0176] The fourth scheduling unit is used to schedule the first target task to be executed in a currently existing idle thread when the number of currently existing threads is equal to the thread number threshold.
[0177] By implementing the above-mentioned device, the electronic device can give priority to creating a new thread, and schedule the first target task that currently needs to be scheduled to be executed in the thread to be executed in the new thread, so as to execute more tasks in parallel as much as possible without affecting other threads that are currently being executed, thereby improving the execution efficiency of the tasks; in addition, when the number of currently existing threads is equal to the thread number threshold, the currently existing idle threads can be searched, and the first target task that currently needs to be scheduled to be executed in the thread can be scheduled to be executed in the idle thread, so that the first target task can be executed as quickly as possible, thereby improving the execution efficiency of the tasks.
[0178] As an optional implementation, the target task information also includes the priority corresponding to each target task; Fig. 9 The device shown may also include a fifth scheduling unit not shown, wherein:
[0179] The fifth scheduling unit is used to schedule the first target task to be executed in a thread corresponding to the first priority according to the first priority corresponding to the first target task, where the first target task is any target task.
[0180] By implementing the above device, the electronic device can schedule the target task to execute in a thread of corresponding priority according to the priority of the target task, so that the subsequent execution process of the target task can obtain resource allocation corresponding to its priority, making the execution of the target task controllable.
[0181] As an optional implementation, the fifth scheduling unit is further configured to schedule the first target task to be executed in an idle thread when there is currently an idle thread corresponding to the first priority;
[0182] Furthermore, when there is no idle thread corresponding to the first priority currently, a new thread corresponding to the first priority is created, and the first target task is scheduled to be executed in the new thread corresponding to the first priority.
[0183] By implementing the above-mentioned device, the electronic device can preferentially reuse the idle threads corresponding to the first priority level to reduce the number of threads corresponding to the first priority level, thereby reducing the occupation of the memory space of the electronic device; in addition, when there is no idle thread corresponding to the first priority level, a new thread corresponding to the first priority level can be created to meet the demand of timely running the first target task, thereby improving the flexibility of the method.
[0184] As an optional implementation, Fig. 9 The device shown may also include a distribution unit (not shown), wherein:
[0185] An allocation unit is used to determine resource scheduling parameters according to the first priority corresponding to the first target task and the running status of the target process after scheduling the first target task to be executed in the thread corresponding to the first priority, where the target process is the process to which the thread executing the first target task belongs; and, according to the resource scheduling parameters, allocate resources to the thread executing the first target task.
[0186] By implementing the above device, the electronic device can determine the resource allocation strategy of the thread executing the first target task based on the priority of the first target task and the running status of the target process, so that the resources allocated to the thread executing the first target task meet the actual usage requirements, thereby improving the intelligence of the method.
[0187] As an optional implementation, the acquisition unit 902 is further configured to acquire target task information transmitted by the task originator through calling the target interface, where the task originator includes a target application program and / or a target operating system.
[0188] By implementing the above device, the target interface can provide the task sender with an interface for transmitting target task information to the electronic device, thereby facilitating the electronic device to uniformly receive and manage the target task information, and facilitating the interaction of information data between the task sender and the electronic device.
[0189] See also Fig.10 , Fig.10 Schematic diagram of the structure of an electronic device disclosed in the embodiment of the present application. Fig.10 As shown, the electronic device may include:
[0190] A memory 1001 storing executable program codes;
[0191] A processor 1002 coupled to the memory 1001;
[0192] The processor 1002 calls the executable program code stored in the memory 1001 to execute the task management method disclosed in the above embodiments.
[0193] An embodiment of the present application discloses a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to execute the task management method disclosed in the above embodiments.
[0194] The embodiments of the present application also disclose an application publishing platform, wherein the application publishing platform is used to publish a computer program product, wherein when the computer program product runs on a computer, the computer executes part or all of the steps of the method in the above method embodiments.
[0195] It should be understood that the "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. Those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required for the present application.
[0196] In the various embodiments of the present application, it should be understood that the size of the serial numbers of the above-mentioned processes does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0197] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0198] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0199] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-accessible memory. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a memory and includes several requests for a computer device (which can be a personal computer, a server or a network device, etc., specifically a processor in a computer device) to perform some or all of the steps of the above-mentioned methods of various embodiments of the present application.
[0200] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, and the storage medium includes a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable rewritable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0201] The task management method and system, device, electronic device, and storage medium disclosed in the embodiments of the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A task management method, characterized in that: The method comprises: Acquire target task information, wherein the target task information includes an execution order between multiple target tasks to be executed, wherein the execution order includes a serial order or a parallel order; When the execution order is a serial order, the multiple target tasks are added to a serial task queue, and the target tasks in the serial task queue are sequentially scheduled to threads for execution; In the case where the execution order is a parallel order, the multiple target tasks are added to a parallel task queue, and the multiple target tasks are scheduled from the parallel task queue to different threads for execution.
2. The method according to claim 1, characterized in that The step of sequentially scheduling the target tasks in the serial task queue to the threads for execution includes: If there are no other tasks in the serial task queue that are in the execution state or the waiting execution state, the target task ranked first in the serial task queue is scheduled to be executed in the thread; When the first target task is completed, the next target task is scheduled from the serial task queue to the thread for execution.
3. The method according to claim 1, characterized in that The multiple target tasks are tasks corresponding to the first business; adding the multiple target tasks to a parallel task queue, and scheduling the multiple target tasks from the parallel task queue to be executed in different threads, includes: Adding the multiple target tasks to a parallel task queue corresponding to the first business; Adding the plurality of target tasks contained in the parallel task queue corresponding to the first business to a target queue, wherein the target queue also includes tasks in at least one parallel task queue corresponding to another business; Multiple tasks are dispatched from the target queue to different threads for execution.
4. The method according to claim 3, characterized in that The target task information also includes the priority corresponding to each of the target tasks; and adding the multiple target tasks included in the parallel task queue corresponding to the first business to the target queue includes: The multiple target tasks included in the parallel task queue corresponding to the first business are respectively added to the target queues corresponding to the priorities of the target tasks, and the tasks included in the same target queue have the same priority.
5. The method according to claim 3 or 4, characterized in that: The step of scheduling multiple tasks from the target queue to different threads for execution includes: A target number of tasks is dispatched from the target queue to different threads for execution, wherein the target number is less than or equal to a thread number threshold.
6. The method according to claim 1, characterized in that The method further comprises: If the number of currently existing threads is less than the thread number threshold, a new thread is created, and a first target task is scheduled to be executed in the new thread, where the first target task is any of the target tasks; If the number of currently existing threads is equal to the thread number threshold, the first target task is scheduled to be executed in the currently existing idle thread.
7. The method according to claim 1, characterized in that The target task information also includes the priority corresponding to each of the target tasks; the method also includes: According to a first priority level corresponding to a first target task, the first target task is scheduled to be executed in a thread corresponding to the first priority level, where the first target task is any of the target tasks.
8. The method according to claim 7, characterized in that The step of scheduling the first target task to be executed in a thread corresponding to the first priority level includes: If there is currently an idle thread corresponding to the first priority, scheduling the first target task to be executed in the idle thread; If there is currently no idle thread corresponding to the first priority, a new thread corresponding to the first priority is created, and the first target task is scheduled to be executed in the new thread corresponding to the first priority.
9. The method according to claim 7 or 8, characterized in that: After scheduling the first target task to be executed in a thread corresponding to the first priority, the method further includes: determining a resource scheduling parameter according to a first priority corresponding to the first target task and a running state of a target process, wherein the target process is a process to which a thread executing the first target task belongs; According to the resource scheduling parameters, resources are allocated to the thread executing the first target task.
10. The method according to claim 1, characterized in that The obtaining of target task information includes: The target task information transmitted by the task issuing end through calling the target interface is obtained, wherein the task issuing end includes a target application program and / or a target operating system.
11. A task management system, characterized in that: The system comprises: an application layer and a framework layer, wherein the framework layer comprises an interface module and a task management module, wherein: The application layer is used to call the target interface provided by the interface module and send target task information to the task management module, wherein the target task information includes an execution order between multiple target tasks to be executed, and the execution order includes a serial order or a parallel order; The task management module is used to add the multiple target tasks to a serial task queue and schedule the target tasks in the serial task queue to the thread for execution in sequence when the execution order is a serial order; or In the case where the execution order is a parallel order, the multiple target tasks are added to a parallel task queue, and the multiple target tasks are scheduled from the parallel task queue to different threads for execution.
12. A task management device, characterized in that: The device comprises: An acquisition unit, used for acquiring target task information, wherein the target task information includes an execution order between a plurality of target tasks to be executed, wherein the execution order includes a serial order or a parallel order; A first scheduling unit, configured to add the plurality of target tasks to a serial task queue when the execution order is a serial order, and sequentially schedule the target tasks in the serial task queue to threads for execution; The second scheduling unit is used to add the multiple target tasks to a parallel task queue when the execution order is a parallel order, and schedule the multiple target tasks from the parallel task queue to different threads for execution.
13. An electronic device, characterized in that: It comprises a memory storing executable program code, and a processor coupled to the memory; wherein the processor calls the executable program code stored in the memory to execute the method according to any one of claims 1 to 10.
14. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.