Hierarchical priority task ordered scheduling method based on virtual thread

By using a two-dimensional queue architecture and a dynamic resource allocation mechanism, the problems of rigid resource allocation and single priority in virtual thread scheduling schemes are solved, achieving efficient and reliable task scheduling and improving resource utilization and system stability.

CN121957804APending Publication Date: 2026-05-01HANGZHOU ARCVIDEO TECHNOLOGY CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HANGZHOU ARCVIDEO TECHNOLOGY CO LTD
Filing Date
2025-12-29
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

Existing task scheduling schemes based on virtual threads struggle to balance efficiency, reliability, and resource adaptability in high-concurrency scenarios. They suffer from rigid resource allocation, simplistic priority scheduling, disconnect between idempotency and retry mechanisms, and fragmented verification and circuit breaker logic, resulting in low system scheduling efficiency, insufficient reliability of core tasks, and significant resource waste.

Method used

By adopting a two-dimensional queue architecture, dynamic resource allocation mechanism, hierarchical priority strategy, and idempotent retry circuit breaker linkage mechanism, and through multi-dimensional verification, load-aware dynamic resource allocation, and hierarchical priority scheduling, the orderly execution of tasks and elastic allocation of resources are achieved, thereby improving resource utilization and the reliability of core tasks.

Benefits of technology

It effectively reduced task scheduling latency, improved resource utilization and the reliability of core tasks, reduced resource waste, enhanced system stability and scheduling efficiency, and ensured priority protection of core tasks and data consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121957804A_ABST
    Figure CN121957804A_ABST
Patent Text Reader

Abstract

The invention discloses a hierarchical priority task orderly scheduling method based on a virtual thread, which comprises the following steps: S10, receiving task parameters transmitted by a business layer, performing task packaging setting, outputting packaged task objects, and transmitting the packaged task objects to a multi-dimensional calibrator; s20, performing task expiration verification, task fusing verification and dependency verification in the multi-dimensional verifier, returning a passing or failing identifier and a failing reason, and if the passing or failing identifier does not pass, triggering a monitoring alarm to record a discard log; s30, the verified tasks enter a two-dimensional queue manager to be subjected to hierarchical enqueue processing and capacity dynamic adjustment, and the capacity dynamic adjustment uses a dynamic resource allocator to achieve elastic allocation of queue capacity and virtual threads based on load awareness; and S40, performing task execution and task retry management on the tasks in the two-dimensional queue.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer concurrent programming and task scheduling technology, specifically relating to a hierarchical priority task ordered scheduling method and system based on virtual threads. Background Technology

[0002] With the popularization of virtual thread technology, its lightweight, low resource consumption and high concurrency support have become the core solution to solve the resource bottleneck of traditional thread scheduling. In actual business, the requirement for orderly execution of tasks grouped by identifier (such as the payment process of the same user and the data synchronization of the same device) is extremely common. However, the existing task scheduling scheme based on virtual thread has core technical defects and it is difficult to balance efficiency, reliability and resource adaptability. Specifically: (1) Rigid resource allocation mechanism: The queue capacity and thread allocation adopt static configuration and cannot be dynamically adjusted according to the system load (CPU / memory usage) and task frequency, resulting in high-frequency identifier tasks queuing and congestion, low-frequency identifier tasks occupying redundant resources, and the resource utilization rate is less than 50%. (2) Single priority scheduling strategy: When the queue is full, it only supports discarding the oldest task or directly rejecting the single strategy. There is no differentiated protection between core tasks (such as payment and transaction) and non-core tasks (such as log reporting and data statistics), which easily leads to the loss or delay of core tasks. (3) Idempotency and retry mechanism are disconnected: The retry logic is not strongly bound to the idempotency of the task. Retrying non-idempotent tasks can easily lead to data inconsistency (such as duplicate deductions). Moreover, the retry interval is fixed and the system recovery rhythm is not considered. (4) Validation and circuit breaker logic are scattered: Task expiration validation, circuit breaker validation, and dependency validation are separated into independent processes. The frequent jumps between nodes not only increase the scheduling delay (an average of more than 30%), but also the circuit breaker trigger only depends on a single failure rate indicator and is not linked to the system load and queue status. (5) Monitoring and scheduling process are isolated: The monitoring nodes are scattered in various process branches and are not linked to core mechanisms such as circuit breakers and retry. It is impossible to quickly adjust the scheduling strategy through monitoring data, resulting in low efficiency in problem localization.

[0003] In summary, existing technologies only focus on the lightweight characteristics of virtual threads and do not design integrated mechanisms for the core requirements of ordered identification, differentiated priority, and elastic resource adaptation. This results in low scheduling efficiency, insufficient reliability of core tasks, and serious resource waste in high-concurrency scenarios. Summary of the Invention

[0004] In view of the above-mentioned problems, the technical problem to be solved by the present invention is to provide a hierarchical priority task orderly scheduling method based on virtual threads. The method achieves efficient and orderly scheduling through a two-dimensional queue architecture, dynamic resource allocation mechanism, hierarchical priority strategy and idempotent retry circuit breaker linkage mechanism. Under the premise of ensuring the orderly execution of tasks with the same identifier, it improves resource utilization, core task reliability and system stability.

[0005] To solve the above-mentioned technical problems, the present invention adopts the following technical solution:

[0006] A hierarchical priority-based task scheduling method based on virtual threads includes the following steps:

[0007] S10 receives task parameters from the business layer, performs task encapsulation settings, outputs the encapsulated task object, and passes it to the multi-dimensional validator.

[0008] S20 performs task expiration verification, task circuit breaker verification, and dependency verification in the multi-dimensional validator, and returns a pass or fail flag and the reason for failure. If it fails, the monitoring alarm will be triggered to record the discard log.

[0009] S30: The verified tasks enter the two-dimensional queue manager for hierarchical queuing and dynamic capacity adjustment. The dynamic capacity adjustment uses a dynamic resource allocator to achieve elastic allocation of queue capacity and virtual threads based on load awareness.

[0010] S40 manages task execution and retry for tasks in the two-dimensional queue.

[0011] Preferably, the task encapsulation settings in S10 include: verifying the validity of parameters including identifier, priority, and task logic; setting default values ​​for unconfigured valid duration, timeout, and maximum number of retries; and generating a unique task ID.

[0012] Preferably, the task expiration verification logic in S20 is as follows: if the task is configured with a valid duration, the task creation time is calculated plus the valid duration to obtain the expiration time, and compared with the current system time: if the current time > the expiration time, it is determined to be expired; otherwise, it passes.

[0013] Preferably, the task priorities include core task P0, ordinary task P1, and low priority task P2.

[0014] Preferably, the task circuit breaker verification logic in S20 is as follows: Verify non-P0 tasks; query the status of the smart circuit breaker using the identifier-priority as the key. The smart circuit breaker status includes closed state, open state, and semi-open state. If the smart circuit breaker status is open, it is determined that the circuit breaker has been triggered; otherwise, it passes.

[0015] Preferably, the dependency verification logic in S20 is as follows: if the task has no list of dependent task IDs, it passes directly; if there are dependent tasks, the status of the dependent tasks is queried as to whether they are completed or not; if all dependent tasks are completed, it passes; if there are incomplete dependencies, they are temporarily stored in the dependency waiting queue, and the dependency status is detected by a lightweight listening thread. The dependency verification is automatically retried after all dependencies are completed.

[0016] Preferably, the data structure design of the two-dimensional queue manager in S30 adopts a two-layer thread-safe mapping structure, which is based on ConcurrentHashMap. The first layer is grouped according to task identifier, and the second layer is divided into independent sub-queues according to priority. Tasks under the same identifier are executed in FIFO order of enqueueing. The task queue is implemented using LinkedBlockingQueue.

[0017] Preferably, the task queue is implemented using LinkedBlockingQueue, including:

[0018] Queue creation: When a new identifier or new priority task is received, if the corresponding queue does not exist, it will be created automatically. The outer mapping will add an identifier key-value pair, and the inner mapping will add a priority-queue key-value pair.

[0019] Hierarchical queuing: First, query the dynamic resource allocator to obtain the target capacity of the current priority queue, where the target capacity is the dynamically adjusted capacity;

[0020] If the current length of the queue is less than the target capacity, the task is directly added to the end of the queue for enqueue processing;

[0021] If the current length is greater than or equal to the target capacity, i.e., the queue is full, then it will be processed differently according to priority:

[0022] For P0 tasks, temporarily expand the capacity to 1.5 times the current target capacity, enqueue the tasks, and restore the target capacity after the current batch of tasks has been completed.

[0023] For task P1, remove one task from the head of the queue, free up space, and then enqueue the current task.

[0024] For task P2, refuse to enqueue it and return a result indicating that the queue is full.

[0025] Preferably, the dynamic capacity adjustment in S30 uses a dynamic resource allocator to achieve elastic allocation of queue capacity and virtual threads based on load awareness, including:

[0026] Data Acquisition: Real-time acquisition of system load metrics and task frequency metrics; the load metrics include CPU utilization and memory utilization, and the task frequency metrics are the number of tasks with the same identifier and priority per unit time;

[0027] The algorithm for dynamic queue capacity adjustment is as follows: The input includes parameters such as the current queue capacity C, CPU utilization U, memory utilization M, and task frequency F; if the CPU load is low and the task frequency is high, the queue capacity is expanded; if the load is high and the task frequency is low, the queue capacity is reduced; and a boundary limit is imposed on the target capacity; the queue capacity is dynamically adjusted once before each batch of tasks is enqueued.

[0028] Virtual thread allocation strategy: Perform basic thread pool configuration; allocate dedicated virtual threads for tasks in high-frequency queues; and share the core thread of the thread pool for tasks in medium-frequency and low-frequency queues.

[0029] Preferably, the task execution in S40 for the tasks in the two-dimensional queue includes:

[0030] Retrieve tasks from the head of the two-dimensional queue;

[0031] The task logic is submitted to an independent thread in the virtual thread pool for execution, and the execution time is monitored through the Future mechanism;

[0032] If the execution time is less than or equal to the timeout configured for the task, record the execution result, including whether it was successful or failed.

[0033] If the execution time exceeds the timeout period, the thread is interrupted and the task is marked as failed.

[0034] Preferably, the task retry management in the two-dimensional queue in S40 includes:

[0035] Determine if the retry trigger condition is met: the task execution failed, the idempotency flag is true, and the number of retries already completed is less than the maximum number of retries;

[0036] Retry interval calculation: Using the exponential backoff algorithm, the interval for the nth retry is 1 second × 2. n ;

[0037] Retry task handling: Resubmit the retry task to the tail of the original identifier-priority queue and execute it in FIFO order.

[0038] The present invention has the following beneficial effects:

[0039] (1) To solve the problem of high scheduling delay caused by scattered verification process and redundant nodes in the existing virtual thread task scheduling scheme, the expiration verification, circuit breaker verification and dependency verification are integrated into a unified multi-dimensional verification mechanism, which simplifies the scheduling process nodes and improves task scheduling efficiency and response speed.

[0040] (2) To overcome the shortcomings of rigid resource allocation in existing solutions, such as congestion of high-frequency tasks and waste of low-frequency tasks, a load-aware dynamic resource allocation mechanism is provided to realize the adaptive expansion and contraction of queue capacity with system load and task frequency, as well as the exclusive and shared differentiated allocation of virtual threads, so as to maximize the utilization of hardware resources such as CPU and memory.

[0041] (3) To solve the problem that the existing scheduling scheme has a single priority processing and thus lacks protection for core tasks, by defining three levels of task priority (P0 / P1 / P2) and designing differentiated queuing strategies when the queue is full (P0 temporarily expands capacity, P1 removes the oldest task, and P2 refuses to enqueue), the priority protection of core business tasks is realized, and the risk of core tasks being lost or delayed is reduced.

[0042] (4) To solve the problem of data inconsistency caused by the disconnect between the existing retry mechanism and idempotency, a smart retry scheme with strong idempotency binding is provided. It triggers exponential backoff retry only for idempotent tasks that have not reached the retry limit, taking into account both task execution reliability and data consistency, and avoiding business risks caused by non-idempotent task retries.

[0043] (5) To make up for the shortcomings of the existing circuit breaker mechanism, which has a single indicator and isolated monitoring, resulting in insufficient system fault tolerance, we will build an intelligent circuit breaker system with multiple indicators (failure rate, queue saturation) linkage, and combine full-link monitoring data to realize dynamic switching of circuit breaker status and alarm linkage, quickly isolate faulty tasks, prevent fault propagation, and improve the overall stability and availability of the system. Attached Figure Description

[0044] Figure 1 This is a flowchart illustrating the steps of a hierarchical priority task scheduling method based on virtual threads, according to an embodiment of the present invention. Detailed Implementation

[0045] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0046] Reference Figure 1 The diagram shows a flowchart of a hierarchical priority task scheduling method based on virtual threads according to an embodiment of the present invention, including the following steps:

[0047] S10 receives task parameters from the business layer, performs task encapsulation settings, outputs the encapsulated task object, and passes it to the multi-dimensional validator.

[0048] S20 performs task expiration verification, task circuit breaker verification, and dependency verification in the multi-dimensional validator, and returns a pass or fail flag and the reason for failure. If it fails, the monitoring alarm will be triggered to record the discard log.

[0049] S30: The verified tasks enter the two-dimensional queue manager for hierarchical queuing and dynamic capacity adjustment. The dynamic capacity adjustment uses a dynamic resource allocator to achieve elastic allocation of queue capacity and virtual threads based on load awareness.

[0050] S40 manages task execution and retry for tasks in the two-dimensional queue.

[0051] In a specific application example, task encapsulation settings in S10 include: validating the validity of parameters including identifier, priority, and task logic; setting default values ​​for unconfigured validity duration, timeout, and maximum retries; and generating a unique task ID. Task parameters passed from the business layer include identifier, priority, task logic, and idempotency flags. Task priorities include core task P0, ordinary task P1, and low-priority task P2. Specific settings can be as follows: the identifier (flag) must be non-empty and ≤64 characters in length; the priority must be one of P0 / P1 / P2; and the task logic (implemented by the Runnable interface) must be non-empty. If no validity duration is configured, it defaults to permanent validity; if no timeout is configured, it defaults to 60 seconds; and if no maximum retries are configured, it defaults to 3. The unique task ID can be constructed using "UUID + first 8 digits of the identifier + priority" (e.g., uuid-12345678-P0) to ensure task uniqueness.

[0052] In a specific application example, the task expiration verification logic in S20 is as follows: If the task is configured with a valid duration, the task creation time is calculated plus the valid duration (e.g., 30 minutes) to obtain the expiration time. The current system time is then compared: if the current time is greater than the expiration time, the task is determined to be expired; otherwise, it passes the test.

[0053] The task circuit breaker verification logic is as follows: Verify non-P0 tasks (P0 core tasks are exempt from circuit breaker); query the status of the smart circuit breaker using the identifier-priority key. The smart circuit breaker status includes closed state, open state, and semi-open state. If the smart circuit breaker status is open, it is determined that the circuit breaker has been triggered; otherwise, it passes.

[0054] The dependency verification logic is as follows: If the task has no dependency task ID list, it passes directly; if there are dependency tasks, the status of the dependency tasks is queried as to whether they are completed or not; if all dependency tasks are completed, it passes; if there are incomplete dependencies, they are temporarily stored in the dependency waiting queue, and the dependency status is checked by a lightweight listening thread (polling once per second). The dependency verification is automatically retried after all dependencies are completed.

[0055] In a specific application example, the data structure design of the two-dimensional queue manager in S30 adopts a two-layer thread-safe mapping structure based on ConcurrentHashMap. The first layer is grouped by task identifier, and the second layer is divided into independent sub-queues according to priority. Tasks under the same identifier are executed in FIFO order of enqueueing. The task queue is implemented using LinkedBlockingQueue.

[0056] Furthermore, the task queue is implemented using LinkedBlockingQueue, including:

[0057] Queue creation: When a new identifier or new priority task is received, if the corresponding queue does not exist, it will be created automatically. The outer mapping will add an identifier key-value pair, and the inner mapping will add a priority-queue key-value pair. The initial queue capacity is 50 by default.

[0058] Hierarchical queuing: First, query the dynamic resource allocator to obtain the target capacity of the current priority queue, where the target capacity is the dynamically adjusted capacity;

[0059] If the current length of the queue is less than the target capacity, the task is directly added to the end of the queue for enqueue processing;

[0060] If the current length is greater than or equal to the target capacity, i.e., the queue is full, then it will be processed differently according to priority:

[0061] For P0 tasks, temporarily expand the capacity to 1.5 times the current target capacity, enqueue the tasks, and restore the target capacity after the current batch of tasks has been completed.

[0062] For task P1, remove one task from the head of the queue, free up space, and then enqueue the current task.

[0063] For task P2, refuse to enqueue it and return a result indicating that the queue is full.

[0064] A specific application example: In S30, dynamic capacity adjustment uses a dynamic resource allocator to achieve elastic allocation of queue capacity and virtual threads based on load awareness, including:

[0065] Data Acquisition: Real-time acquisition of system load metrics and task frequency metrics; the load metrics include CPU utilization and memory utilization, and the task frequency metrics are the number of tasks with the same identifier and priority per unit time;

[0066] The algorithm for dynamic queue capacity adjustment is as follows: The input includes parameters such as the current queue capacity C, CPU utilization U (0~1), memory utilization M (0~1), and task frequency F (times / minute); if the CPU load is low and the task frequency is high, the queue capacity is expanded; if the load is high and the task frequency is low, the queue capacity is reduced; and a boundary limit is imposed on the target capacity; the queue capacity is dynamically adjusted once before each batch of tasks is enqueued.

[0067] Virtual thread allocation strategy: Perform basic thread pool configuration; allocate dedicated virtual threads for tasks in high-frequency queues; and share the core thread of the thread pool for tasks in medium-frequency and low-frequency queues.

[0068] For a specific example, the expansion conditions could be: U < 0.5 (low CPU load) and F > 200 (high-frequency tasks), then the target capacity C_target = C × 1.2, an expansion of 20%;

[0069] The reduction conditions can be: (U>0.8 or M>0.9) (high load) and F < 50 (low frequency of task), then the target capacity C_target = C×0.8, and the reduction is 20%;

[0070] Boundary limits can be: 10≤C_target≤1000 (to avoid task loss due to insufficient capacity, or resource waste due to excessive capacity).

[0071] The basic configuration of the thread pool can be: core thread count = number of CPU cores × 2, maximum thread count = number of CPU cores × 4, idle thread lifespan of 30 seconds, and the thread factory uses the Java 21 virtual thread factory (Thread.ofVirtual().factory()).

[0072] Dedicated thread allocation can be: a priority queue for tasks with a frequency F > 200 times / minute, with 1 to 2 dedicated virtual threads allocated to avoid queuing for high-frequency tasks;

[0073] Shared thread allocation can be: tasks in medium-frequency (50≤F≤200) and low-frequency (F<50) queues, sharing the core threads of the thread pool to improve thread utilization.

[0074] A specific application example, in S40, task execution of tasks in a two-dimensional queue includes:

[0075] Retrieve tasks from the head of the two-dimensional queue;

[0076] The task logic is submitted to an independent thread in the virtual thread pool for execution, and the execution time is monitored through the Future mechanism;

[0077] If the execution time is less than or equal to the timeout configured for the task (e.g., 30 seconds), then record the execution result, including whether it was successful or failed.

[0078] If the execution time exceeds the timeout period, the thread is interrupted and the task is marked as failed.

[0079] Preferably, the task retry management in the two-dimensional queue in S40 includes:

[0080] Determine if the retry trigger condition is met: the task execution failed, the idempotency flag is true, and the number of retries already completed is less than the maximum number of retries;

[0081] Retry interval calculation: Using the exponential backoff algorithm, the interval for the nth retry is 1 second × 2. n (n≥1, such as the first interval being 2 seconds, the second being 4 seconds, and the third being 8 seconds);

[0082] Retry task handling: Resubmit the retry task to the end of the original identifier-priority queue and execute it in FIFO order to avoid disrupting the order of tasks.

[0083] In specific application examples, smart fuses trigger fuses based on multi-indicator linkage to prevent fault propagation, which can be achieved in the following ways:

[0084] Circuit breaker status management: Maintain circuit breaker status (closed state / open state / semi-open state) using identifier-priority as the key, with the initial state being closed;

[0085] Trigger thresholds (triggered if any one of them is met):

[0086] i. Threshold 1: Task failure rate > 50% within 1 minute (number of failures / total number of executions);

[0087] ii. Threshold 2: Queue saturation > 90% (current length / target capacity) for 3 seconds;

[0088] The state transition logic is as follows:

[0089] i. Closed state → Open state: Enters after the threshold is triggered, and refuses non-P0 tasks from joining the queue for 5 seconds;

[0090] ii. Open state → Semi-open state: Automatically switches after 5 seconds, allowing a maximum of 10 tasks to join the queue;

[0091] iii. From semi-open state to closed state: The failure rate of 10 tasks is less than 30%, and the system returns to normal.

[0092] iv. Semi-open state → Open state: If the failure rate of 10 tasks is ≥30%, re-enter the open state;

[0093] To achieve end-to-end monitoring and alarm linkage, the monitoring and alarm system implements the following:

[0094] Monitoring data collection: Collect metrics for the entire lifecycle of the task (submission time, verification result, queue status, execution duration, execution result, number of retries, circuit breaker status);

[0095] Data storage: Monitoring data is retained for 7 days and can be queried by identifier, priority, and time range;

[0096] Alarm configuration: Supports custom alarm thresholds (e.g., P0 task failure rate > 30%, circuit breaker trigger count > 5 times / hour);

[0097] Alarm methods: After an alarm is triggered, it will be reported via email, SMS or log, which will help maintenance personnel to quickly locate the problem.

[0098] The hierarchical priority task scheduling method based on virtual threads in this invention can be deployed on a single machine or in a cluster. In a single-machine deployment, all modules are implemented in memory, with the two-dimensional queue, circuit breaker status, and monitoring data stored locally in memory. There are no external dependencies, resulting in low deployment costs and suitability for concurrency scenarios below 10,000 per second. In a cluster deployment, a distributed cache (such as Redis) shares the "identifier-priority-queue" mapping, circuit breaker status, and dependent task status. Monitoring data is stored in a time-series database (such as InfluxDB), supporting concurrency up to 100,000 per second, making it suitable for distributed systems and microservice architectures.

[0099] The virtual thread-based hierarchical priority task scheduling method described above, through multi-dimensional integrated verification, a two-dimensional queue of identifiers and priorities, load-aware dynamic resource allocation, hierarchical priority differentiated scheduling, idempotent strong binding intelligent retry, and multi-indicator linkage intelligent circuit breaking mechanism, not only reduces task scheduling latency by more than 40%, improves CPU utilization by 35%, and reduces memory usage by 30%, but also effectively solves the pain points of redundant processes and rigid resource allocation in existing solutions. It achieves a core task execution success rate of over 99.95% and system availability of 99.9%, while reducing maintenance costs by 50% through modular architecture. It is adaptable to diverse deployment scenarios such as single machines and distributed clusters, and takes into account scheduling efficiency, resource utilization, business reliability, and system stability in high-concurrency scenarios. It can widely meet the ordered task scheduling needs of distributed systems, microservices, real-time data processing, and other fields.

[0100] It should be understood that the exemplary embodiments described herein are illustrative and not restrictive. Although one or more embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art will understand that various changes in form and detail may be made without departing from the spirit and scope of the invention as defined by the appended claims.

Claims

1. A hierarchical priority-based task scheduling method based on virtual threads, characterized in that, Includes the following steps: S10 receives task parameters from the business layer, performs task encapsulation settings, outputs the encapsulated task object, and passes it to the multi-dimensional validator. S20 performs task expiration verification, task circuit breaker verification, and dependency verification in the multi-dimensional validator, and returns a pass or fail flag and the reason for failure. If it fails, the monitoring alarm will be triggered to record the discard log. S30: The verified tasks enter the two-dimensional queue manager for hierarchical queuing and dynamic capacity adjustment. The dynamic capacity adjustment uses a dynamic resource allocator to achieve elastic allocation of queue capacity and virtual threads based on load awareness. S40 manages task execution and retry for tasks in the two-dimensional queue.

2. The hierarchical priority task scheduling method based on virtual threads as described in claim 1, characterized in that, In S10, task encapsulation settings include: verifying the validity of parameters such as identifier, priority, and task logic; setting default values ​​for unconfigured validity duration, timeout, and maximum number of retries; and generating a unique task ID.

3. The hierarchical priority task scheduling method based on virtual threads as described in claim 2, characterized in that, The task expiration verification logic in S20 is as follows: If the task is configured with a valid duration, the task creation time is calculated plus the valid duration to obtain the expiration time. The current system time is then compared: if the current time is greater than the expiration time, the task is considered expired; otherwise, it passes the verification.

4. The hierarchical priority task scheduling method based on virtual threads as described in claim 2, characterized in that, Task priorities include core tasks P0, ordinary tasks P1, and low-priority tasks P2.

5. The hierarchical priority task scheduling method based on virtual threads as described in claim 3, characterized in that, The task circuit breaker verification logic in S20 is as follows: Verify non-P0 tasks; query the status of the smart circuit breaker using the identifier-priority key. The smart circuit breaker status includes closed state, open state, and semi-open state. If the smart circuit breaker status is open, it is determined that the circuit breaker has been triggered; otherwise, it passes.

6. The hierarchical priority task scheduling method based on virtual threads as described in claim 2, characterized in that, The dependency verification logic in S20 is as follows: If the task has no list of dependent task IDs, it passes directly; if there are dependent tasks, the status of the dependent tasks is queried as to whether they are completed or not; if all dependent tasks are completed, it passes; if there are incomplete dependencies, they are temporarily stored in the dependency waiting queue, and the dependency status is detected by a lightweight listening thread. The dependency verification is automatically retried after all dependencies are completed.

7. The hierarchical priority task scheduling method based on virtual threads as described in claim 2, characterized in that, The data structure design of the two-dimensional queue manager in S30 adopts a two-layer thread-safe mapping structure, which is based on ConcurrentHashMap. The first layer is grouped by task identifier, and the second layer is divided into independent sub-queues according to priority. Tasks under the same identifier are executed in FIFO order of enqueue. The task queue is implemented using LinkedBlockingQueue.

8. The hierarchical priority task scheduling method based on virtual threads as described in claim 7, characterized in that, The task queue is implemented using LinkedBlockingQueue and includes: Queue creation: When a new identifier or new priority task is received, if the corresponding queue does not exist, it will be created automatically. The outer mapping will add an identifier key-value pair, and the inner mapping will add a priority-queue key-value pair. Hierarchical queuing: First, query the dynamic resource allocator to obtain the target capacity of the current priority queue, where the target capacity is the dynamically adjusted capacity; If the current length of the queue is less than the target capacity, the task is directly added to the end of the queue for enqueue processing; If the current length is greater than or equal to the target capacity, i.e., the queue is full, then it will be processed differently according to priority: For P0 tasks, temporarily expand the capacity to 1.5 times the current target capacity, enqueue the tasks, and restore the target capacity after the current batch of tasks has been completed. For task P1, remove one task from the head of the queue, free up space, and then enqueue the current task. For task P2, refuse to enqueue it and return a result indicating that the queue is full.

9. The hierarchical priority task scheduling method based on virtual threads as described in claim 2, characterized in that, In S30, dynamic capacity adjustment uses a dynamic resource allocator to achieve elastic allocation of queue capacity and virtual threads based on load awareness, including: Data Acquisition: Real-time acquisition of system load metrics and task frequency metrics; the load metrics include CPU utilization and memory utilization, and the task frequency metrics are the number of tasks with the same identifier and priority per unit time; The algorithm for dynamic queue capacity adjustment is as follows: The input includes parameters such as the current queue capacity C, CPU utilization U, memory utilization M, and task frequency F; if the CPU load is low and the task frequency is high, the queue capacity is expanded; if the load is high and the task frequency is low, the queue capacity is reduced; and a boundary limit is imposed on the target capacity; the queue capacity is dynamically adjusted once before each batch of tasks is enqueued. Virtual thread allocation strategy: Perform basic thread pool configuration; allocate dedicated virtual threads for tasks in high-frequency queues; and share the core thread of the thread pool for tasks in medium-frequency and low-frequency queues.

10. The hierarchical priority task scheduling method based on virtual threads as described in claim 2, characterized in that, Task execution in S40 for tasks in a two-dimensional queue includes: Retrieve tasks from the head of the two-dimensional queue; The task logic is submitted to an independent thread in the virtual thread pool for execution, and the execution time is monitored through the Future mechanism; If the execution time is less than or equal to the timeout configured for the task, record the execution result, including whether it was successful or failed. If the execution time exceeds the timeout period, the thread is interrupted and the task is marked as failed.

11. The hierarchical priority task scheduling method based on virtual threads as described in claim 2, characterized in that, S40 includes the following retry management for tasks in a two-dimensional queue: Determine if the retry trigger condition is met: the task execution failed, the idempotency flag is true, and the number of retries already completed is less than the maximum number of retries; Retry interval calculation: Using the exponential backoff algorithm, the interval for the nth retry is 1 second × 2. n ; Retry task handling: Resubmit the retry task to the tail of the original identifier-priority queue and execute it in FIFO order.

Citation Information

Cited By

  • A task scheduling method and system based on a hierarchical abstraction model

    CN122220079A

  • A task scheduling method and system based on a hierarchical abstraction model

    CN122220079B