Timing task interruption method, timer, vehicle and storage medium

By creating a stage task execution class in Java timer, dividing scheduled tasks into segments and querying task cancellation attributes, the problem of scheduled tasks not being interrupted in time is solved, and automatic cancellation of scheduled tasks is achieved and system stability is improved.

CN118779079AActive Publication Date: 2024-10-15CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202410935535.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-12
Publication Date
2024-10-15
Estimated Expiration
2044-07-12

AI Technical Summary

Technical Problem

The existing Java timer cannot interrupt the executing task in a timely and effective manner when canceling the scheduled task, resulting in increased development complexity and affected system stability.

Method used

By creating a phase task execution class, including task cancellation attributes and process scheduling functions, the scheduled tasks are divided into segments. After the previous phase task is executed, the task cancellation attribute is queried. If it is an interruption attribute, the execution of the unfinished phase task is stopped to implement the scheduled task. Phased execution and automatic cancellation.

Benefits of technology

It achieves timely and effective interruption of scheduled tasks, reduces development complexity, improves system stability and security, and avoids abnormal risks that may be caused by manually canceling tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118779079A_ABST
    Figure CN118779079A_ABST
Patent Text Reader

Abstract

The invention provides a timed task interruption method, a timer, a vehicle and a storage medium, and the method comprises the steps that a stage task execution class is created in advance, the stage task execution class comprises a task cancelling attribute and a process scheduling function, and the task cancelling attribute is used for marking whether a timed task is cancelled or not; obtaining a target task to be executed at fixed time, calling a process scheduling function, performing stage division on the target task, and generating a stage task set; before executing each stage task in the stage task set, querying the attribute value of the task cancelling attribute; and if the attribute value is the preset interrupt attribute, stopping executing the stage tasks which are not executed in the stage task set. By creating the stage task execution class to segment the timed task, the task is interrupted according to the attribute value before each stage task is executed, so that staged execution and automatic cancellation of the timed task are realized, and timely and effective interruption of the timed task is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a timed task interruption method, a timer, a vehicle and a storage medium. Background Art

[0002] In Java (a computer language), java.util.Timer (i.e. timer tool) is an advanced timer used to schedule the execution of specified tasks in a background thread, that is, to execute some tasks that need to be executed periodically or regularly, and automatically execute tasks based on a given time point, a given time interval, or a given number of executions, such as scheduled task scheduling, scheduled email sending, and scheduled database update checking. In Timer (i.e. timer), there is a schedule function (i.e. process scheduling function), which accepts three parameters: java.util.TimerTask task, which is the specific task to be executed; long delay, which is the delay before starting to execute the task task; long period, which is the period of each task execution. At the same time, Timer also provides a cancel function (i.e. task cancellation function) to cancel the timer task.

[0003] In the related art, when calling the cancel function to cancel a timer task, if a task has already started executing, the task that has started executing will not be stopped. For example, for the requirement to execute a download task every 1 minute, since the download task is a time-consuming task, when the user wants to stop the download task, some download tasks are in progress. In this case, even if the user calls the cancel function, the download task that is already being executed cannot be stopped, and the only effect is that no new download tasks will be started later. This results in: 1. The task cannot be automatically canceled. After the task starts executing, it cannot be automatically canceled and manual intervention is required; 2. The development difficulty is increased, and additional code needs to be written to handle the cancellation of the task, which increases the complexity of development; 3. There are potential risks. Manually canceling the task may cause exceptions during the task execution process, affecting the stability and security of the system. Summary of the invention

[0004] In view of the above-mentioned shortcomings of the prior art, the present application discloses a timed task interruption method, a timer, a vehicle and a storage medium, which are used to solve the technical problem in the prior art that a timed task being executed cannot be interrupted in a timely and effective manner.

[0005] In the first aspect, the present application provides a method for interrupting a scheduled task, the method comprising: pre-creating a stage task execution class, the stage task execution class including a task cancellation attribute and a process scheduling function, wherein the task cancellation attribute is used to mark whether the scheduled task is canceled; obtaining a target task to be executed on a scheduled basis, and calling the process scheduling function to divide the target task into stages to generate a stage task set; before executing each stage task in the stage task set, querying the attribute value of the task cancellation attribute; if the attribute value is a preset interrupt attribute, stopping the execution of the unexecuted stage tasks in the stage task set.

[0006] In one embodiment of the present application, the process scheduling function is called to divide the target task into stages and generate a stage task set, including: performing a timing type analysis on the target task to determine the target timing type corresponding to the target task, wherein the timing type includes a periodic timing task; determining whether the target timing type is the periodic timing task; if the target task is the periodic timing task, dividing each periodic task in the target task into stages to generate a plurality of first-stage task functions; generating the stage task set according to the plurality of first-stage task functions corresponding to each of the periodic tasks and the task period and delay time corresponding to the target task.

[0007] In one embodiment of the present application, the timing type also includes a one-time timing task; after determining the target timing type corresponding to the target task, it also includes: judging whether the target timing type is the one-time timing task; if the target task is the one-time timing task, dividing the target task into stages to generate multiple second-stage task functions; generating the stage task set according to the delay time corresponding to the multiple second-stage task functions and the target task.

[0008] In one embodiment of the present application, the stage division of the target task includes: performing a task type analysis on the target task to determine the target task type corresponding to the target task, wherein the task type includes a progress-type task and a duration-type task; if the target task is the progress-type task, the target task is divided into stages according to a preset progress division principle; if the target task is the duration-type task, the target task is divided into stages according to a preset duration division principle.

[0009] In one embodiment of the present application, each of the stage tasks in the stage task set is arranged according to an execution order; before executing each stage task in the stage task set, the attribute value of the task cancellation attribute is queried, including: pre-setting an interval time and a query frequency between every two stage tasks; if it is monitored that the previous stage task has been completed, then the attribute value is queried multiple times according to the query frequency within the interval time until the next stage task starts to be executed.

[0010] In one embodiment of the present application, the stage task execution class also includes a task cancellation function; the method for setting the attribute value includes: in response to a received interrupt request, calling the task cancellation function to parse the interrupt request to obtain a task identifier, wherein the interrupt request carries the task identifier; matching the task identifier with a target task identifier corresponding to the target task; if the match is consistent, setting the attribute value to the interrupt attribute; if the match is inconsistent, setting the attribute value to the execution attribute.

[0011] In one embodiment of the present application, stopping the execution of the unexecuted stage tasks in the stage task set includes: based on the interrupt attribute, obtaining the unexecuted segmented task function in the stage task set, and determining it as the target stage task function; generating an interrupt instruction according to the target segmented task function; executing the interrupt instruction to control the stage task corresponding to the target stage task function to stop executing.

[0012] In the second aspect, the present application provides a timer that can interrupt a scheduled task, and the timer includes: a construction module, which is used to pre-create a stage task execution class, and the stage task execution class includes a task cancellation attribute and a process scheduling function, wherein the task cancellation attribute is used to mark whether the scheduled task is cancelled; a stage module, which is used to obtain the target task to be executed on a scheduled basis, and call the process scheduling function to divide the target task into stages to generate a stage task set; a query module, which is used to query the attribute value of the task cancellation attribute before executing each stage task in the stage task set; a control module, which is used to stop executing the unexecuted stage tasks in the stage task set if the attribute value is a preset interrupt attribute.

[0013] In a third aspect, the present application provides a vehicle, characterized in that it includes the timer capable of interrupting a timed task as described in the second aspect, or uses the timed task interruption method as described in the first aspect.

[0014] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor of a computer, the computer executes the timed task interruption method described in the first aspect.

[0015] As described above, the timed task interruption method, timer, vehicle and storage medium provided by the embodiments of the present application have the following beneficial effects:

[0016] First, a stage task execution class is created in advance, which includes a task cancellation attribute and a process scheduling function. The task cancellation attribute is used to mark whether the scheduled task is cancelled. Then, the target task to be scheduled is obtained. By calling the process scheduling function, the target task is divided into stages to generate a stage task set. Before executing each stage task in the stage task set, the attribute value of the task cancellation attribute is queried first. If the attribute value is an interrupt attribute at this time, the stage tasks that have not been executed in the stage task set are stopped. The scheduled task is segmented by creating a stage task execution class, that is, the target task is divided into multiple stages for execution. After executing the previous stage task, if the scheduled task has not been completed, the attribute value is queried before executing the next stage task. If it is an interrupt attribute, the task is interrupted. The attribute status is automatically detected at the transition point of each stage, which realizes the staged execution and automatic cancellation of the scheduled task, ensuring the timely and effective interruption of the scheduled task.

[0017] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:

[0019] Figure 1 It is a schematic diagram of an implementation environment of a timer capable of interrupting a timed task, shown in an exemplary embodiment of the present application;

[0020] Figure 2 is a flow chart of a timed task interruption method shown in an exemplary embodiment of the present application;

[0021] Figure 3 is a schematic diagram of a stage task execution class shown in an exemplary embodiment of the present application;

[0022] Figure 4 is a flowchart of a specific timed task interruption method shown in an exemplary embodiment of the present application;

[0023] Figure 5is a block diagram of a timer capable of performing a timed task interruption, shown in an exemplary embodiment of the present application;

[0024] Figure 6 It is a structural schematic diagram of an electronic device shown as an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0025] The following will describe the implementation methods of the present application with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. The present application can also be implemented or applied through other different specific implementation methods, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be understood that the preferred embodiments are only for illustrating the present application, not for limiting the scope of protection of the present application.

[0026] It should be noted that the illustrations provided in the following embodiments are only used to illustrate the basic concept of the present application in a schematic manner, and therefore the illustrations only show components related to the present application rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0027] In the following description, a large number of details are discussed to provide a more thorough explanation of the embodiments of the present application. However, it is obvious to those skilled in the art that the embodiments of the present application can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present application difficult to understand.

[0028] Timer refers to a timer used to schedule the execution of a specified task in a background thread, to execute some tasks that need to be executed periodically or regularly, and to automatically execute tasks based on a given time point, a given time interval, or a given number of executions. However, the inventor of this application has found that when calling the cancel function to cancel a timer task, if a task has already started executing, the task that has started executing will not be stopped. Even if the cancel function is called, the download task that is already executing cannot be stopped, and the only effect is that no new download tasks will be started later. Therefore, the existing Timer: 1. It cannot automatically cancel the task. After the task starts executing, it cannot be automatically canceled, and manual intervention is required; 2. The development difficulty is increased, and additional code needs to be written to handle the cancellation of the task, which increases the complexity of development; 3. There are potential risks. Manually canceling a task may cause anomalies during the execution of the task, affecting the stability and security of the system.

[0029] Therefore, see Figure 1 , Figure 1 FIG. 1 is a schematic diagram of an implementation environment of a timer capable of interrupting a timed task according to an exemplary embodiment of the present application. Figure 1 As shown, the implementation environment includes a vehicle 110 and a timer 120, wherein the timer 120 is embedded in the vehicle 110 and is used to implement the execution and interruption of the scheduled task in the vehicle 110. The timer 120 segments the scheduled task by creating a stage task execution class, that is, the target task is divided into multiple stages for execution. After the execution of the previous stage task, if the scheduled task has not been completed, the attribute value is queried before the execution of the next stage task. If it is an interrupt attribute, the task is interrupted. The attribute status is automatically detected at the transition point of each stage, thereby realizing the staged execution and automatic cancellation of the scheduled task, and ensuring the timely and effective interruption of the scheduled task.

[0030] See also Figure 2 , Figure 2 is a flowchart of a timed task interruption method shown in an exemplary embodiment of the present application. The method can be applied to Figure 1 The implementation environment shown is a schematic diagram. It should be understood that the method may also be applicable to other exemplary implementation environments, and this embodiment does not limit the implementation environment to which the method is applicable.

[0031] Figure 2 As shown, in an exemplary embodiment, the scheduled task interruption method includes at least steps S210 to S240, which are described in detail as follows:

[0032] Step S210, pre-create a stage task execution class, which includes a task cancellation attribute and a process scheduling function.

[0033] Among them, the stage task execution class is used to segment the tasks to be scheduled, execute the tasks at each stage of the scheduled task, and interrupt the scheduled task in a timely and effective manner; the task cancellation attribute is used to mark whether the scheduled task is canceled; the process scheduling function is used to perform task segmentation and task execution.

[0034] See also Figure 3 , Figure 3 FIG. 1 is a schematic diagram of a stage task execution class shown in an exemplary embodiment of the present application. Figure 3As shown, in the phase task execution class PhasedTimer, the attributes include timer attributes and task cancellation attributes, where the timer attribute is a "Timer" type variable named "timer", which is an object used for timing; the task cancellation attribute is an "AtomicBoolean" type variable named "isCancelled", which is a Boolean atomic variable used to mark whether the scheduled task has been canceled. In addition, two methods are included, corresponding to the process scheduling function schedule and the task cancellation function cancel, where schedule accepts three parameters, namely two Long types and one List type, and the return value type is Void, which is used to segment the task and set the scheduled task. The incoming task will be executed at the specified time point; cancel has no parameters, and the return value type is also Void, which is used to cancel the scheduled task that has been set and can interrupt the task being executed.

[0035] Step S220, obtaining the target task to be executed at a scheduled time, and calling the process scheduling function to divide the target task into stages and generate a stage task set.

[0036] Among them, the target task refers to the task to be executed at a certain time; the stage task set includes multiple stage tasks, and each stage task corresponds to an execution function, forming a function set intermediateStages.

[0037] In addition, the target task is divided into multiple execution stages through the process scheduling function schedule, and the number of stages can be customized according to needs.

[0038] Specifically, the process scheduling function is called to divide the target task into stages and generate a stage task set, including: performing a timing type analysis on the target task to determine the target timing type corresponding to the target task, wherein the timing type includes a periodic timing task; judging whether the target timing type is a periodic timing task; if the target task is a periodic timing task, dividing each periodic task in the target task into stages to generate a plurality of first-stage task functions; generating a stage task set according to the plurality of first-stage task functions corresponding to each periodic task, the task period and delay time corresponding to the target task.

[0039] It should be noted that the timer executes some tasks that need to be executed periodically or regularly, namely periodic scheduled tasks and one-time scheduled tasks. Among them, periodic scheduled tasks refer to tasks that are repeatedly executed multiple times at preset time intervals, and one-time scheduled tasks refer to scheduled tasks that are executed only once at a specific time point in the future.

[0040] In this embodiment, if the target task is a periodic scheduled task, each periodic task in the target task must be divided into stages, and then a stage task function is generated for each stage task, and the corresponding stage task is executed by calling the function. Each periodic task refers to a task that is repeatedly executed multiple times according to a preset time interval, that is, each periodic task will be divided into multiple stages, and multiple first-stage task functions are the sum of functions corresponding to multiple stage tasks in each periodic task. For periodic scheduled tasks, in addition to the corresponding delayed execution time, there is also a corresponding interval time between periodic tasks, that is, the task cycle. Therefore, finally, a stage task set is generated according to the multiple first-stage task functions corresponding to each periodic task, the task cycle between periodic tasks, and the delay time.

[0041] In this way, each periodic task in the periodic task is divided into stages, and when each periodic task of the target task is executed, attribute value inquiries can be performed between stage tasks to achieve timely and effective interruption of the executing periodic task.

[0042] In one embodiment, the timing type also includes a one-time timing task; after determining the target timing type corresponding to the target task, it also includes: judging whether the target timing type is a one-time timing task; if the target task is a one-time timing task, dividing the target task into stages and generating multiple second-stage task functions; generating a stage task set according to the delay time corresponding to the multiple second-stage task functions and the target task.

[0043] In this embodiment, if the target task is a one-time scheduled task, the target task is divided into stages, and then a stage task function is generated for each stage task, and the corresponding stage task is executed by calling the function. The multiple second stage task functions are the sum of the functions corresponding to the multiple stage tasks. For a one-time scheduled task, there is a corresponding delayed execution time. Therefore, finally, a stage task set is generated according to the multiple second stage task functions and the delay time.

[0044] In this way, the one-time scheduled task is divided into stages, and when executing the target task, the attribute value query can be performed between the stage tasks, so that the one-time scheduled task being executed can be interrupted in a timely and effective manner.

[0045] In one embodiment, the target task is divided into stages, including: performing a task type analysis on the target task to determine the target task type corresponding to the target task, wherein the task type includes a progress-type task and a duration-type task; if the target task is a progress-type task, the target task is divided into stages according to a preset progress division principle; if the target task is a duration-type task, the target task is divided into stages according to a preset duration division principle.

[0046] It should be noted that a progress-type task refers to a task whose completion time may vary due to various factors. Therefore, the progress of the task is directly described by the execution progress. For example, a task of downloading a song at a scheduled time may have different download completion times due to the real-time network speed. A duration-type task refers to a task that will not have different completion times due to other factors. Therefore, the progress of the task can be described by the execution duration. For example, a scheduled task is video transcoding in local data processing, and it converts video files from one format to another. This process mainly consumes storage resources. When the resources are sufficient and stable, the completion time is almost the same.

[0047] In this embodiment, if the target task is a progress-type task, the target task is divided into stages according to a preset progress division principle, wherein the progress value in the progress division principle can be customized according to the specific situation and needs, for example, divided according to 20%, 40%, 60%, 80%, and 100% of the progress; if the target task is a duration-type task, the target task is divided into stages according to a preset duration division principle, wherein the duration value in the duration division principle can be customized according to the specific situation and needs, for example, divided according to 5S, 10S, 15S, etc.

[0048] In this way, different task types are divided into stages according to different division principles, which makes the stage division more reasonable, thereby enhancing the effect of timely and effective interruption for various tasks.

[0049] It should also be noted that the progress values ​​can be an arithmetic progression or a unequal progression, and the same applies to the duration values. In addition, the settings of the progress values ​​and duration values ​​can be more intensive according to needs, so as to further ensure the timeliness of task interruption.

[0050] Step S230, before executing each stage task in the stage task set, query the attribute value of the task cancellation attribute.

[0051] It should be understood that each stage task in the stage task set is arranged according to the execution order.

[0052] In an embodiment of the present application, before executing each stage task in the stage task set, the attribute value of the task cancellation attribute is queried, wherein the attribute value includes the interrupt attribute true and the execution attribute false. Once the interrupt attribute is detected, the execution of subsequent stage tasks is stopped.

[0053] Specifically, before executing each stage task in the stage task set, the attribute value of the attribute canceled by the query task is included in: between each two stage tasks, the interval time and query frequency are pre-set; if it is monitored that the previous stage task has been completed, the attribute value is queried multiple times according to the query frequency within the interval time until the next stage task starts to be executed.

[0054] In this embodiment, by setting the interval time and query frequency, after monitoring that the previous stage task is completed, the attribute value is queried multiple times according to the query frequency within the interval time until the next stage task starts to be executed. In this way, between the stage tasks, the attribute value is queried multiple times within a certain period of time, which can ensure that the interruption attribute is queried in time, avoid the start of the next stage task, and ensure the timely and effective interruption of the scheduled task.

[0055] In one embodiment, the stage task execution class also includes a task cancellation function; the method for setting the attribute value includes: in response to a received interrupt request, calling the task cancellation function to parse the interrupt request and obtain a task identifier, wherein the interrupt request carries the task identifier; matching the task identifier with the target task identifier corresponding to the target task; if the match is consistent, setting the attribute value to the interrupt attribute; if the match is inconsistent, setting the attribute value to the execution attribute.

[0056] In this embodiment, please continue to see Figure 3 The stage task execution class also includes a task cancellation function. When an interrupt request for a scheduled task is received, it responds to the interrupt request and calls the task cancellation function to parse the interrupt request and obtain the task identifier. It should be noted that the interrupt request carries the task identifier of the scheduled task that needs to be canceled. In addition, the interrupt request can be initiated by the user or by the system. The task identifier is then matched with the target task identifier corresponding to the target task. When the match is consistent, the attribute value is set as the interrupt attribute. In this way, it can be ensured that the interrupted scheduled task is the correct one.

[0057] Step S240: If the attribute value is a preset interrupt attribute, then the unexecuted stage tasks in the stage task set are stopped from being executed.

[0058] When the attribute value is the interrupt attribute, it means that the scheduled task is canceled, and the subsequent stage tasks are immediately controlled to stop executing. In this way, developers do not need to write additional code to handle the cancellation of the executing task, which simplifies the development process. At the same time, the function of automatically canceling the executing task reduces the abnormal risk that may be caused by manually canceling the executing task, and improves the stability and security of the system.

[0059] In one embodiment, stopping the execution of unexecuted stage tasks in the stage task set includes: based on the interrupt attribute, obtaining the unexecuted segmented task function in the stage task set and determining it as the target stage task function; generating an interrupt instruction according to the target segmented task function; executing the interrupt instruction to control the stage task corresponding to the target stage task function to stop execution.

[0060] It should also be noted that in the stage task set, when executing a stage task, the corresponding stage task function is taken out from the set for execution. However, before execution, it is first determined whether the current isCancelled is true. If it is not true, the taken stage task function is executed. If isCancelled is true, all subsequent stage task functions will not be executed.

[0061] In this embodiment, when the attribute value is an interrupt attribute, the unexecuted segmented task function in the stage task set is determined as the target stage task function, so as to generate an interrupt instruction based on the target segmented task function. When the interrupt instruction is executed, the stage task corresponding to the target stage task function is controlled to stop executing, thereby realizing the effective interruption of the scheduled task.

[0062] For example, if the scheduled task is a file download task, the task is divided into four stages: A, B, C, and D. Before executing A, if the query attribute value is false, then continue to execute B. If the query attribute value is true after executing B and before executing C, then immediately stop the stage C that is about to be executed and the unexecuted stage D. In this way, compared with the traditional Timer, PhasedTimer can interrupt the scheduled task that is already being executed, preventing the problem of untimely interruption and thus saving resources.

[0063] See also Figure 4 , Figure 4 FIG. 1 is a flowchart of a specific method for interrupting a timed task as shown in an exemplary embodiment of the present application. Figure 4As shown, first create a stage task execution class; then call the scheduling function, divide the stages according to the target task to be executed regularly, and generate a stage task set; then call the scheduling function again to start the scheduled task; after completing the previous stage task, query whether the task cancellation attribute is an interrupt attribute; if it is not an interrupt attribute, it indicates that the scheduled task has not been cancelled, then determine whether there is an unexecuted stage task function; if there is an unexecuted stage task function, it indicates that the scheduled task has not been completed, then continue to execute the next stage task function, and then continue to query whether the task cancellation attribute is an interrupt attribute; if there is no unexecuted stage task function, it indicates that the scheduled task has been completed, then end; if it is an interrupt attribute, it indicates that the scheduled task has been cancelled, then determine whether there is an unexecuted stage task function; if there is an unexecuted stage task function, it indicates that the scheduled task has not been completed, then stop executing the unexecuted stage task function; if there is no unexecuted stage task function, it indicates that the scheduled task has been completed, then end.

[0064] Nowadays, the entertainment systems in vehicles can play movies and TV series. The following takes the example of downloading TV series by the entertainment system in the vehicle to illustrate how the Timer function in this application can interrupt the scheduled task in a timely and effective manner, as detailed below:

[0065] Assume that a user wants to download 10 episodes of a TV series, and download one episode every minute. The capacity of each episode is 100 MB. Then the scheduled task is a periodic scheduled task and a progress task. The download of each episode of the TV series is regarded as a periodic task. At the same time, each download task can be divided into 5 stages, namely A (0-20 MB), B (21-40 MB), C (41-60 MB), D (61-80 MB), and E (81-100 MB). After starting the download task for a while, the user finds that the TV series is wrong and manually cancels the download task. In this case, the task cancellation attribute will be set to the interrupt attribute. Assume that the first 20 megabytes of the second episode are being downloaded. The traditional Timer cannot be stopped because the task has already started. Even if the user cancels the task, all 100 megabytes of the second episode will be downloaded, resulting in a waste of traffic. In this application, the task isCancelled flag will be read after the 20 megabytes of stage A are completed and before stage B begins. If isCancelled is true at this time, stage B and subsequent stage tasks will not be executed. This allows for more flexible interruption of the scheduled task being executed, saving user data traffic and avoiding unnecessary failures.

[0066] The above-mentioned scheduled task interruption method first pre-creates a stage task execution class, which includes a task cancellation attribute and a process scheduling function, wherein the task cancellation attribute is used to mark whether the scheduled task is cancelled, and then obtains the target task to be scheduled for execution, and divides the target task into stages by calling the process scheduling function to generate a stage task set. Before executing each stage task in the stage task set, the attribute value of the task cancellation attribute is first queried. If the attribute value is an interrupt attribute at this time, the stage task that has not been executed in the stage task set is stopped. The scheduled task is segmented by creating a stage task execution class, that is, the target task is divided into multiple stages for execution. After executing the previous stage task, if the scheduled task has not been completed, the attribute value is queried before executing the next stage task. If it is an interrupt attribute, the task is interrupted. The attribute state is automatically detected at the transition point of each stage, and the staged execution and automatic cancellation of the scheduled task are realized, ensuring the timely and effective interruption of the scheduled task.

[0067] See also Figure 5 , Figure 5 is a block diagram of a timer capable of performing a timed task interruption, as shown in an exemplary embodiment of the present application. The timer can be applied to Figure 1 The implementation environment shown is a timer. It should be understood that the timer may also be applicable to other exemplary implementation environments, and this embodiment does not limit the implementation environment to which the system is applicable.

[0068] like Figure 5 As shown, in an exemplary embodiment, the timer 500 capable of performing timed task interruption includes at least a construction module 510, a phase module 520, a query module 530 and a control module 540, which are described in detail as follows:

[0069] A construction module 510 is used to pre-create a stage task execution class, which includes a task cancellation attribute and a process scheduling function, wherein the task cancellation attribute is used to mark whether the scheduled task is cancelled;

[0070] The phase division module 520 is used to obtain the target task to be executed regularly, and call the process scheduling function to divide the target task into phases to generate a phase task set;

[0071] A query module 530, used for querying the attribute value of the task cancellation attribute before executing each stage task in the stage task set;

[0072] The control module 540 is configured to stop executing unexecuted stage tasks in the stage task set if the attribute value is a preset interrupt attribute.

[0073] It should be noted that the timer capable of interrupting a scheduled task provided in the above embodiment and the scheduled task interruption method provided in the above embodiment belong to the same concept, wherein the contents of the operations performed by each module have been described in detail in the method embodiment and will not be repeated here.

[0074] The present application also provides a vehicle, including a timer capable of interrupting a timed task as described above, or using a timed task interruption method as described above.

[0075] It should be noted that the timer capable of performing a timed task interruption and the timed task interruption method have been described in detail in the timer embodiment and the method embodiment, and will not be repeated here.

[0076] See also Figure 6 , Figure 6 It is a structural schematic diagram of an electronic device provided by an embodiment of the present application. Figure 6 The structure diagram of the computer system suitable for implementing the electronic device of the embodiment of the present application is shown. It should be noted that: Figure 6 The computer system 600 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0077] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 602 or the program loaded from the storage part 608 to the random access memory (RAM) 603, such as executing the method in the above embodiment. In the RAM 603, various programs and data required for system operation are also stored. The CPU 601, the ROM 602 and the RAM 603 are connected to each other through the bus 604. The input / output (I / O) interface 605 is also connected to the bus 604.

[0078] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed so that a computer program read therefrom is installed into the storage section 608 as needed.

[0079] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 609, and / or installed from a removable medium 611. When the computer program is executed by a central processing unit (CPU) 601, various functions defined in the system of the present application are executed.

[0080] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor of a computer, the computer executes the timed task interruption method as described above. The computer-readable storage medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.

[0081] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. This propagated data signal can take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. A computer program contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.

[0082] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0083] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not constitute limitations on the units themselves in some cases.

[0084] The above embodiments are merely illustrative of the principles and effects of the present application, and are not intended to limit the present application. Anyone familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present application. Therefore, all equivalent modifications or changes made by a person of ordinary skill in the art without departing from the spirit and technical ideas disclosed in the present application shall still be covered by the claims of the present application.

Claims

1. A timed task interruption method, characterized in that: The method comprises: Pre-create a stage task execution class, wherein the stage task execution class includes a task cancellation attribute and a process scheduling function, wherein the task cancellation attribute is used to mark whether the scheduled task is cancelled; Obtaining the target task to be executed at a scheduled time, and calling the process scheduling function to divide the target task into stages to generate a stage task set; Before executing each stage task in the stage task set, querying the attribute value of the task cancellation attribute; If the attribute value is a preset interrupt attribute, the execution of the unexecuted stage tasks in the stage task set is stopped.

2. The timed task interruption method according to claim 1, characterized in that: The calling of the process scheduling function, dividing the target task into stages, and generating a stage task set includes: Performing a timing type analysis on the target task to determine a target timing type corresponding to the target task, wherein the timing type includes a periodic timing task; Determine whether the target timing type is the periodic timing task; If the target task is the periodic scheduled task, each periodic task in the target task is divided into stages to generate a plurality of first stage task functions; The stage task set is generated according to the plurality of first stage task functions corresponding to each of the periodic tasks, the task period and delay time corresponding to the target task.

3. The timed task interruption method according to claim 2, characterized in that: The timing type also includes one-time timing tasks; After determining the target timing type corresponding to the target task, the method further includes: Determine whether the target timing type is the one-time timing task; If the target task is the one-time scheduled task, the target task is divided into stages to generate a plurality of second-stage task functions; The stage task set is generated according to the delay times corresponding to the plurality of second-stage task functions and the target task.

4. The timed task interruption method according to claim 1, characterized in that: The step of dividing the target task into stages includes: Performing task type analysis on the target task to determine the target task type corresponding to the target task, wherein the task type includes a progress-based task and a duration-based task; If the target task is a progress-type task, the target task is divided into stages according to a preset progress division principle; If the target task is a time-based task, the target task is divided into stages according to a preset time-based division principle.

5. The timed task interruption method according to claim 1, characterized in that: Each of the stage tasks in the stage task set is arranged according to an execution order; Before executing each stage task in the stage task set, querying the attribute value of the task cancellation attribute includes: Between each two stage tasks, an interval time and a query frequency are preset; If it is monitored that the task of the previous stage is completed, the attribute value is queried multiple times at the query frequency within the interval time until the task of the next stage starts to be executed.

6. The timed task interruption method according to any one of claims 1 to 5, characterized in that: The stage task execution class also includes a task cancellation function; The method for setting the attribute value includes: In response to the received interrupt request, calling the task cancellation function to parse the interrupt request to obtain a task identifier, wherein the interrupt request carries the task identifier; Matching the task identifier with a target task identifier corresponding to the target task; If the match is consistent, the attribute value is set as the interrupt attribute; if the match is inconsistent, the attribute value is set as the execution attribute.

7. The timed task interruption method according to claim 6, characterized in that: The stopping of executing the unexecuted stage tasks in the stage task set includes: Based on the interrupt attribute, obtaining the unexecuted segmented task function in the stage task set and determining it as the target stage task function; Generate an interrupt instruction according to the target segment task function; Execute the interrupt instruction to control the stage task corresponding to the target stage task function to stop execution.

8. A timer capable of interrupting a scheduled task, characterized in that: The timer comprises: A construction module is used to pre-create a stage task execution class, wherein the stage task execution class includes a task cancellation attribute and a process scheduling function, wherein the task cancellation attribute is used to mark whether the scheduled task is cancelled; A phased module is used to obtain the target task to be executed regularly, and call the process scheduling function to divide the target task into phases to generate a phase task set; A query module, used for querying the attribute value of the task cancellation attribute before executing each stage task in the stage task set; The control module is used for stopping the execution of the unexecuted stage tasks in the stage task set if the attribute value is a preset interrupt attribute.

9. A vehicle, characterized in that: It comprises the timer capable of performing a timed task interruption as described in claim 8, or uses the timed task interruption method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the timed task interruption method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Test task scheduling method and device and electronic equipment

    CN110287008A

  • Timed task running method and device, and computer equipment

    CN113886049A

  • Batch task processing method, device, equipment, system, medium and program product

    CN116737339A