Timed task interrupt method, timer, vehicle and storage medium
By creating staged task execution classes in the scheduled task and querying the cancellation attribute before each staged task, the problem of not being able to interrupt scheduled tasks in a timely manner in the existing technology is solved, realizing the automatic cancellation of scheduled tasks and improving system stability.
Patent Information
- Application Number
- CN202410935535.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-12
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2044-07-12
AI Technical Summary
Existing technologies cannot effectively and promptly interrupt ongoing scheduled tasks, leading to increased development complexity and risks to system stability and security.
By pre-creating phased task execution classes, including task cancellation attributes and process scheduling functions, the target tasks are divided into phases. Before each phase task, the task cancellation attribute is queried. If the interruption attribute is found, the execution of the unfinished phase task is stopped.
It enables timely and effective interruption of scheduled tasks, simplifies the development process, reduces the risk of exceptions caused by manually canceling tasks, and improves system stability and security.
Smart Images

Figure CN118779079B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a timed task interrupt method, a timer, a vehicle, and a storage medium. Background Technology
[0002] In Java, the `java.util.Timer` utility is an advanced timer used to schedule the execution of specified tasks in a background thread. These tasks are designed to be executed periodically or at set intervals, automatically executing based on given times, time intervals, or a predetermined number of executions. Examples include scheduled task scheduling, timed email sending, and timed database update checks. The `Timer` utility includes a `schedule` function, which accepts three parameters: `java.util.TimerTask task` (the specific task to be executed), `long delay` (the delay period before the task begins), and `long period` (the interval between task executions). The `Timer` utility also provides a `cancel` function to cancel timer tasks.
[0003] In related technologies, when calling the `cancel` function to cancel a timer task, if a task has already started executing, the already running task will not be stopped. For example, for a requirement to execute a download task every minute, since downloading is a time-consuming task, some download tasks may still be in progress when the user wants to stop them. In this case, even if the user calls the `cancel` function, they cannot stop the already running download tasks; they can only prevent new download tasks from starting. This leads to: 1. Inability to automatically cancel tasks: Once a task has started, it cannot be automatically canceled and requires manual intervention; 2. Increased development difficulty: Additional code needs to be written to handle task cancellation, increasing development complexity; 3. Potential risks: Manually canceling tasks may cause exceptions during task execution, affecting system stability and security. Summary of the Invention
[0004] In view of the shortcomings of the prior art described above, this application discloses a timed task interruption method, a timer, a vehicle, and a storage medium to solve the technical problem that the prior art cannot interrupt a timed task in a timely and effective manner.
[0005] Firstly, this application provides a method for interrupting a scheduled task. The method includes: pre-creating 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 has been cancelled; 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 interruption attribute, then stopping the execution of the unexecuted stage tasks in the stage task set.
[0006] In one embodiment of this application, the step of calling the process scheduling function to divide the target task into stages and generate a stage task set includes: performing timing type analysis on the target task to determine the target timing type corresponding to the target task, wherein the timing type includes periodic timing tasks; 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 multiple first-stage task functions; and generating the stage task set based on the multiple first-stage task functions corresponding to each periodic task, the task period and delay time corresponding to the target task.
[0007] In one embodiment of this application, the timing type further includes a one-time timing task; after determining the target timing type corresponding to the target task, the method further includes: determining whether the target timing type is the one-time timing task; if the target task is the one-time timing task, then dividing the target task into stages to generate multiple second-stage task functions; and generating the stage task set based on the delay time corresponding to the multiple second-stage task functions and the target task.
[0008] In one embodiment of this application, 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 progress-type tasks and duration-type tasks; if the target task is a progress-type task, then the target task is divided into stages according to a preset progress division principle; if the target task is a duration-type task, then the target task is divided into stages according to a preset duration division principle.
[0009] In one embodiment of this application, each stage task in the stage task set is arranged according to the execution order; the step of querying the attribute value of the task cancellation attribute before executing each stage task in the stage task set includes: pre-setting an interval time and query frequency between every two stage tasks; if it is detected that the previous stage task has been completed, the attribute value is queried multiple times within the interval time according to the query frequency until the next stage task begins to be executed.
[0010] In one embodiment of this application, the stage task execution class further includes a task cancellation function; the method for setting the attribute value includes: in response to a received interruption request, calling the task cancellation function to parse the interruption request and obtain a task identifier, wherein the interruption 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 as the interruption attribute; if the match is inconsistent, setting the attribute value as the execution attribute.
[0011] In one embodiment of this application, stopping the execution of unexecuted stage tasks in the stage task set includes: obtaining unexecuted segmented task functions in the stage task set based on the interrupt attribute, and determining them as target stage task functions; generating an interrupt instruction according to the target segmented task function; and executing the interrupt instruction to control the stage task corresponding to the target stage task function to stop execution.
[0012] Secondly, this application provides a timer capable of interrupting scheduled tasks. The timer includes: a construction module for pre-creating a phased task execution class, wherein the phased 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 has been cancelled; a phased module for obtaining the target task to be executed on a scheduled basis and calling the process scheduling function to divide the target task into phases to generate a phased task set; a query module for querying the attribute value of the task cancellation attribute before executing each phased task in the phased task set; and a control module for stopping the execution of unexecuted phased tasks in the phased task set if the attribute value is a preset interruption attribute.
[0013] Thirdly, this application provides a vehicle characterized by including a timer capable of timed task interruption as described in the second aspect, or using a timed task interruption method as described in the first aspect.
[0014] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by the computer's processor, causes the computer to perform the timed task interrupt method described in the first aspect.
[0015] As described above, the timer, vehicle, and storage medium provided in this application have the following beneficial effects:
[0016] First, a pre-created staged task execution class is established, which includes a task cancellation attribute and a process scheduling function. The task cancellation attribute is used to mark whether the scheduled task has been cancelled. Then, the target task to be executed is obtained, and the target task is divided into stages by calling the process scheduling function to generate a staged task set. Before executing each stage task in the staged task set, the attribute value of the task cancellation attribute is queried. If the attribute value is the interruption attribute, the execution of the unexecuted stage tasks in the staged task set is stopped. By creating a staged task execution class to segment the scheduled task, the target task is divided into multiple stages for execution. After the previous stage task is completed, if the scheduled task is still not completed, the attribute value is queried before executing the next stage task. If the attribute value is the interruption attribute, the task is interrupted. The attribute status is automatically detected at the transition point of each stage, realizing the staged execution and automatic cancellation of scheduled tasks, ensuring timely and effective interruption of scheduled tasks.
[0017] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description
[0018] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort. In the drawings:
[0019] Figure 1 This is a schematic diagram illustrating an implementation environment of a timer capable of interrupting timed tasks, as shown in an exemplary embodiment of this application.
[0020] Figure 2 This is a flowchart illustrating a timed task interruption method in an exemplary embodiment of this application;
[0021] Figure 3 This is a schematic diagram illustrating a staged task execution class, as shown in an exemplary embodiment of this application;
[0022] Figure 4 This is a flowchart illustrating a specific timer task interruption method in an exemplary embodiment of this application;
[0023] Figure 5This is a block diagram illustrating a timer capable of interrupting a timed task, as shown in an exemplary embodiment of this application;
[0024] Figure 6 This is a schematic diagram illustrating the structure of an electronic device according to an exemplary embodiment of this application. Detailed Implementation
[0025] The embodiments of this application will be described below with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. It should be understood that the preferred embodiments are only for illustrating this application and are not intended to limit the scope of protection of this application.
[0026] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this application. Therefore, the illustrations only show the components related to this application and are not drawn according to the number, shape and size of the components in actual implementation. In actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0027] In the following description, numerous details are explored to provide a more thorough explanation of embodiments of the present application. However, it will be apparent to those skilled in the art that embodiments of the present application may be practiced without these specific details. In other embodiments, well-known structures and devices are shown in block diagram form rather than in detail to avoid obscuring embodiments of the present application.
[0028] A Timer is a timer used to schedule the execution of specified tasks in a background thread. These tasks are executed periodically or at set intervals, automatically based on a given time point, a given time interval, or a given number of executions. However, the inventors of this application have discovered that when the cancel function is called to cancel a timer task, if a task has already started executing, the already running task will not be stopped. Even if the cancel function is called, it cannot stop the already executing download task; it only prevents new download tasks from starting. Therefore, existing Timers: 1. cannot automatically cancel tasks after they have started, requiring manual intervention; 2. increase development difficulty, requiring additional code to handle task cancellation, increasing development complexity; 3. pose potential risks, as manual task cancellation may cause exceptions during task execution, affecting system stability and security.
[0029] Therefore, please see Figure 1 , Figure 1 This is a schematic diagram illustrating an implementation environment of a timer capable of timed task interruption, as shown in an exemplary embodiment of this application. Figure 1 As shown, the implementation environment includes a vehicle 110 and a timer 120. The timer 120 is embedded in the vehicle 110 and is used to execute and interrupt the timed tasks in the vehicle 110. The timer 120 divides the timed tasks into segments by creating a staged task execution class, that is, it divides the target task into multiple stages of execution. After the previous stage of the task is completed, if the timed task is still not completed, the attribute value is queried before the next stage of the task is executed. If the attribute value is interrupted, 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 timed tasks, ensuring the timely and effective interruption of the timed tasks.
[0030] Please see Figure 2 , Figure 2 This is a flowchart illustrating a timed task interruption method in an exemplary embodiment of this application. This method can be applied to... Figure 1 The implementation environment shown is intended to illustrate a method that can also be applied to other exemplary implementation environments. This embodiment does not limit the implementation environment to which the method is applicable.
[0031] Figure 2 As shown, in an exemplary embodiment, the timed task interruption method includes at least steps S210 to S240, which are described in detail below:
[0032] Step S210: Pre-create a stage task execution class, which includes task cancellation attributes and process scheduling functions.
[0033] The phased task execution class is used to segment the tasks to be executed on a scheduled basis, execute each phase 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 has been cancelled; and the process scheduling function is used to segment and execute the task.
[0034] Please see Figure 3 , Figure 3 This is a schematic diagram illustrating a staged task execution class, as shown in an exemplary embodiment of this application. Figure 3As shown, the `PhasedTimer` class, which executes staged tasks, includes a timer attribute and a task cancellation attribute. The timer attribute is a variable of type `Timer` named "timer", used to time the task. The task cancellation attribute is an atomic Boolean variable named "isCancelled", used to indicate whether the scheduled task has been cancelled. Additionally, it includes two methods: the process scheduling function `schedule` and the task cancellation function `cancel`. `schedule` accepts three parameters—two `Long` types and one `List` type—and returns a `Void` value. It is used to segment tasks and set scheduled tasks, which will execute at the specified times. `cancel` has no parameters and also returns a `Void` value. It is used to cancel already set scheduled tasks and can interrupt currently executing tasks.
[0035] Step S220: Obtain the target task to be executed at a time, and call 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 time; the stage task set includes multiple stage tasks, and each stage task has a corresponding execution function, forming the function set intermediateStages.
[0037] In addition, the target task can be split into multiple execution stages by using the process scheduling function schedule, and the number of stages can be customized according to requirements.
[0038] Specifically, the process scheduling function is invoked to divide the target task into stages and generate a stage task set, including: analyzing the timing type of the target task to determine the target timing type, where the timing type includes periodic timing tasks; determining 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 multiple first-stage task functions; and generating a stage task set based on the multiple 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 timers execute tasks that need to be performed periodically or at set intervals, namely periodic timed tasks and one-time timed tasks. Periodic timed tasks are tasks that are repeatedly executed multiple times at preset time intervals, while one-time timed tasks are pre-defined tasks that are executed only once at a specific point in the future.
[0040] In this embodiment, if the target task is a periodic timed task, each periodic task within the target task is divided into stages. Each stage task then generates a corresponding stage task function, which is called to execute the corresponding stage task. Each periodic task refers to a task that is repeatedly executed multiple times according to a preset time interval; that is, each periodic task is divided into multiple stages, and the multiple first-stage task functions are the sum of the functions corresponding to the multiple stage tasks within each periodic task. For periodic timed tasks, in addition to the corresponding delay execution time, there is also the interval time between periodic tasks, i.e., the task period. Therefore, finally, a stage task set is generated based on the multiple first-stage task functions corresponding to each periodic task, the task periods between periodic tasks, and the delay time.
[0041] In this way, each periodic task in a periodic task is divided into stages. When executing each periodic task of the target task, attribute values can be queried between the stage tasks, so as to realize timely and effective interruption of the periodic task being executed.
[0042] In one embodiment, the timing type further includes a one-time timing task; after determining the target timing type corresponding to the target task, the method further includes: determining whether the target timing type is a one-time timing task; if the target task is a one-time timing task, then dividing the target task into stages and generating multiple second-stage task functions; and generating a stage task set based on 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 timed task, the target task is divided into stages, and each stage task corresponds to a stage task function. The corresponding stage task is executed by calling the function, and the multiple second-stage task functions are the sum of the functions corresponding to the multiple stage tasks. For one-time timed tasks, there is a corresponding delay time. Therefore, the stage task set is finally generated based on the multiple second-stage task functions and the delay time.
[0044] In this way, one-time scheduled tasks are divided into stages. When the target task is executed, attribute values can be queried between the stages, so as to realize timely and effective interruption of the one-time scheduled task being executed.
[0045] In one embodiment, 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 progress-type tasks and duration-type tasks; if the target task is a progress-type task, then the target task is divided into stages according to a preset progress division principle; if the target task is a duration-type task, then the target task is divided into stages according to a preset duration division principle.
[0046] It should be noted that progress-based tasks refer to tasks whose completion time can vary due to various factors. Therefore, the progress of the task is directly described by the execution progress. For example, a task that downloads a song at a set time will have different completion times due to real-time network speed. Duration-based tasks, on the other hand, refer to tasks whose completion time is not affected by 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, which converts video files from one format to another. This process mainly consumes storage resources, and under conditions of sufficient and stable resources, the completion time is almost the same.
[0047] In this embodiment, if the target task is a progress-based task, the target task is divided into stages according to a preset progress division principle. The progress value in the progress division principle can be customized according to specific circumstances and needs, for example, divided according to 20%, 40%, 60%, 80%, and 100% progress. If the target task is a duration-based task, the target task is divided into stages according to a preset duration division principle. The duration value in the duration division principle can be customized according to specific circumstances and needs, for example, divided according to 5 seconds, 10 seconds, and 15 seconds.
[0048] In this way, different task types are divided into stages according to different division principles, making the stage division more reasonable, and thus enhancing the timely and effective interruption of various tasks.
[0049] It should also be noted that the progress values can be either arithmetic or non-arithmetic sequences, and the same applies to the duration values. In addition, the progress and duration values can be set more densely according to requirements, which can further ensure the timeliness of task interruption.
[0050] Step S230: Before each stage task in the execution stage task set, query the attribute value of the task cancellation attribute.
[0051] It should be understood that each phase task in the phase task set is arranged according to the execution order.
[0052] In this embodiment of the application, before each stage task in the execution stage task set, the attribute value of the task cancellation attribute is queried. The attribute value includes the interruption attribute true and the execution attribute false. Once the interruption attribute is detected, the execution of subsequent stage tasks is stopped.
[0053] Specifically, before each phase task in the execution phase task set, the attribute value of the task cancellation attribute is queried, including: pre-setting the interval time and query frequency between every two phase tasks; if the previous phase task is detected to have been completed, the attribute value is queried multiple times within the interval time according to the query frequency, until the next phase task begins to be executed.
[0054] In this embodiment, by setting the interval time and query frequency, after monitoring that the previous stage task has been completed, the attribute value is queried multiple times within the interval time according to the query frequency until the next stage task starts to be executed. In this way, by querying the attribute value multiple times within a certain period of time between stage tasks, it can be ensured that the interruption attribute is queried in time, and the next stage task is prevented from starting to be executed, thus ensuring the timely and effective interruption of the scheduled task.
[0055] In one embodiment, the stage task execution class further includes a task cancellation function; the method for setting attribute values includes: in response to a received interruption request, calling the task cancellation function to parse the interruption request and obtain a task identifier, wherein the interruption request carries a 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 interruption attribute; if the match is inconsistent, setting the attribute value to the execution attribute.
[0056] In this embodiment, please continue to refer to Figure 3 The stage task execution class also includes a task cancellation function. Upon receiving an interruption request from a scheduled task, it responds to the request by calling the task cancellation function to parse the interruption request and obtain the task identifier. It's important to note that the interruption request carries the task identifier of the scheduled task to be cancelled. Furthermore, the interruption request can be initiated by the user or the system. Then, the task identifier is matched against the target task's identifier. Only when a match is found is the attribute value set to the interrupt attribute. This ensures that the correct scheduled task is interrupted.
[0057] Step S240: If the attribute value is a preset interruption attribute, then stop executing the unexecuted phase tasks in the phase task set.
[0058] When the attribute value is "interrupt," it indicates that the scheduled task has been canceled, and subsequent stage tasks are immediately stopped. This eliminates the need for developers to write additional code to handle the cancellation of tasks in progress, simplifying the development process. Furthermore, the automatic cancellation of tasks in progress reduces the potential risks of errors that might arise from manual cancellation, improving system stability and security.
[0059] In one embodiment, stopping the execution of unexecuted phase tasks in the phase task set includes: obtaining unexecuted segmented task functions in the phase task set based on interrupt attributes, and determining them as target phase task functions; generating interrupt instructions based on target segmented task functions; and executing interrupt instructions to control the phase task corresponding to the target phase task function to stop execution.
[0060] It should also be noted that within the set of stage tasks, when executing a certain stage task, the corresponding stage task function is retrieved from the set for execution. However, before execution, it is first checked whether isCancelled is true. If it is not true, the retrieved stage task function is executed. If isCancelled is true, then no subsequent stage task functions are executed.
[0061] In this embodiment, when the attribute value is an interrupt attribute, the segmented task function that has not been executed in the stage task set is determined as the target stage task function. An interrupt instruction is generated 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 execution. In this way, the effective interruption of the timed task is realized.
[0062] For example, a scheduled task might be a file download task, divided into four stages: A, B, C, and D. Before executing A, if a query attribute is found to be false, then B continues execution. If, after B has finished executing and before C has finished executing, a query attribute is found to be true, then the upcoming C stage and the unexecuted D stage are immediately stopped. In this way, compared to a traditional Timer, PhasedTimer can interrupt a scheduled task that is already running, preventing untimely interruptions and thus saving resources.
[0063] Please see Figure 4 , Figure 4 This is a flowchart illustrating a specific timed task interruption method as shown in an exemplary embodiment of this application. Figure 4As shown, first, a stage task execution class is created; then, the scheduling function is called to divide the target task to be executed into stages and generate a stage task set; next, the scheduling function is called again to start the scheduled task; after the previous stage task is completed, the task cancellation attribute is checked to see if it is an interrupt attribute; if it is not an interrupt attribute, it means that the scheduled task has not been cancelled, so it is checked whether there are any unexecuted stage task functions; if there are any unexecuted stage task functions, it means that the scheduled task has not yet been completed, so the next stage task function is executed, and then the task cancellation attribute is checked again to see if it is an interrupt attribute; if there are no unexecuted stage task functions, it means that the scheduled task has been completed, and the process ends; if it is an interrupt attribute, it means that the scheduled task has been cancelled, so it is checked whether there are any unexecuted stage task functions; if there are any unexecuted stage task functions, it means that the scheduled task has not been completed, so the execution of the unexecuted stage task functions is stopped; if there are no unexecuted stage task functions, it means that the scheduled task has been completed, and the process ends.
[0064] Modern vehicle entertainment systems can play movies and TV shows. The following example, using the download of a TV series on a vehicle's entertainment system, illustrates how the Timer function in this application can effectively and promptly interrupt scheduled tasks. Details are as follows:
[0065] Suppose a user wants to download 10 episodes of a TV series, one episode every minute, with each episode being 100 MB. This scheduled task is both a periodic task and a progress-based task. The download of each episode is considered a periodic task, and each episode can be divided into 5 stages, each 20 MB in size: A (0-20 MB), B (21-40 MB), C (41-60 MB), D (61-80 MB), and E (81-100 MB). If a user discovers they have selected the wrong TV series after a download task has been running for some time and manually cancels the download task, the task cancellation attribute will be set to the interrupt attribute. For example, if the first 20MB of episode 2 is currently downloading, a traditional Timer, because the task is already running, cannot be stopped. Even if the user cancels the task, the entire 100MB of episode 2 will be downloaded, wasting bandwidth. In this application, the `isCancelled` flag is read after the first 20MB of stage A is completed and before stage B begins. If `isCancelled` is true, stage B and subsequent stages will not continue to execute. This allows for more flexible interruption of running scheduled tasks, saving user data and avoiding unnecessary malfunctions.
[0066] The aforementioned method for interrupting scheduled tasks first pre-creates a phased task execution class, which includes a task cancellation attribute and a process scheduling function. The task cancellation attribute is used to mark whether the scheduled task has been cancelled. Then, the target task to be executed is obtained, and the target task is divided into phases by calling the process scheduling function to generate a phased task set. Before executing each phase task in the phased task set, the attribute value of the task cancellation attribute is queried. If the attribute value is the interruption attribute, the execution of the unexecuted phase tasks in the phased task set is stopped. By creating a phased task execution class to segment the scheduled task, the target task is divided into multiple phases for execution. After the previous phase task is completed, if the scheduled task is still not completed, the attribute value is queried before executing the next phase task. If the attribute value is the interruption attribute, the task is interrupted. The attribute status is automatically detected at the transition point of each phase, realizing the phased execution and automatic cancellation of scheduled tasks, ensuring timely and effective interruption of scheduled tasks.
[0067] Please see Figure 5 , Figure 5 This is a block diagram illustrating a timer capable of interrupting a timed task, as shown in an exemplary embodiment of this application. This timer can be applied to... Figure 1 The implementation environment shown is intended to illustrate that the timer can also be applied 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 interrupting a scheduled task includes at least a construction module 510, a phased module 520, a query module 530, and a control module 540, which are described in detail below:
[0069] Module 510 is used to pre-create stage task execution classes, which include task cancellation attributes and process scheduling functions. The task cancellation attribute is used to mark whether the scheduled task has been cancelled.
[0070] The phased module 520 is used to obtain the target task to be executed at a time, and call the process scheduling function to divide the target task into phases and generate a phase task set.
[0071] The query module 530 is used to query the attribute value of the task cancellation attribute before each stage task in the execution stage task set.
[0072] The control module 540 is used to stop the execution of unexecuted phase tasks in the phase task set if the attribute value is a preset interrupt attribute.
[0073] It should be noted that the timer capable of interrupting timed tasks provided in the above embodiments and the timed task interruption method provided in the above embodiments belong to the same concept. The content of the operation performed by each module has been described in detail in the method embodiments, and will not be repeated here.
[0074] This application also provides a vehicle including a timer capable of being interrupted by a timed task as described above, or using a timed task interrupt method as described above.
[0075] It should be noted that the timer and the timer interrupt method that can perform timed task interruption have been described in detail in the timer embodiment and the method embodiment, and will not be repeated here.
[0076] Please see Figure 6 , Figure 6 This is a schematic diagram of the structure of an electronic device provided in one embodiment of this application. Figure 6 A schematic diagram of a computer system suitable for implementing the embodiments of this application is shown. It should be noted that... Figure 6 The computer system 600 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this 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, such as executing the methods described in the above embodiments, based on programs stored in Read-Only Memory (ROM) 602 or programs loaded from Storage Unit 608 into Random Access Memory (RAM) 603. The RAM 603 also stores various programs and data required for system operation. The CPU 601, ROM 602, and RAM 603 are interconnected via a bus 604. An Input / Output (I / O) interface 605 is also connected to the bus 604.
[0078] The following components are connected to I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, 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, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to I / O interface 605 as needed. A removable medium 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 610 as needed so that computer programs read from it can be installed into storage section 608 as needed.
[0079] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 609, and / or installed from removable medium 611. When the computer program is executed by central processing unit (CPU) 601, it performs various functions defined in the system of this application.
[0080] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a computer's processor, causes the computer to perform the timed task interrupt method described above. This computer-readable storage medium may be included in the electronic device described in the above embodiments, or it may exist independently and not assembled into the electronic device.
[0081] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.
[0082] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. Each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0083] The units described in the embodiments of this application can be implemented in software or hardware, and the described units can also be located in a processor. The names of these units do not necessarily limit the specific unit itself.
[0084] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in this application should still be covered by the claims of this application.
Claims
1. A method for interrupting a timed task, characterized in that, The method includes: A stage task execution class is pre-created, which includes a task cancellation attribute and a process scheduling function. The task cancellation attribute is used to mark whether the scheduled task has been cancelled. Obtain the target task to be executed at a time, and call the process scheduling function to divide the target task into stages and generate a stage task set; Before executing each stage task in the stage task set, query the attribute value of the task cancellation attribute; If the attribute value is a preset interruption attribute, then the execution of the unexecuted phase tasks in the phase task set will be stopped; The step of calling the process scheduling function to divide the target task into stages and generate a stage task set includes: performing timing type analysis on the target task to determine the target timing type corresponding to the target task, wherein the timing type includes periodic timing tasks; 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 multiple first-stage task functions; and generating the stage task set based on the multiple first-stage task functions corresponding to each periodic task, the task period and delay time corresponding to the target task.
2. The timed task interruption method according to claim 1, characterized in that, The timing types also include one-time timed 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 timed task; If the target task is a one-time timed task, then the target task is divided into stages to generate multiple second-stage task functions; The stage task set is generated based on the delay time corresponding to the target task and multiple second-stage task functions.
3. The timed task interruption method according to claim 1, characterized in that, The step of dividing the target task into stages includes: The target task is analyzed to determine the target task type, wherein the task type includes progress-based tasks and duration-based tasks. If the target task is a progress-type task, then the target task is divided into stages according to the preset progress division principle; If the target task is a time-based task, then the target task is divided into stages according to the preset time-based division principle.
4. 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 the execution order; The step of querying the attribute value of the task cancellation attribute before executing each stage task in the stage task set includes: Between each pair of described phase tasks, the interval time and query frequency are preset; If the previous stage task is detected to have been completed, the attribute value is queried multiple times within the specified interval according to the specified query frequency until the next stage task begins.
5. The timed task interruption method according to any one of claims 1 to 4, 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 a received interruption request, the task cancellation function is invoked to parse the interruption request and obtain the task identifier, wherein the interruption request carries the task identifier; Match the task identifier with the target task identifier corresponding to the target task; If a match is found, the attribute value is set to the interrupt attribute; if a match is not found, the attribute value is set to the execution attribute.
6. The timed task interruption method according to claim 5, characterized in that, The step of stopping the execution of unexecuted phase tasks in the phase task set includes: Based on the interruption attribute, obtain the unexecuted stage task functions in the stage task set and determine them as target stage task functions; An interrupt instruction is generated based on the target stage task function; Execute the interrupt instruction to stop the execution of the stage task corresponding to the target stage task function.
7. A timer capable of interrupting timed tasks, characterized in that, The timer includes: A construction module is used to pre-create stage task execution classes, which include task cancellation attributes and process scheduling functions. The task cancellation attribute is used to mark whether the scheduled task has been cancelled. The phased module is used to obtain the target task to be executed at a time, and call the process scheduling function to divide the target task into phases and generate a phased task set. The query module is used to query the attribute value of the task cancellation attribute before executing each stage task in the stage task set. The control module is used to stop executing the unexecuted phase tasks in the phase task set if the attribute value is a preset interruption attribute. The phased module is specifically used to perform timing type analysis on the target task, determine the target timing type corresponding to the target task, wherein the timing type includes periodic timing tasks; determine whether the target timing type is the periodic timing task; if the target task is the periodic timing task, then divide each periodic task in the target task into phases to generate multiple first-phase task functions; and generate the phased task set based on the multiple first-phase task functions corresponding to each periodic task, the task cycle and delay time corresponding to the target task.
8. A vehicle, characterized in that, Includes the timer capable of timed task interruption as described in claim 7, or uses the timed task interruption method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, It stores computer-readable instructions that, when executed by the computer's processor, cause the computer to perform the timed task interrupt method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Test task scheduling method and device and electronic equipment
CN110287008A
Timed task running method and device, and computer equipment
CN113886049A