Task scheduling control method, system and electronic equipment
By generating distributed lock components, task storage components and task executor components, a task scheduler is constructed, which solves the problem in the existing technology that the task scheduling component cannot effectively control the task execution priority and location, and realizes efficient and flexible task scheduling.
Patent Information
- Application Number
- CN202510772137.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-11
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2045-06-11
AI Technical Summary
The task scheduling component in the prior art requires the introduction of an additional database to maintain task scheduling data, cannot effectively control the execution priority and position of the scheduled tasks, and cannot directly drive the scheduling of step-by-step tasks.
By generating distributed lock components, task storage components and task executor components, building a task scheduler based on task attribute parameters and process parameters, and using asynchronous thread pools and asynchronous task callback interfaces to determine the task scheduling sequence, the task scheduling logic is simplified and execution efficiency is improved.
It simplifies the implementation process of task scheduling, improves the efficiency and flexibility of task scheduling, can effectively control the execution priority and location of tasks, and supports the scheduling of step-by-step tasks.
Smart Images

Figure CN120276832B_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 equipment. Background Art
[0002] For back-end applications that require scheduling of many different types of tasks, Java-developed task scheduling components such as Quartz and XXL-JOB are primarily used. These components often rely on their own data structures for scheduling and are either deployed independently or integrated into the application system. However, these components require the use of a database to maintain task scheduling data, which prevents effective control of the execution priority of scheduled tasks and cannot directly drive the scheduling of sub-tasks. Furthermore, this approach cannot control the execution of tasks in the main thread or asynchronous threads during scheduling. Furthermore, it lacks the ability to implement unified and abstract callback processing for 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, which simplifies the implementation process of task scheduling, aggregates the components 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 calling 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, the method comprising:
[0006] Generate a distributed lock component, a task storage component, and a task executor component of the task running environment based on the task attribute parameters of the task running environment;
[0007] Determine the task priority strategy and task scheduling strategy for tasks in the task running environment based on the task process parameters of the task running environment;
[0008] Based on the distributed lock component, task storage component and task executor component, and using the task priority strategy and task scheduling strategy, a task scheduler corresponding to the task is constructed;
[0009] Use the task scheduler to build the asynchronous thread pool and asynchronous task callback interface corresponding to the task, and determine the task scheduling sequence corresponding to the task through the asynchronous thread pool and asynchronous task callback interface;
[0010] Control the scheduling process of the task scheduler to execute tasks according to the task scheduling sequence.
[0011] Optionally, based on the task attribute parameters of the task execution environment, a distributed lock component, a task storage component, and a task executor component of the task execution environment are generated, including:
[0012] Generate a distributed lock component corresponding to the task in the task running environment based on the process access parameters between the task and the shared resource in the task attribute parameters;
[0013] Generate a task storage component corresponding to the task in the task running environment based on the task storage parameters between the task and the task container in the task attribute parameters;
[0014] Generate a task executor component corresponding to the task in the task running environment based on the task type parameter and running parameters in the task attribute parameters.
[0015] Optionally, based on the task type parameters and running parameters in the task attribute parameters, a task executor component corresponding to the task in the task running environment is generated, including:
[0016] 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;
[0017] Determine a first task executor component corresponding to the direct processing task using the operating parameters, and determine a second task executor component corresponding to the step-by-step processing task using the operating parameters;
[0018] A task executor component is generated based on the first task executor component and the second task executor component.
[0019] Optionally, based on the task process parameters of the task running environment, a task priority strategy and a task scheduling strategy for the task in the task running environment are determined, including:
[0020] Determine the task scheduling parameters of the task in the task running environment using the task process parameters;
[0021] Determine the priority parameters of the task based on the task scheduling parameters, and use the priority parameters to determine the task priority strategy corresponding to the task;
[0022] The execution parameters of the task are determined based on the task scheduling parameters, and the task scheduling strategy corresponding to the task is determined using the execution parameters and priority parameters.
[0023] Optionally, a task scheduler corresponding to the task is constructed based on the distributed lock component, the task storage component, and the task executor component, and using the task priority strategy and the task scheduling strategy, including:
[0024] Construct a task scheduler component corresponding to the task scheduler according to the distributed lock component, the task storage component and the task executor component;
[0025] Using the task scheduler component to determine the task memory and task executor corresponding to the task under the task priority strategy and task scheduling strategy;
[0026] Build a task scheduler based on the task storage and task executor.
[0027] Optionally, use the task scheduler to build the asynchronous thread pool and asynchronous task callback interface corresponding to the task, including:
[0028] Determine thread scheduling parameters corresponding to the task scheduler based on the execution location parameters of the task, and use the thread scheduling parameters to build an asynchronous thread pool corresponding to the task; wherein the thread scheduling parameters include at least: main thread scheduling parameters, IO thread pool scheduling parameters and CPU thread pool scheduling parameters;
[0029] The callback logic parameters corresponding to the task scheduler are determined based on the task execution parameters of the task, and the callback logic parameters are used to construct the asynchronous task callback interface corresponding to the task.
[0030] Optionally, the task scheduling sequence corresponding to the task is determined through the asynchronous thread pool and the asynchronous task callback interface, including:
[0031] Based on the asynchronous thread pool and asynchronous task callback interface, determine the task storage and task executor corresponding to the task in the task scheduler;
[0032] After the task executor is registered with the task scheduler using the task memory, the task scheduler is used to determine the task scheduling sequence corresponding to the task.
[0033] Optionally, the scheduling process of controlling the task scheduler to execute tasks according to the task scheduling sequence includes:
[0034] Use the task scheduling sequence to obtain the task scheduling sequence parameters and scheduling control parameters;
[0035] The scheduling control parameters are used to control the tasks for scheduling according to the scheduling execution order determined by the scheduling sequence parameters.
[0036] In a second aspect, the present invention provides a task scheduling control system, the system comprising:
[0037] A first initialization unit is used to generate a distributed lock component, a task storage component, and a task executor component of the task execution environment based on the task attribute parameters of the task execution environment;
[0038] A second initialization unit is used to determine a task priority strategy and a task scheduling strategy for the task in the task running environment based on the task flow parameters of the task running environment;
[0039] A task scheduler generation unit is used to build a task scheduler corresponding to the task based on the distributed lock component, the task storage component and the task executor component, and using the task priority strategy and the task scheduling strategy;
[0040] The task scheduling sequence determination unit is used to use the task scheduler to build an asynchronous thread pool and an asynchronous task callback interface corresponding to the task, and determine the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface;
[0041] The task scheduling execution unit is used to control the scheduling process of the task scheduler to execute tasks according to the task scheduling sequence.
[0042] In a third aspect, an embodiment of the present invention further provides an electronic device comprising a processor and a memory, wherein 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.
[0043] In a fourth aspect, an embodiment of the present invention further provides a storage medium storing computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the steps of the task scheduling control method provided in the first aspect.
[0044] The present invention provides a task scheduling control method, system and electronic device. In the process of scheduling and controlling tasks, 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 strategy and task scheduling strategy of the task in the task running environment based on the task flow parameters of the task running environment; then constructs a task scheduler corresponding to the task based on the distributed lock component, the task memory component and the task executor component, and uses the task priority strategy and the task scheduling strategy; then uses the task scheduler to construct an asynchronous thread pool and an asynchronous task callback interface corresponding to the task, 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 according to the task scheduling sequence. The method simplifies the implementation process of task scheduling, aggregates the components to obtain a task scheduler, uses the task scheduler to schedule tasks according to the task scheduling sequence, and processes the tasks through the corresponding memory and executor, thereby simplifying the task call logic and improving the efficiency of task scheduling execution.
[0045] Other features and advantages of the present invention will be described in the following description, and in part will become apparent from the description, or understood by practicing the present invention. The purposes and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0046] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0048] Figure 1 A flowchart of a task scheduling control method provided by an embodiment of the present invention;
[0049] Figure 2 A flowchart of step S101 in a task scheduling control method provided by an embodiment of the present invention;
[0050] Figure 3 A flowchart of step S203 in a task scheduling control method provided by an embodiment of the present invention;
[0051] Figure 4 A flowchart of step S102 in a task scheduling control method provided by an embodiment of the present invention;
[0052] Figure 5 A flowchart of step S103 in a task scheduling control method provided by an embodiment of the present invention;
[0053] Figure 6 A flowchart of a task scheduling control method provided in an embodiment of the present invention, using a task scheduler to construct an asynchronous thread pool corresponding to a task and an asynchronous task callback interface;
[0054] Figure 7 A flowchart of a task scheduling control method provided in an embodiment of the present invention, in which a task scheduling sequence corresponding to a task is determined through an asynchronous thread pool and an asynchronous task callback interface;
[0055] Figure 8 A flowchart of step S105 in a task scheduling control method provided by an embodiment of the present invention;
[0056] Figure 9A schematic diagram of executing a task scheduling component in a task scheduling control method provided by an embodiment of the present invention;
[0057] Figure 10 A schematic diagram of a task scheduling control system provided by an embodiment of the present invention;
[0058] Figure 11 A schematic structural diagram of an electronic device provided by an embodiment of the present invention.
[0059] icon:
[0060] 1010 - first initialization unit; 1020 - second initialization unit; 1030 - task scheduler generation unit; 1040 - task scheduling sequence determination unit; 1050 - task scheduling execution unit;
[0061] 101 - processor; 102 - memory; 103 - bus; 104 - communication interface. DETAILED DESCRIPTION
[0062] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0063] For back-end applications that require scheduling of many different types of tasks, Java-developed task scheduling components such as Quartz and XXL-JOB are primarily used. These components often rely on their own data structures for scheduling and are either deployed independently or integrated into the application system. However, these components require the use of a database to maintain task scheduling data, which prevents effective control of the execution priority of scheduled tasks and cannot directly drive the scheduling of sub-tasks. Furthermore, this approach cannot control the execution of tasks in the main thread or asynchronous threads during scheduling. Furthermore, it lacks the ability to implement unified and abstract callback processing for asynchronous tasks.
[0064] In summary, the components used in the task scheduling control process in the prior art still have problems with irrational scheduling logic and low efficiency. Based on this, the present invention implements a task scheduling control method, system, and electronic device. This method simplifies the implementation process of task scheduling, aggregates the various components to obtain a task scheduler, and uses the task scheduler to schedule tasks according to the task scheduling sequence. The tasks are processed through the corresponding memory and executor, thereby simplifying the task call logic and improving the task scheduling execution efficiency.
[0065] To facilitate understanding of this embodiment, a task scheduling control method disclosed in an embodiment of the present invention is first described in detail. Figure 1 Shown, including:
[0066] Step S101, generating a distributed lock component, a task storage component, and a task executor component of the task execution environment based on task attribute parameters of the task execution environment;
[0067] Step S102, determining a task priority strategy and a task scheduling strategy for the task in the task running environment based on the task flow parameters of the task running environment;
[0068] Step S103: constructing a task scheduler corresponding to the task based on the distributed lock component, the task storage component, and the task executor component, and using the task priority strategy and the task scheduling strategy;
[0069] Step S104: Utilize the task scheduler to construct an asynchronous thread pool and an asynchronous task callback interface corresponding to the task, and determine the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface;
[0070] Step S105 , controlling the task scheduler to execute the task scheduling process according to the task scheduling sequence.
[0071] Specifically, the core of this method is to generate a task scheduler. The construction of this task scheduler primarily involves a distributed lock component, a task storage component, and a task executor component. It also utilizes task priority and scheduling strategies to build the task scheduler. Once the task scheduler is built, it determines the schedulable task scheduling sequence by constructing the asynchronous thread pool corresponding to the task and the asynchronous task callback interface. The task scheduler then uses this task scheduling sequence to schedule the execution of the task, thereby driving the task scheduling process.
[0072] Optionally, based on the task attribute parameters of the task execution environment, a distributed lock component, a task storage component and a task executor component of the task execution environment are generated in step S101, such as Figure 2 Shown, including:
[0073] Step S201: generating a distributed lock component corresponding to the task in the task execution environment based on the process access parameters between the task and the shared resource in the task attribute parameters;
[0074] Step S202: generating a task storage component corresponding to the task in the task execution environment based on the task storage parameters between the task and the task container in the task attribute parameters;
[0075] Step S203 : generating 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.
[0076] The distributed lock component is used to ensure the granularity of task execution within a distributed task scheduling framework. A distributed lock is a locking mechanism that can span multiple processes or threads and is used to coordinate access to shared resources in a distributed environment. Distributed locks rely on external state storage systems, such as databases and Redis, to achieve atomic and exclusive operations. Specifically, the distributed lock component's workflow is as follows:
[0077] Acquiring a lock: When a task instance needs to access a shared resource, it first attempts to acquire a lock from the distributed lock component. This is usually achieved by sending a request to an external state storage system, such as sending a SETNX command to Redis or inserting a unique constraint record into a database.
[0078] Lock success: If the external state storage system returns a success response, it means that the task instance has successfully acquired the lock and can now operate on the shared resource.
[0079] Lock failure: If the external state storage system returns a failure response, it means that the lock has been acquired by another task instance. At this time, the task instance needs to wait or take other measures.
[0080] Release the lock: When a task instance completes its operation on a shared resource, it sends a request to the distributed lock component to release the lock. This is usually achieved by deleting the lock record in the external state storage system.
[0081] The implementation details are as follows:
[0082] Mutual Exclusion: Ensures that only one task instance can acquire the lock at a time to avoid conflicts caused by concurrent access.
[0083] Reliability: Ensure that the lock is released correctly in abnormal situations such as task instance crashes or network failures to avoid deadlock problems.
[0084] Performance: Minimize the overhead of acquiring and releasing locks to improve system throughput.
[0085] The task storage component is used to interact with specific task containers. Each task container is registered in the storage. The storage provides an interface for querying pending tasks, updating the task processing interface, updating the task processing completion interface, and obtaining the subtask interface of the step-by-step task.
[0086] There is a task container set in the task storage. This set is initialized when the task storage is created. 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 of interacting with the storage are delegated to the specific task container for processing.
[0087] The task executor component is designed to deal with specific task processors. Each task processor is registered in the executor. After the task scheduler obtains the tasks to be executed from the task memory, it is handed over to the task executor component for processing and execution.
[0088] Optionally, based on the type parameter and the running parameter of the task in the task attribute parameter, a task executor component corresponding to the task in the task running environment is generated in step S203, such as Figure 3 As shown, including:
[0089] Step S301, determining 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;
[0090] Step S302, using the operating parameters to determine the first task executor component corresponding to the direct processing task, and using the operating parameters to determine the second task executor component corresponding to the step-by-step processing task;
[0091] Step S303: Generate a task executor component based on the first task executor component and the second task executor component.
[0092] The task scheduler contains a collection of task executors. This collection is created by registering task executors. The key is the task ID, and the value is the specific task executor. Task executors include two implementations: a standard task executor and a distributed task executor, corresponding to direct task processing and step-by-step task processing, respectively. Upon receiving a task, a standard task executor directly handles the specific implementation; a distributed task executor delegates the task to a sub-task executor implementation.
[0093] The step-by-step task executor component is a subcomponent of the task executor component. It is mainly used to process distributed tasks and change the status of the main task by processing the step-by-step tasks.
[0094] Optionally, based on the task flow parameters of the task execution environment, step S102 of determining the task priority strategy and task scheduling strategy of the task in the task execution environment is as follows: Figure 4 As shown, including:
[0095] Step S401, determining task scheduling parameters of a task in a task running environment using task flow parameters;
[0096] Step S402, determining a priority parameter of the task based on the task scheduling parameter, and determining a task priority strategy corresponding to the task using the priority parameter;
[0097] Step S403 : determining the execution parameters of the task based on the task scheduling parameters, and determining the task scheduling policy corresponding to the task using the execution parameters and the priority parameters.
[0098] The task scheduling strategy and priority strategy specify a set of abstract task scheduling algorithms, including random, round-robin, and minimum failure rate modes. Specifically, the random mode means that when scheduling a task, a task is randomly selected from the list of tasks to be scheduled for execution. This mode is suitable for scenarios where there is no strict priority or dependency between tasks. The round-robin mode means that tasks are scheduled for execution in a certain order (such as the order in which the task codes are registered). When the end of the list is reached, scheduling will restart from the beginning of the list. The minimum failure rate mode means that based on the historical execution records of the task (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 prioritized.
[0099] Specifically, the task priority strategy can ensure that critical tasks are executed first. The specific operations of the task priority strategy are as follows:
[0100] Priority definition: Set an initial priority for each task type. This priority can be flexibly adjusted based on business logic. Priority can be an integer or enumeration type, with smaller values indicating higher priority.
[0101] Priority Adjustment: During operation, the system can dynamically adjust the priority of tasks based on actual conditions. For example, if a task has not been completed for a long time, the system can automatically increase its priority so that it can be processed as soon as possible.
[0102] Priority Scheduling: When scheduling tasks, the task scheduler sorts them by priority. The highest-priority task is scheduled first. If multiple tasks have the same priority, they are scheduled in the order they arrive or according to other scheduling algorithms (such as round-robin or minimum failure rate).
[0103] Priority inheritance and transfer: For step-by-step tasks, the priority of subtasks can be inherited from their parent tasks or set independently based on business logic. This ensures that the priority of the entire task chain remains consistent or can be flexibly adjusted as needed.
[0104] Priority Monitoring and Adjustment: The system provides a priority monitoring feature, allowing operations personnel or maintenance personnel to monitor the priority and execution status of tasks in real time. When necessary, they can manually adjust the priority of tasks to ensure system stability and efficiency.
[0105] The task scheduling strategy is specifically designed 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:
[0106] Step-by-step task registration: In the task storage component, step-by-step tasks are registered as special types of tasks. Each step-by-step task contains one or more subtasks, which are executed in a preset order.
[0107] Step-by-step task retrieval: When the task scheduler needs to retrieve a pending task from the task storage, it checks whether there are any step-by-step tasks to process. If so, the task scheduler selects the most appropriate step-by-step task for scheduling based on the task's priority and the scheduling strategy (e.g., random, round-robin, minimum failure rate, etc.).
[0108] Subtask assignment and execution: Once a subtask is selected, the task scheduler will hand it over to the subtask executor component for processing. The subtask executor will assign the subtasks to the task executor components one by one for execution in the preset order.
[0109] Subtask status update and monitoring: During subtask execution, the step-by-step task executor monitors the subtask status (e.g., in progress, successful, failed, etc.) in real time. Once a subtask is completed, the step-by-step task executor updates the subtask status and decides whether to proceed to the next subtask as needed.
[0110] Main Task Status Changes: The step-by-step task executor also changes the status of the main task based on the execution status of its subtasks. For example, when all subtasks are successfully completed, the main task's status is updated to "Completed." If a subtask fails, the main task's status may be updated to "Failed" or "Waiting for Retry."
[0111] Optionally, according to the distributed lock component, the task storage component and the task executor component, and using the task priority strategy and the task scheduling strategy, a task scheduler corresponding to the task is constructed in step S103, such as Figure 5 As shown, including:
[0112] Step S501: construct a task scheduler component corresponding to the task scheduler according to the distributed lock component, the task storage component, and the task executor component;
[0113] Step S502, using the task scheduler component to determine the task memory and task executor corresponding to the task under the task priority policy and task scheduling policy;
[0114] Step S503: construct a task scheduler according to the task memory and the task executor.
[0115] During the construction of the task scheduler, a task scheduler component is first initialized, which includes the above-mentioned distributed lock component, task memory component and task executor component; then, the task scheduler component is used to determine the task memory container and the corresponding task executor corresponding to the task under the task priority strategy and task scheduling strategy, and then the task scheduler is constructed based on the task memory and task executor.
[0116] Optionally, use the task scheduler to build the asynchronous thread pool and asynchronous task callback interface corresponding to the task, such as Figure 6 Shown, including:
[0117] Step S601: determining 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 include at least: main thread scheduling parameters, IO thread pool scheduling parameters, and CPU thread pool scheduling parameters;
[0118] Step S602 : determining 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.
[0119] By marking the task scheduling attributes, an asynchronous thread pool can be designed, involving CPU-type tasks and IO-type tasks. The task scheduling attribute specifically refers to an execution location of a task. Currently, the scheduler provides three attribute tags for the business party to choose from, namely: main thread scheduling, IO thread pool scheduling, and CPU thread pool scheduling. These three attributes are determined by the business party based on its own task execution requirements. For example: if the task executes very quickly and does not need to rely on other computing data or file database resources, main thread scheduling can be selected; if it needs to rely on a large number of files or database resources, IO-type tasks can be selected and scheduled by the IO thread pool; if it needs to rely on a large amount of computing data (such as statistical data calculation), CPU-type tasks can be selected and scheduled by the CPU thread pool.
[0120] CPU-based task thread pools are primarily used to execute computationally intensive tasks that typically require significant CPU resources. By assigning these tasks independent thread pools, you can ensure they receive sufficient CPU time, improving execution efficiency.
[0121] IO-type task thread pool: Mainly used to perform IO-intensive tasks, which usually involve a large number of file reading and writing, network transmission, and other operations. Assigning a separate thread pool to such tasks can optimize the concurrency of IO operations and reduce waiting time.
[0122] Thread pool configuration: Based on the actual system requirements and resource availability, appropriately configure parameters such as the thread pool size, number of core threads, maximum number of threads, and queue size. Set different thread pool parameters for different types of tasks to better meet their execution requirements. For example, for CPU-based tasks, the number of core threads in the thread pool should ideally be equal to the number of cores on the machine + 1. For I / O-based tasks, the number of core threads in the thread pool should be equal to the number of cores on the machine * 2.
[0123] Since some types of tasks cannot directly obtain results when they are executed (such as SMS sending result receipt), the callback logic parameters corresponding to the task scheduler can be determined based on the task execution parameters of the task, and the callback logic parameters can be used to build the asynchronous task callback interface corresponding to the task. The task processor implements the callback interface to wait for the callback and process it, thereby driving the task to be truly completed.
[0124] Optionally, the task scheduling sequence corresponding to the task is determined through the asynchronous thread pool and the asynchronous task callback interface, such as Figure 7 As shown, including:
[0125] Step S701: determining the task memory and task executor corresponding to the task in the task scheduler based on the asynchronous thread pool and the asynchronous task callback interface;
[0126] Step S702 : After registering the task executor with the task scheduler using the task memory, the task scheduler is used to determine the task scheduling sequence corresponding to the task.
[0127] The asynchronous task callback interface is used to handle callback logic after asynchronous task completion. This callback interface allows task developers to perform specific follow-up operations or processing logic after task execution. Specifically, the asynchronous task callback interface is defined as a general interface that task developers need to implement and provide their own callback processing logic. When an asynchronous task completes, the task scheduler automatically calls this callback interface and passes the task execution results and other relevant information to the task developer for subsequent processing.
[0128] Optionally, the step S105 of controlling the task scheduler to execute the task scheduling process according to the task scheduling sequence is as follows: Figure 8 As shown, including:
[0129] Step S801, using the task scheduling sequence to obtain the scheduling sequence parameters and scheduling control parameters of the task;
[0130] Step S802: According to the scheduling execution order determined by the scheduling sequence parameters, the tasks are scheduled using the scheduling control parameters.
[0131] By implementing the task storage container and task executor provided by the task scheduler and registering the task executor with the task scheduler, a schedulable task series is generated. The task scheduling sequence is used to obtain the task's scheduling sequence parameters and scheduling control parameters. The scheduling control parameters are then used to control the task's scheduling according to the scheduling execution order determined by the scheduling sequence parameters. The task scheduler can then schedule the execution of the task series, thereby driving the execution of the tasks.
[0132] like Figure 9 A schematic diagram of executing a task scheduling component in a task scheduling control method is shown. Figure 9 There is a task container set in the task storage in , which is initialized when the task storage is created. 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 of interacting with the storage are delegated to the specific task container for processing.
[0133] also, Figure 9 As can be seen, the task scheduler contains a task executor collection, which puts data into the task executor collection through the registration task executor method. The key of the collection is the task number, and the value of the collection 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 the step-by-step task executor receives the task, it needs to further delegate the task to the step-by-step sub-task executor for implementation.
[0134] From the task scheduling control method mentioned in the above embodiment, it can be seen that this method simplifies the implementation process of task scheduling, aggregates the various components 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 calling logic and improving the task scheduling execution efficiency.
[0135] Corresponding to the task scheduling control method provided in the above embodiment, the embodiment of the present invention provides a task scheduling control system, such as Figure 10 As shown, the system includes:
[0136] A first initialization unit 1010 is configured to generate a distributed lock component, a task storage component, and a task executor component of the task execution environment based on task attribute parameters of the task execution environment;
[0137] The second initialization unit 1020 is used to determine the task priority strategy and task scheduling strategy of the task in the task running environment based on the task flow parameters of the task running environment;
[0138] The task scheduler generation unit 1030 is configured to construct a task scheduler corresponding to the task based on the distributed lock component, the task storage component, and the task executor component, and using the task priority policy and the task scheduling policy;
[0139] The task scheduling sequence determining unit 1040 is configured to use the task scheduler to construct an asynchronous thread pool and an asynchronous task callback interface corresponding to the task, and determine the task scheduling sequence corresponding to the task through the asynchronous thread pool and the asynchronous task callback interface;
[0140] The task scheduling execution unit 1050 is used to control the task scheduler to execute the task scheduling process according to the task scheduling sequence.
[0141] From the task scheduling control system mentioned in the above embodiment, it can be seen that the system simplifies the implementation process of task scheduling, aggregates the various components 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 calling logic and improving the task scheduling execution efficiency.
[0142] The task scheduling control system provided in the embodiment of the present invention has the same implementation principle and technical effects as those of the aforementioned task scheduling control method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference can be made to the corresponding content in the aforementioned task scheduling control method embodiment.
[0143] This embodiment also provides an electronic device. The structural diagram of the electronic device is as follows: Figure 11 As shown, the device includes a processor 101 and a memory 102; wherein 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-mentioned task scheduling control method.
[0144] Figure 11 The electronic device shown further includes a bus 103 and a communication interface 104 , and the processor 101 , the communication interface 104 and the memory 102 are connected via the bus 103 .
[0145] The memory 102 may include a high-speed random access memory (RAM) and may also include a non-volatile memory, such as at least one disk storage. The bus 103 may be an ISA bus, a PCI bus, or an EISA bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 11 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0146] 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 message or IPv4 message to the user terminal through the network interface.
[0147] The processor 101 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by an integrated logic circuit of hardware in the processor 101 or by instructions in the form of software. The above-mentioned processor 101 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The various methods, steps, and logic block diagrams disclosed in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc. The steps of the method disclosed in conjunction 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 can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in memory 102, and processor 101 reads information in memory 102 and, in conjunction with its hardware, completes the steps of the method of the aforementioned embodiment.
[0148] An embodiment of the present invention further provides a storage medium storing a computer program. When the computer program is executed by a processor, the steps of the task scheduling control method in the above embodiment are executed.
[0149] In the several embodiments provided in this 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 schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For 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 mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interface, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0150] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0151] In addition, each functional unit in each embodiment of the present invention 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.
[0152] If the functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage media include various media capable of storing program code, such as USB flash drives, mobile hard drives, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical disks.
[0153] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the above-described embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above-described embodiments within the technical scope disclosed by the present invention, or replace some of the technical features therein with equivalents. Such modifications, changes, or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.
Claims
1. A task scheduling control method, characterized in that: The method comprises: Based on the process access parameters between the task and the shared resource in the task attribute parameters, a distributed lock component corresponding to the task in the task running environment is generated; based on the task storage parameters between the task and the task container in the task attribute parameters, a task storage component corresponding to the task in the task running environment is generated; according to the type parameters in the task attribute parameters, a direct processing task and a step-by-step processing task corresponding to the task in the task running environment are determined; the first task executor component corresponding to the direct processing task is determined by using the operating parameters, and the second task executor component corresponding to the step-by-step processing task is determined by using the operating parameters; a task executor component is generated based on the first task executor component and the second task executor component; Determining a task priority strategy and a task scheduling strategy for tasks in the task execution environment based on task flow parameters of the task execution environment; Constructing a task scheduler corresponding to the task according to the distributed lock component, the task storage component, and the task executor component, and using the task priority strategy and the task scheduling strategy; Determine the thread scheduling parameters corresponding to the task scheduler based on the execution position parameters of the task, and use the thread scheduling parameters to build an asynchronous thread pool corresponding to the task; wherein, the thread scheduling parameters include at least: 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 use the callback logic parameters to build an asynchronous task callback interface corresponding to the task; 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; The task scheduler is controlled to execute the scheduling process of the task according to the task scheduling sequence.
2. The task scheduling control method according to claim 1, characterized in that: Determining a task priority strategy and a task scheduling strategy for tasks in the task execution environment based on task flow parameters of the task execution environment includes: Determine task scheduling parameters for tasks in the task running environment using the task flow parameters; Determining a priority parameter of the task based on the task scheduling parameter, and determining the task priority policy corresponding to the task using the priority parameter; An execution parameter of the task is determined based on the task scheduling parameter, and the task scheduling policy corresponding to the task is determined using the execution parameter and the priority parameter.
3. The task scheduling control method according to claim 1, characterized in that: According to the distributed lock component, the task storage component, and the task executor component, and using the task priority strategy and the task scheduling strategy, a task scheduler corresponding to the task is constructed, including: Constructing a task scheduler component corresponding to the task scheduler according to the distributed lock component, the task storage component and the task executor component; Determine, by using the task scheduler component, the task memory and the task executor corresponding to the task under the task priority policy and the task scheduling policy; The task scheduler is constructed according to the task memory and the task executor.
4. The task scheduling control method according to claim 1, characterized in that: The process of controlling the task scheduler to execute the task scheduling according to the task scheduling sequence includes: Obtaining the scheduling sequence parameters and scheduling control parameters of the tasks using the task scheduling sequence; According to the scheduling execution order determined by the scheduling sequence parameters, the tasks are controlled by the scheduling control parameters for scheduling.
5. A task scheduling control system, characterized in that: The system comprises: A first initialization unit is configured to generate a distributed lock component corresponding to a task in a task running environment based on process access parameters between the task and the shared resource in the task attribute parameters; generate a task storage component corresponding to the task in the task running environment based on task storage parameters between the task and the task container in the task attribute parameters; determine a direct processing task and a step-by-step processing task corresponding to the task in the task running environment according to a type parameter in the task attribute parameters; determine a first task executor component corresponding to the direct processing task using the operating parameters, and determine a second task executor component corresponding to the step-by-step processing task using the operating parameters; and generate a task executor component based on the first task executor component and the second task executor component; A second initialization unit is configured to determine a task priority strategy and a task scheduling strategy for the tasks in the task execution environment based on task flow parameters of the task execution environment; A task scheduler generating unit, configured to construct a task scheduler corresponding to the task according to the distributed lock component, the task storage component, and the task executor component, and using the task priority strategy and the task scheduling strategy; A task scheduling sequence determination unit is used to determine the thread scheduling parameters corresponding to the task scheduler based on the execution position parameters of the task, and use the thread scheduling parameters to build an asynchronous thread pool corresponding to the task; wherein the thread scheduling parameters include at least: 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 use the callback logic parameters to build an asynchronous task callback interface corresponding to the task; 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 with the task scheduler using the task memory, use the task scheduler to determine the task scheduling sequence corresponding to the task; The task scheduling execution unit is used to control the task scheduler to execute the scheduling process of the task according to the task scheduling sequence.
6. An electronic device, characterized in that: The system comprises a processor and a memory, wherein 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 according to any one of claims 1 to 4.
Citation Information
Patent Citations
Task scheduling method applied to hybrid cloud environment
CN119987963A