Task scheduling control method and system and electronic equipment
By building a task scheduler, combining distributed locks, memory and executors, the shortcomings of existing task scheduling components in priority control and asynchronous execution are solved, and efficient task scheduling and priority management are achieved.
Patent Information
- Application Number
- CN202510772137.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-11
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-06-11
AI Technical Summary
Existing task scheduling components cannot effectively control the execution priority of scheduling tasks, cannot execute in the main thread and asynchronous thread, and cannot handle callbacks for asynchronous tasks in a unified manner.
By generating distributed lock components, task memory components and task executor components of the task operation environment, combining task priority policies and scheduling policies, a task scheduler is built, and a task scheduling sequence is determined using asynchronous thread pools and asynchronous task callback interfaces to simplify task scheduling logic.
It improves the execution efficiency of task scheduling, simplifies task calling logic, and realizes efficient scheduling and priority control of tasks.
Smart Images

Figure CN120276832A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of task scheduling, and in particular to a task scheduling control method, system and electronic device. Background Art
[0002] For back-end applications, when there are many different types of tasks to be scheduled for an application program, task scheduling components developed in Java such as Quartz, XXL-JOB, etc. are mainly used. Most of these components rely on their own data structures for scheduling, either deployed separately or integrated into the application system. However, the above components need to introduce an additional database to maintain task scheduling data, cannot effectively control the execution priority of scheduling tasks, and cannot directly drive the scheduling of step-by-step tasks; in addition, this method cannot control whether the task scheduling needs to be executed in the main thread or an asynchronous thread; at the same time, it cannot control the unified abstract processing of the callbacks of asynchronous tasks.
[0003] In summary, the components used in the task scheduling control process in the prior art still have problems such as unreasonable scheduling logic and low efficiency. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide a task scheduling control method, system and electronic device. This method simplifies the implementation process of task scheduling, aggregates various components to obtain a task scheduler, and uses the task scheduler to schedule tasks according to the task scheduling sequence, and processes them through the corresponding memory and executor, thereby simplifying the task call logic and improving the task scheduling execution efficiency.
[0005] In a first aspect, an embodiment of the present invention provides a task scheduling control method, which includes: Generating a distributed lock component, a task memory component and a task executor component for the task running environment based on the task attribute parameters of the task running environment; Determining the task priority policy and task scheduling policy of the tasks in the task running environment based on the task process parameters of the task running environment; According to the distributed lock component, the task memory component and the task executor component, and using the task priority policy and task scheduling policy to construct a task scheduler corresponding to the task; Using the task scheduler to construct an asynchronous thread pool and an asynchronous task callback interface corresponding to the task, and determining the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface; Controlling the task scheduler to execute the task scheduling process according to the task scheduling sequence.
[0006] Optionally, generate a distributed lock component, a task memory component, and a task executor component for the task running environment based on the task attribute parameters of the task running environment, including: Generate a distributed lock component corresponding to the task in the task running environment based on the process access parameter between the task and the shared resource in the task attribute parameters; Generate a task memory component corresponding to the task in the task running environment based on the task saving parameter between the task and the task container in the task attribute parameters; Generate a task executor component corresponding to the task in the task running environment based on the type parameter and the running parameter of the task in the task attribute parameters.
[0007] Optionally, generate a task executor component corresponding to the task in the task running environment based on the type parameter and the running parameter of the task in the task attribute parameters, including: Determine the direct processing task and the step-by-step processing task corresponding to the task in the task running environment according to the type parameter; Use the running parameter to determine the first task executor component corresponding to the direct processing task, and use the running parameter to determine the second task executor component corresponding to the step-by-step processing task; Generate a task executor component based on the first task executor component and the second task executor component.
[0008] Optionally, determine the task priority policy and the task scheduling policy of the task in the task running environment based on the task process parameter of the task running environment, including: Use the task process parameter to determine the task scheduling parameter of the task in the task running environment; Determine the priority parameter of the task based on the task scheduling parameter, and use the priority parameter to determine the task priority policy corresponding to the task; Determine the execution parameter of the task based on the task scheduling parameter, and use the execution parameter and the priority parameter to determine the task scheduling policy corresponding to the task.
[0009] Optionally, construct a task scheduler corresponding to the task according to the distributed lock component, the task memory component, and the task executor component, and use the task priority policy and the task scheduling policy, including: Construct a task scheduler component of the task scheduler corresponding to the task according to the distributed lock component, the task memory component, and the task executor component; Use the task scheduler component to determine the task memory and the task executor corresponding to the task under the task priority policy and the task scheduling policy; Construct a task scheduler according to the task memory and the task executor.
[0010] Optionally, construct an asynchronous thread pool and an asynchronous task callback interface corresponding to the task by using the task scheduler, including: Determine the thread scheduling parameters corresponding to the task scheduler based on the execution location parameters of the task, and construct an asynchronous thread pool corresponding to the task by using the thread scheduling parameters; wherein, the thread scheduling parameters at least include: main thread scheduling parameters, IO thread pool scheduling parameters, and CPU thread pool scheduling parameters; Determine the callback logic parameters corresponding to the task scheduler based on the task execution parameters of the task, and construct an asynchronous task callback interface corresponding to the task by using the callback logic parameters.
[0011] Optionally, determine the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface, including: Based on the asynchronous thread pool and the asynchronous task callback interface, determine the task memory and the task executor corresponding to the task in the task scheduler; After registering the task executor to the task scheduler by using the task memory, use the task scheduler to determine the task scheduling sequence corresponding to the task.
[0012] Optionally, control the scheduling process of the task scheduler to execute the task according to the task scheduling sequence, including: Use the task scheduling sequence to obtain the scheduling order parameters and the scheduling control parameters of the task; According to the scheduling execution order determined by the scheduling order parameters, use the scheduling control parameters to control the scheduling of the task.
[0013] In a second aspect, the present invention provides a task scheduling control system, and the system includes: A first initialization unit, configured to generate a distributed lock component, a task memory component, and a task executor component of the task running environment based on the task attribute parameters of the task running environment; A second initialization unit, configured to determine the task priority policy and the task scheduling policy of the task in the task running environment based on the task process parameters of the task running environment; A task scheduler generation unit, configured to construct a task scheduler corresponding to the task according to the distributed lock component, the task memory component, and the task executor component, and by using the task priority policy and the task scheduling policy; A task scheduling sequence determination unit, configured to construct an asynchronous thread pool and an asynchronous task callback interface corresponding to the task by using the task scheduler, and determine the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface; A task scheduling execution unit, configured to control the scheduling process of the task scheduler to execute the task according to the task scheduling sequence.
[0014] In a third aspect, an embodiment of the present invention further provides an electronic device, including a processor and a memory. The memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the steps of the task scheduling control method provided in the first aspect.
[0015] In a fourth aspect, an embodiment of the present invention further provides a storage medium that stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions cause the processor to implement the steps of the task scheduling control method provided in the first aspect.
[0016] A task scheduling control method, system and electronic device provided by an embodiment of the present invention, in the process of scheduling and controlling a task, the method first generates a distributed lock component, a task memory component and a task executor component of the task running environment based on the task attribute parameters of the task running environment; then determines the task priority policy and task scheduling policy of the task in the task running environment based on the task process parameters of the task running environment; then constructs a task scheduler corresponding to the task according to the distributed lock component, the task memory component and the task executor component, and uses the task priority policy and the task scheduling policy; then constructs an asynchronous thread pool and an asynchronous task callback interface corresponding to the task by using the task scheduler, and determines the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface; finally, controls the task scheduler to execute the task scheduling process according to the task scheduling sequence. This method simplifies the implementation process of task scheduling, aggregates each component to obtain a task scheduler, uses the task scheduler to schedule tasks according to the task scheduling sequence, and processes them through the corresponding memory and executor, thereby simplifying the task call logic and improving the task scheduling execution efficiency.
[0017] Other features and advantages of the present invention will be described in the following specification, and, in part, will be obvious from the specification, or will be learned by implementing the present invention. The objectives and other advantages of the present invention are achieved and obtained by the structures specifically pointed out in the specification, claims and drawings.
[0018] To make the above objectives, features and advantages of the present invention more obvious and understandable, the following specific preferred embodiments are given, and in conjunction with the accompanying drawings, the detailed description is as follows. Description of the Drawings
[0019] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for the description of the specific embodiments or the prior art. Obviously, the following drawings are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0020] Figure 1 Flowchart of a task scheduling control method provided by an embodiment of the present invention; Figure 2 Flowchart of step S101 in a task scheduling control method provided by an embodiment of the present invention; Figure 3 Flowchart of step S203 in a task scheduling control method provided by an embodiment of the present invention; Figure 4 Flowchart of step S102 in a task scheduling control method provided by an embodiment of the present invention; Figure 5 Flowchart of step S103 in a task scheduling control method provided by an embodiment of the present invention; Figure 6 Flowchart of constructing an asynchronous thread pool corresponding to a task and an asynchronous task callback interface by using a task scheduler in a task scheduling control method provided by an embodiment of the present invention; Figure 7 Flowchart of determining a task scheduling sequence corresponding to a task through an asynchronous thread pool and an asynchronous task callback interface in a task scheduling control method provided by an embodiment of the present invention; Figure 8 Flowchart of step S105 in a task scheduling control method provided by an embodiment of the present invention; Figure 9 Schematic diagram of the execution of a task scheduling component in a task scheduling control method provided by an embodiment of the present invention; Figure 10 Schematic diagram of a task scheduling control system provided by an embodiment of the present invention; Figure 11 Schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.
[0021] Icon: 1010 - First initialization unit; 1020 - Second initialization unit; 1030 - Task scheduler generation unit; 1040 - Task scheduling sequence determination unit; 1050 - Task scheduling execution unit; 101 - Processor; 102 - Memory; 103 - Bus; 104 - Communication interface. Detailed implementation manner
[0022] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below in conjunction with the embodiments. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the scope of protection of the present invention.
[0023] For back-end applications, when there are many different types of tasks to be scheduled for an application program, task scheduling components developed in Java, such as Quartz, XXL-JOB, etc., are mainly used. Most of these components rely on their own data structures for scheduling, either deployed separately or integrated into the application system. However, the above components need to additionally introduce a database to maintain task scheduling data, cannot effectively control the execution priority of scheduling tasks, nor can they directly drive the scheduling of step-by-step tasks. In addition, this method cannot control whether the task scheduling needs to be executed in the main thread or an asynchronous thread. At the same time, it cannot control the unified abstract processing of the callbacks of asynchronous tasks.
[0024] In summary, the components used in the task scheduling control process in the prior art still have problems of unreasonable scheduling logic and low efficiency. Based on this, the embodiments of the present invention provide a task scheduling control method, system, and electronic device. This method simplifies the implementation process of task scheduling, aggregates various components to obtain a task scheduler, and uses the task scheduler to schedule tasks according to the task scheduling sequence, and processes them through the corresponding memory and executor, thereby simplifying the task invocation logic and improving the task scheduling execution efficiency.
[0025] To facilitate the understanding of this embodiment, first, a task scheduling control method disclosed in the embodiments of the present invention will be introduced in detail. This method is as Figure 1 shown and includes: Step S101, generate a distributed lock component, a task memory component, and a task executor component for the task running environment based on the task attribute parameters of the task running environment; Step S102, determine the task priority policy and task scheduling policy of the tasks in the task running environment based on the task process parameters of the task running environment; Step S103, construct a task scheduler corresponding to the task according to the distributed lock component, the task memory component, and the task executor component, and use the task priority policy and task scheduling policy; Step S104, construct an asynchronous thread pool and an asynchronous task callback interface corresponding to the task by using the task scheduler, and determine the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface; Step S105, control the task scheduler to execute the task scheduling process according to the task scheduling sequence.
[0026] Specifically, the core of this method is to generate a task scheduler. During the construction of the task scheduler, it mainly involves components such as a distributed lock component, a task memory component, and a task executor component. Task priority policies and task scheduling policies are also used to construct the task scheduler. After the task scheduler is constructed, an asynchronous thread pool corresponding to the task and an asynchronous task callback interface are constructed to determine the schedulable task scheduling sequence. At this time, the task scheduler can use the task scheduling sequence to schedule the execution of the task, thereby driving the task scheduling process.
[0027] Optionally, step S101 of generating the distributed lock component, task memory component, and task executor component of the task running environment based on the task attribute parameters of the task running environment is as Figure 2 shown, and includes: Step S201: Generate a distributed lock component corresponding to the task in the task running environment based on the process access parameter between the task and the shared resource in the task attribute parameters; Step S202: Generate a task memory component corresponding to the task in the task running environment based on the task save parameter between the task and the task container in the task attribute parameters; Step S203: Generate a task executor component corresponding to the task in the task running environment based on the type parameter and running parameter of the task in the task attribute parameters.
[0028] The distributed lock component is used to ensure the granularity of task execution in the distributed task scheduling framework. A distributed lock is a lock mechanism that can span multiple processes or threads. It is used to coordinate access to shared resources in a distributed environment. The implementation of the distributed lock depends on an external state storage system, such as a database, Redis, etc., to achieve atomic exclusive operations. Specifically, the working process of the distributed lock component is as follows: Acquire the lock: When a task instance needs to access a shared resource, it first tries to acquire the lock from the distributed lock component. This is usually achieved by sending a request to the external state storage system, such as sending a SETNX command to Redis or inserting a record with a uniqueness constraint into the database.
[0029] Lock success: If the external state storage system returns a successful response, indicating that the task instance has successfully acquired the lock, it can then operate on the shared resource.
[0030] Lock failure: If the external state storage system returns a failure response, indicating that the lock has been acquired by another task instance, the task instance needs to wait or take other measures.
[0031] Releasing the lock: When a task instance finishes operating on the shared resource, it sends a request to release the lock to the distributed lock component. This is usually achieved by deleting the lock record in the external state storage system.
[0032] The implementation details are as follows: Mutual exclusion: Ensure that only one task instance can acquire the lock at the same time, avoiding conflicts caused by concurrent access.
[0033] Reliability: Ensure that the lock can be correctly released in case of exceptions such as task instance crashes or network failures, avoiding deadlock problems.
[0034] Performance: Minimize the overhead of acquiring and releasing the lock to improve the system throughput.
[0035] The task memory component is used to interact with specific task containers. Each task container is registered in this memory. The memory provides external interfaces for querying tasks to be processed, updating the interface for tasks in processing, updating the interface for completed task processing, and obtaining sub-tasks of step-by-step tasks. There is a task container set in the task memory. This set is initialized when the task memory is created, and all task containers are loaded into this task container set. The key of the set is the task number, and the value of the set is the specific task container. All methods for interacting through the memory are delegated to the specific task container for processing.
[0036] The designed task executor component is used to interact with specific task processors. Each task processor is registered in the executor. After the task scheduler obtains the task to be executed from the task memory, it hands it over to the task executor component for processing and execution.
[0037] Optionally, based on the task type parameter and operation parameter in the task attribute parameter, generate the task executor component corresponding to the task in the task running environment in step S203. As Figure 3 shown, it includes: Step S301, determine the direct processing task and step-by-step processing task corresponding to the task in the task running environment according to the type parameter; Step S302, use the operation parameter to determine the first task executor component corresponding to the direct processing task, and use the operation parameter to determine the second task executor component corresponding to the step-by-step processing task; Step S303, generate the task executor component based on the first task executor component and the second task executor component.
[0038] The task scheduler contains a set of task executors. This set is populated by registering task executor methods, with the task number as the key and the specific task executor as the value. The task executor has two implementations: the ordinary task executor and the distributed task executor, which correspond to directly processing tasks and processing tasks step by step, respectively. When the ordinary task executor receives a task, it directly processes the specific implementation. When the step-by-step task executor receives a task, it needs to further delegate the task to the sub-step task executor for implementation.
[0039] The step-by-step task executor component is a sub-component of the task executor component, mainly used for processing distributed tasks and changing the status of the main task by processing step-by-step tasks.
[0040] Optionally, step S102 of determining the task priority policy and task scheduling policy of the task in the task running environment based on the task process parameters of the task running environment, such as Figure 4 shown, includes: Step S401, using the task process parameters to determine the task scheduling parameters of the task in the task running environment; Step S402, determining the priority parameters of the task based on the task scheduling parameters, and using the priority parameters to determine the task priority policy corresponding to the task; Step S403, determining the execution parameters of the task based on the task scheduling parameters, and using the execution parameters and the priority parameters to determine the task scheduling policy corresponding to the task.
[0041] The task scheduling policy and priority policy specify an abstract task scheduling algorithm, including modes such as random, polling, and minimum failure rate. Specifically, the random mode means that when scheduling tasks, a task is randomly selected from the list of tasks to be scheduled for execution. This mode is suitable for scenarios where there are no strict priorities or dependencies between tasks. The polling mode means that tasks are scheduled for execution in a certain order (such as the order of task code registration, etc.). When the end of the list is reached, scheduling starts again from the beginning of the list. The minimum failure rate mode means that based on the historical execution records of tasks (such as the number of failures, success rate, etc.), the task with the lowest failure rate is selected for execution. This mode is suitable for scenarios where the stability of task execution needs to be considered first.
[0042] Specifically, the task priority policy can ensure that critical tasks are executed first. The specific operations of the task priority policy are as follows: Priority definition: Set an initial priority for each task type, which can be flexibly adjusted according to business logic. The priority can be an integer or an enumeration type, and the smaller the value, the higher the priority.
[0043] Priority adjustment: During operation, the system can dynamically adjust the priorities of tasks according to the actual situation. For example, when a certain task has not been completed for a long time, the system can automatically increase its priority to process it as soon as possible.
[0044] Priority scheduling: When the task scheduler schedules tasks, it sorts them according to their priorities. The task with the highest priority will be scheduled and executed first. If multiple tasks have the same priority, they will be scheduled according to the order in which the tasks arrive or according to other scheduling algorithms (such as round-robin, minimum failure rate, etc.).
[0045] Priority inheritance and transfer: For step-by-step tasks, the priorities of subtasks can be inherited from their parent tasks or set independently according to business logic. This can ensure that the priorities of the entire task chain remain consistent or be flexibly adjusted as needed.
[0046] Priority monitoring and adjustment: The system provides a priority monitoring function that allows operation personnel or maintenance personnel to monitor the priorities and execution status of tasks in real time. When necessary, they can manually adjust the priorities of tasks to ensure the stability and efficiency of the system.
[0047] The task scheduling strategy is specifically used to handle tasks that need to be executed step by step. The following is the specific operation process of the step-by-step task scheduling strategy: Step-by-step task registration: In the task memory component, step-by-step tasks are registered as special types of tasks. Each step-by-step task contains one or more subtasks, and these subtasks are executed in a preset order.
[0048] Step-by-step task acquisition: When the task scheduler needs to obtain tasks to be executed from the task memory, it checks whether there are step-by-step tasks to be processed. If there are, the task scheduler will select the most suitable step-by-step task for scheduling according to the priority and scheduling strategy of the task (such as random, round-robin, minimum failure rate, etc.).
[0049] Subtask allocation and execution: Once a step-by-step task is selected, the task scheduler will hand it over to the step-by-step task executor component for processing. The step-by-step task executor will, in accordance with the preset order, allocate subtasks to the task executor component one by one for execution.
[0050] Subtask status update and monitoring: During the execution of subtasks, the step-by-step task executor will monitor the status of subtasks in real time (such as in execution, execution successful, execution failed, etc.). Once a subtask is completed, the step-by-step task executor will update the status of the subtask and decide whether to continue executing the next subtask as needed.
[0051] Main task status change: The step-by-step task executor also changes the status of the main task according to the execution status of the subtasks. For example, when all subtasks are successfully executed, the status of the main task will be updated to "completed"; if a subtask fails, the status of the main task may be updated to "failed" or "pending retry".
[0052] Optionally, the steps S103 for constructing a task scheduler corresponding to a task according to the distributed lock component, the task memory component, and the task executor component, and using the task priority policy and the task scheduling policy are as follows Figure 5 shown, including: Step S501, constructing a task scheduler component corresponding to the task scheduler according to the distributed lock component, the task memory component, and the task executor component; Step S502, using the task scheduler component to determine the task memory and the task executor corresponding to the task under the task priority policy and the task scheduling policy; Step S503, constructing a task scheduler according to the task memory and the task executor.
[0053] During the construction of the task scheduler, a task scheduler component is first initialized, which contains the above-mentioned distributed lock component, task memory component, and task executor component; then, through this task scheduler component, the task memory container and the corresponding task executor corresponding to the task under the task priority policy and the task scheduling policy are determined, and then the task scheduler is constructed according to the task memory and the task executor.
[0054] Optionally, use the task scheduler to construct an asynchronous thread pool and an asynchronous task callback interface corresponding to the task, as follows Figure 6 shown, including: Step S601, determining the thread scheduling parameters corresponding to the task scheduler based on the execution location parameters of the task, and constructing an asynchronous thread pool corresponding to the task using the thread scheduling parameters; wherein, the thread scheduling parameters at least include: main thread scheduling parameters, IO thread pool scheduling parameters, and CPU thread pool scheduling parameters; Step S602, determining the callback logic parameters corresponding to the task scheduler based on the task execution parameters of the task, and constructing an asynchronous task callback interface corresponding to the task using the callback logic parameters.
[0055] By marking task scheduling attributes, an asynchronous thread pool is designed, which involves CPU-intensive tasks, IO-intensive tasks, etc. The task scheduling attribute specifically refers to an execution location of a task. Currently, the scheduler provides three attribute marks for the business side to choose from, namely: main thread scheduling, IO thread pool scheduling, and CPU thread pool scheduling. These three attributes are determined by the business side according to its own task execution requirements. For example, if a task is executed quickly and does not depend on other computing data or file database resources, main thread scheduling can be selected; if it depends on a large amount of files or database resources, an IO-intensive task can be selected and executed by the IO thread pool; if it depends on a large amount of computing data (such as statistical data calculation), a CPU-intensive task can be selected and executed by the CPU thread pool.
[0056] CPU-intensive task thread pool: mainly used to execute compute-intensive tasks, which usually require a large amount of CPU resources. By allocating an independent thread pool for such tasks, it can ensure that they can obtain sufficient CPU time, thereby improving execution efficiency.
[0057] IO-intensive task thread pool: mainly used to execute IO-intensive tasks, which usually involve a large number of file reads and writes, network transmissions, etc. Allocating an independent thread pool for such tasks can optimize the concurrency of IO operations and reduce waiting time.
[0058] Thread pool configuration: According to the actual requirements and resource conditions of the system, reasonably configure parameters such as the size of the thread pool, the number of core threads, the maximum number of threads, and the queue size. Set different thread pool parameters for different types of tasks to better meet their execution requirements. For example, the number of core threads in the CPU-intensive task thread pool should preferably meet the principle of the number of machine cores + 1, and the number of core threads in the IO-intensive task thread pool can adopt the principle of the number of machine cores * 2.
[0059] When certain types of tasks are being executed, the results cannot be directly obtained (such as the SMS sending result receipt). Therefore, the callback logic parameters corresponding to the task scheduler can be determined based on the task execution parameters of the task, and an asynchronous task callback interface corresponding to the task can be constructed using the callback logic parameters. The task processor implements the callback interface to wait for the callback and process it, thereby driving the task to be truly completed.
[0060] Optionally, determine the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface, as Figure 7 shown, including: Step S701, based on the asynchronous thread pool and the asynchronous task callback interface, determine the task memory and task executor corresponding to the task in the task scheduler; Step S702, after registering the task executor to the task scheduler using the task memory, use the task scheduler to determine the task scheduling sequence corresponding to the task.
[0061] The asynchronous task callback interface is used to handle the callback logic after the completion of an asynchronous task. This callback interface allows task developers to perform specific subsequent operations or processing logic after the task execution is completed. Specifically, the asynchronous task callback interface is defined as a general interface, and task developers need to implement this interface and provide their own callback processing logic. When the asynchronous task is completed, the task scheduler will automatically call this callback interface and pass the result of the task execution or other relevant information to the task developer for subsequent processing.
[0062] Optionally, step S105 of controlling the task scheduler to execute the task scheduling process according to the task scheduling sequence is as follows Figure 8 shown, including: Step S801, obtaining the scheduling order parameter and the scheduling control parameter of the task by using the task scheduling sequence; Step S802, controlling the task scheduling by using the scheduling control parameter according to the scheduling execution order determined by the scheduling order parameter.
[0063] By implementing the task memory container and the task executor provided by the task scheduler and registering the task executor into the task scheduler, a schedulable task series is obtained. By using the task scheduling sequence to obtain the scheduling order parameter and the scheduling control parameter of the task, and then according to the scheduling execution order determined by the scheduling order parameter, the scheduling control parameter is used to control the task scheduling. At this time, the task scheduler can schedule the execution of this task series, thereby driving the execution of the task.
[0064] As Figure 9 shown in the schematic diagram of the task scheduling component execution in a task scheduling control method Figure 9 There is a task container set in the task memory in, which is initialized when the task memory is created. All task containers are loaded into this task container combination. The key of the set is the task number, and the value of the set is the specific task container. All methods interacting through the memory are delegated to the specific task container for processing.
[0065] In addition, Figure 9 it can be seen from that there is a task executor set in the task scheduler, which is put into the task executor set by registering the task executor method. The key of the set is the task number, and the value of the set is the specific task executor. The task executor includes two implementations, namely the ordinary task executor and the distributed task executor. The ordinary task executor directly processes the specific implementation after receiving the task; after receiving the task, the step-by-step task executor needs to further delegate the task to the step-by-step sub-task executor for implementation.
[0066] As can be seen from the task scheduling control method described in the above embodiments, this method simplifies the implementation process of task scheduling. After aggregating each component, a task scheduler is obtained. The task scheduler is used to schedule tasks according to the task scheduling sequence and process them through the corresponding memory and executor, thereby simplifying the task invocation logic and improving the task scheduling execution efficiency.
[0067] Corresponding to the task scheduling control method provided in the foregoing embodiments, an embodiment of the present invention provides a task scheduling control system, as Figure 10 shown. The system includes: A first initialization unit 1010, configured to generate a distributed lock component, a task memory component, and a task executor component of the task running environment based on the task attribute parameters of the task running environment; A second initialization unit 1020, configured to determine the task priority policy and task scheduling policy of the tasks in the task running environment based on the task process parameters of the task running environment; A task scheduler generation unit 1030, configured to construct a task scheduler corresponding to the task according to the distributed lock component, the task memory component, and the task executor component, and using the task priority policy and the task scheduling policy; A task scheduling sequence determination unit 1040, configured to construct an asynchronous thread pool and an asynchronous task callback interface corresponding to the task by using the task scheduler, and determine the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface; A task scheduling execution unit 1050, configured to control the task scheduler to execute the task scheduling process according to the task scheduling sequence.
[0068] As can be seen from the task scheduling control system described in the above embodiments, this system simplifies the implementation process of task scheduling. After aggregating each component, a task scheduler is obtained. The task scheduler is used to schedule tasks according to the task scheduling sequence and process them through the corresponding memory and executor, thereby simplifying the task invocation logic and improving the task scheduling execution efficiency.
[0069] The implementation principle and the technical effects generated by the task scheduling control system provided in the embodiments of the present invention are the same as those of the foregoing embodiments of the task scheduling control method. For the sake of brief description, for the parts not mentioned in the device embodiment, reference may be made to the corresponding content in the foregoing embodiments of the task scheduling control method.
[0070] This embodiment also provides an electronic device. The structural schematic diagram of the electronic device is as Figure 11 shown. The device includes a processor 101 and a memory 102. Among them, the memory 102 is used to store one or more computer instructions, and the one or more computer instructions are executed by the processor to implement the steps of the above task scheduling control method.
[0071] Figure 11 The electronic device shown also includes a bus 103 and a communication interface 104. The processor 101, the communication interface 104, and the memory 102 are connected through the bus 103.
[0072] Among them, the memory 102 may include a high-speed random access memory (RAM, Random Access Memory), and may also include a non-volatile memory, such as at least one disk memory. The bus 103 may be an ISA bus, a PCI bus, an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, Figure 11 only a bidirectional arrow is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0073] The communication interface 104 is used to connect to at least one user terminal and other network units through a network interface, and send the encapsulated IPv4 packet or IPv4 packet to the user terminal through the network interface.
[0074] The processor 101 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit in the hardware of the processor 101 or the instructions in software form. The above-mentioned processor 101 may be a general-purpose processor, including a central processing unit (Central Processing Unit, abbreviated as CPU), a network processor (Network Processor, abbreviated as NP), etc.; it may also be a digital signal processor (Digital Signal Processor, abbreviated as DSP), an application specific integrated circuit (Application Specific Integrated Circuit, abbreviated as ASIC), a field programmable gate array (Field-Programmable Gate Array, abbreviated as FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present disclosure. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present disclosure can be directly embodied as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module may be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. This storage medium is located in the memory 102, and the processor 101 reads the information in the memory 102 and combines its hardware to complete the steps of the method in the foregoing embodiments.
[0075] An embodiment of the present invention also provides a storage medium, on which a computer program is stored. When the computer program is run by a processor, it executes the steps of the task scheduling control method in the foregoing embodiment.
[0076] In several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For another example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
[0077] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0078] In addition, each functional unit in various embodiments of the present invention may be integrated in one processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.
[0079] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a non-volatile computer-readable storage medium executable by a processor. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.
[0080] Finally, it should be noted that the above-described embodiments are only specific embodiments of the present invention, used to illustrate the technical solutions of the present invention, rather than limiting it. The protection scope of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that any person skilled in the art within the technical scope disclosed by the present invention can still modify the technical solutions recorded in the foregoing embodiments, or can easily think of changes, or make equivalent replacements for some of the technical features; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A task scheduling control method, characterized in that, The method includes: Generating a distributed lock component, a task memory component, and a task executor component of the task running environment based on task attribute parameters of the task running environment; Determining a task priority policy and a task scheduling policy of a task in the task running environment based on task flow parameters of the task running environment; Constructing a task scheduler corresponding to the task according to the distributed lock component, the task memory component, and the task executor component, and using the task priority policy and the task scheduling policy; Constructing an asynchronous thread pool and an asynchronous task callback interface corresponding to the task by using the task scheduler, and determining a task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface; Controlling the task scheduler to execute the scheduling process of the task according to the task scheduling sequence.
2. The task scheduling control method according to claim 1, wherein Generating a distributed lock component, a task memory component, and a task executor component of the task running environment based on task attribute parameters of the task running environment, including: Generating the distributed lock component corresponding to the task in the task running environment based on the process access parameter between the task and the shared resource in the task attribute parameters; Generating the task memory component corresponding to the task in the task running environment based on the task saving parameter between the task and the task container in the task attribute parameters; Generating the task executor component corresponding to the task in the task running environment based on the type parameter and the running parameter of the task in the task attribute parameters.
3. The task scheduling control method according to claim 2, wherein, Generating the task executor component corresponding to the task in the task running environment based on the type parameter and the running parameter of the task in the task attribute parameters, including: Determining a direct processing task and a step-by-step processing task corresponding to the task in the task running environment according to the type parameter; Determining a first task executor component corresponding to the direct processing task by using the running parameter, and determining a second task executor component corresponding to the step-by-step processing task by using the running parameter; Generating the task executor component based on the first task executor component and the second task executor component.
4. The task scheduling control method according to claim 1, wherein Determining a task priority policy and a task scheduling policy of a task in the task running environment based on task flow parameters of the task running environment, including: Determining task scheduling parameters of the task in the task running environment by using the task flow parameters; Determining a priority parameter of the task based on the task scheduling parameters, and determining the task priority policy corresponding to the task by using the priority parameter; Determining execution parameters of the task based on the task scheduling parameters, and determining the task scheduling policy corresponding to the task by using the execution parameters and the priority parameter.
5. The task scheduling control method according to claim 1, characterized in that Constructing a task scheduler corresponding to the task according to the distributed lock component, the task memory component, and the task executor component, and using the task priority policy and the task scheduling policy, including: Construct the task scheduler component corresponding to the task scheduler based on the distributed lock component, the task memory component, and the task executor component; Use the task scheduler component to determine the task memory and task executor corresponding to the task under the task priority policy and the task scheduling policy; Construct the task scheduler according to the task memory and the task executor; 6. The task scheduling control method according to claim 1, characterized in that, Use the task scheduler to construct the asynchronous thread pool and asynchronous task callback interface corresponding to the task, including: Determine the thread scheduling parameters corresponding to the task scheduler based on the execution location parameter of the task, and use the thread scheduling parameters to construct the asynchronous thread pool corresponding to the task; wherein, the thread scheduling parameters at least include: main thread scheduling parameters, IO thread pool scheduling parameters, and CPU thread pool scheduling parameters; Determine the callback logic parameters corresponding to the task scheduler based on the task execution parameter of the task, and use the callback logic parameters to construct the asynchronous task callback interface corresponding to the task; 7. The task scheduling control method according to claim 1, wherein Determine the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface, including: Based on the asynchronous thread pool and the asynchronous task callback interface, determine the task memory and task executor corresponding to the task in the task scheduler; After registering the task executor to the task scheduler using the task memory, use the task scheduler to determine the task scheduling sequence corresponding to the task; 8. The task scheduling control method according to claim 1, wherein Control the task scheduler to execute the scheduling process of the task according to the task scheduling sequence, including: Use the task scheduling sequence to obtain the scheduling order parameter and scheduling control parameter of the task; According to the scheduling execution order determined by the scheduling order parameter, use the scheduling control parameter to control the scheduling of the task; 9. A task scheduling control system, characterized in that, The system includes: A first initialization unit for generating a distributed lock component, a task memory component, and a task executor component of the task running environment based on the task attribute parameters of the task running environment; A second initialization unit for determining the task priority policy and task scheduling policy of the tasks in the task running environment based on the task flow parameters of the task running environment; A task scheduler generation unit for constructing the task scheduler corresponding to the task according to the distributed lock component, the task memory component, and the task executor component, and using the task priority policy and the task scheduling policy; A task scheduling sequence determination unit for using the task scheduler to construct the asynchronous thread pool and asynchronous task callback interface corresponding to the task, and determining the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface; A task scheduling execution unit for controlling the task scheduler to execute the scheduling process of the task according to the task scheduling sequence.
10. An electronic device, characterized in that, It includes a processor and a memory, and the memory stores computer-executable instructions that can be executed by the processor. The processor executes the computer-executable instructions to implement the steps of the task scheduling control method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Distributed scheduling system architecture and micro-service workflow scheduling method
CN113535362A
Task scheduling method applied to hybrid cloud environment
CN119987963A
Scalable transaction manager for distributed databases
US20220391382A1
Task Scheduling Based on Component Margins
US20240403121A1