Timing task continuous operation method and device, equipment, storage medium and program product
By recording timestamps and monitoring changes in page visibility in financial web applications, and pausing and restarting timers for time compensation, the problem of task interruption caused by page switching in browser timers is solved, thus achieving the continuity and accuracy of scheduled tasks.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-22
- Publication Date
- 2026-04-03
AI Technical Summary
In existing financial web applications, browser timers are prone to slowing down or freezing when users switch tabs or minimize windows, which makes it impossible to guarantee the continuity and accuracy of scheduled tasks, resulting in transaction interruptions and data update delays.
By recording timestamps and listening for changes in page visibility, pausing and restarting timers, and performing time compensation, the system ensures that scheduled tasks run continuously during page transitions.
It ensures the continuity and accuracy of scheduled tasks on the macro timeline, prevents cumulative drift of scheduled tasks caused by page switching, and ensures the stability of web applications and the continuity of transactions.
Smart Images

Figure CN121785731A_ABST
Abstract
Description
Technical Field
[0001] This disclosure can be applied to the financial sector, and more specifically relates to a method, apparatus, device, storage medium, and program product for continuous operation of timed tasks. Background Technology
[0002] In the current financial sector, web applications heavily rely on browser timers to automatically poll critical tasks such as market data updates and fund synchronization.
[0003] However, when users switch tabs or minimize windows, browsers reduce or freeze timers on background pages to conserve resources, leading to significant delays and accumulated errors in financial data updates. When users return to the trading interface, transactions may be interrupted due to session keep-alive failure. Existing technologies cannot guarantee both resource efficiency and the continuity and accuracy of scheduled tasks across a macro timeline, which has become a key issue limiting the user experience and reliability of financial web applications. Summary of the Invention
[0004] In view of the above problems, this disclosure provides a method, apparatus, device, storage medium and program product for continuous operation of timed tasks.
[0005] According to a first aspect of this disclosure, a method for continuous execution of a scheduled task is provided, comprising: initializing a target timer set in the original page in response to a user's operation of opening an original page; triggering the start of the target timer according to a scheduled task request corresponding to the user's target operation in the original page, and recording a first timestamp at the time of triggering as the base time of the scheduled task; pausing the execution of the target timer and recording the current second timestamp when the original page is detected to have switched to the target page based on a preset monitoring tool; restarting the execution of the target timer and recording the current third timestamp when the target page is detected to have switched back to the original page and the target timer is in a state awaiting compensation; and performing time compensation on the target timer according to the time difference between the second timestamp and the third timestamp, so that the scheduled task can run continuously.
[0006] According to embodiments of this disclosure, monitoring is performed based on a preset monitoring tool, including: determining the switch between the original page and the target page through a preset visibility change event; wherein, when the state of the visible file in the handling function of the visibility change event is detected as hidden, it is determined that the original page is switched to the target page; when the state of the visible file in the handling function of the visibility change event is detected as visible, it is determined that the target page is switched to the original page.
[0007] According to embodiments of this disclosure, when the original page is switched to the target page, the original page is invisible; when the target page is switched to the original page, the original page is visible.
[0008] According to embodiments of this disclosure, in response to a user opening an original page, initializing a target timer set in the original page includes: in response to a user opening an original page, initializing an initial timer state management object and configuring the basic parameters of the initial timer, wherein the initial timer does not start a periodic timer task; registering a page visibility listener for the initial timer after configuring the basic parameters to obtain the target timer.
[0009] According to embodiments of this disclosure, time compensation is performed on a target timer based on the time difference between a second timestamp and a third timestamp, including: calculating the time difference between the second timestamp and the third timestamp and using it as a pause duration; and compensating for the next predetermined trigger time of the target timer in advance based on the pause duration.
[0010] According to embodiments of this disclosure, the next predetermined trigger time of the target timer is compensated in advance, including: obtaining the original interval duration of the target timer; subtracting the pause duration from the original interval duration to obtain the adjusted interval duration; and resetting the target timer based on the adjusted interval duration.
[0011] According to an embodiment of this disclosure, after restarting the target timer, the method further includes: calculating the virtual duration elapsed since the target timer was started based on the first timestamp, the third timestamp, and the original interval duration of the target timer; and, if it is determined that the virtual duration exceeds one or more timer task cycles, executing the expired timer task and updating the trigger time of the next timer task.
[0012] A second aspect of this disclosure provides a device for continuous operation of a scheduled task, comprising: an initialization module for initializing a target timer set in the original page in response to a user's operation of opening the original page; a first timestamp recording module for triggering the start of the target timer based on the scheduled task request corresponding to the user's target operation in the original page, and recording the first timestamp at the time of triggering as the base time of the scheduled task; a monitoring module for pausing the operation of the target timer and recording the current second timestamp when the original page is detected to have switched to the target page, based on a preset monitoring tool; and restarting the operation of the target timer and recording the current third timestamp when the target page is detected to have switched back to the original page and the target timer is in a state awaiting compensation; and a time compensation module for compensating the target timer based on the time difference between the second timestamp and the third timestamp, so that the scheduled task can run continuously.
[0013] A third aspect of this disclosure provides an electronic device comprising: one or more processors; and a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the method described above.
[0014] A fourth aspect of this disclosure also provides a computer-readable storage medium having a computer program or instructions stored thereon, which, when executed by a processor, implement the steps of the above-described method.
[0015] The fifth aspect of this disclosure also provides a computer program product, including a computer program or instructions that, when executed by a processor, implement the steps of the above-described method. Attached Figure Description
[0016] The foregoing contents, as well as other objects, features, and advantages of this disclosure, will become clearer from the following description of embodiments with reference to the accompanying drawings, in which:
[0017] Figure 1 This diagram illustrates an application scenario of a timed task continuous execution method according to an embodiment of the present disclosure.
[0018] Figure 2 A flowchart illustrating a method for continuous execution of a timed task according to an embodiment of the present disclosure is shown schematically.
[0019] Figure 3 A flowchart illustrating the initialization of a target timer according to an embodiment of the present disclosure is shown schematically;
[0020] Figure 4 A flowchart illustrating time compensation for a target timer according to an embodiment of the present disclosure is shown schematically;
[0021] Figure 5 A flowchart illustrating the updating of the trigger time of the next timed task according to an embodiment of the present disclosure is shown schematically;
[0022] Figure 6 A schematic diagram illustrating a structural block diagram of a timed task continuous operation apparatus according to embodiments of the present disclosure; and
[0023] Figure 7 A block diagram schematically illustrates an electronic device suitable for implementing a method for continuous operation of a timed task according to an embodiment of the present disclosure. Detailed Implementation
[0024] The embodiments of the present disclosure will now be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the disclosure. In the following detailed description, numerous specific details are set forth to provide a thorough understanding of the embodiments of the present disclosure for ease of explanation. However, it will be apparent that one or more embodiments may be practiced without these specific details. Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concepts of the present disclosure.
[0025] In the technical solution disclosed herein, the user information (including but not limited to user personal information, user image information, user device information, such as location information) and data (including but not limited to data used for analysis, stored data, and displayed data) involved are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, storage, use, processing, transmission, provision, disclosure, and application of related data all comply with relevant laws, regulations, and standards, and necessary measures have been taken to ensure that they do not violate public order and good morals. Corresponding operation entry points are provided for users to choose to authorize or refuse.
[0026] It should be noted that in the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, it does not mean that the applicant has used or necessarily used the solution.
[0027] In scenarios involving automated decision-making using personal information, the methods, devices, and systems provided in this disclosure all offer users corresponding entry points for choosing to agree to or reject the automated decision-making results. If the user chooses to reject, the process proceeds to the expert decision-making stage. Here, "automated decision-making" refers to the activity of automatically analyzing and evaluating an individual's behavioral habits, interests, or economic, health, and credit status through computer programs, and then making a decision. Here, "expert decision-making" refers to the activity of making decisions by personnel who specialize in a particular field, possess specialized experience, knowledge, and skills, and have reached a certain level of professional expertise.
[0028] The embodiments of this disclosure provide a method for continuous execution of a scheduled task, comprising: initializing a target timer set in the original page in response to a user's operation of opening an original page; triggering the start of the target timer according to the scheduled task request corresponding to the user's target operation in the original page, and recording a first timestamp at the time of triggering as the base time of the scheduled task; pausing the execution of the target timer and recording the current second timestamp when the original page is detected to have switched to the target page based on a preset monitoring tool; restarting the execution of the target timer and recording the current third timestamp when the target page is detected to have switched back to the original page and the target timer is in a state awaiting compensation; and performing time compensation on the target timer according to the time difference between the second timestamp and the third timestamp, so that the scheduled task can run continuously.
[0029] Through the embodiments of this disclosure, the method achieves continuity and accuracy of scheduled tasks on a macro timeline. By employing a closed-loop control mechanism of recording timestamps, pausing, and compensating, it solves the problem of cumulative drift of scheduled tasks caused by browser timer throttling or freezing due to page switching, ensuring the time accuracy of scheduled tasks during long-term operation. Furthermore, this method can intelligently sense changes in the application's operating environment (foreground and background) and make proactive adjustments, enabling web applications that rely on precise scheduled tasks to remain stable even when users frequently switch tabs, preventing transaction interruptions.
[0030] Figure 1 The diagram illustrates an application scenario of a timed task continuous execution method according to an embodiment of the present disclosure.
[0031] like Figure 1 As shown, application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 serves as a medium for providing a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0032] Users can use the first terminal device 101, the second terminal device 102, and the third terminal device 103 to interact with the server 105 via the network 104 to receive or send messages, etc. Various communication client applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).
[0033] The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be various electronic devices with displays and support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0034] Server 105 can be a server that provides various services, such as a backend management server that supports websites browsed by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103 (this is just an example). The backend management server can analyze and process data such as received user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal devices.
[0035] It should be noted that the scheduled task continuous execution method provided in this embodiment can generally be executed by server 105. Correspondingly, the scheduled task continuous execution device provided in this embodiment can generally be located in server 105. The scheduled task continuous execution method provided in this embodiment can also be executed by a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105. Correspondingly, the scheduled task continuous execution device provided in this embodiment can also be located in a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105.
[0036] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0037] The following will be based on Figure 1 The described scene, through Figures 2-5 The method for continuous execution of timed tasks according to the disclosed embodiments is described in detail.
[0038] Figure 2 A flowchart illustrating a method for continuous execution of a timed task according to an embodiment of the present disclosure is shown schematically.
[0039] like Figure 2 As shown, the method for continuous execution of a timed task may further include operations S210 to S240.
[0040] In operation S210, in response to the user's operation of opening the original page, the target timer set in the original page is initialized.
[0041] In the embodiments of this disclosure, a timed task is generated when a user opens a web page and submits a form (or performs other operations on the page). This timed task is executed by a timer, and can be, for example, a task such as sending a verification code during a countdown to a target timer. The continuous execution of this timed task is described in detail below.
[0042] Figure 3 A flowchart illustrating the initialization of a target timer according to an embodiment of the present disclosure is shown schematically.
[0043] like Figure 3 As shown, in the embodiments of this disclosure, in response to the user's operation of opening the original page, the initialization of the target timer set in the original page may further include operations S310 to S320.
[0044] When operating S310, in response to the user's operation of opening the original page, an initial timer state management object is initialized and the basic parameters of the initial timer are configured. The initial timer does not start periodic timed tasks.
[0045] In embodiments of this disclosure, in response to a user opening a web page, a centralized data container is established to manage the entire lifecycle state of the timer, rather than immediately starting a periodic timed task.
[0046] Specifically, when a user opens a web page, an initial timer state management object is created, and a series of basic parameter properties are configured for this object. For example, the execution cycle of the scheduled task is defined, and the timer is explicitly marked as being in the "not running" initial state.
[0047] In the S320 operation, a page visibility listener is registered for the initial timer after configuring the basic parameters, and the target timer is obtained.
[0048] In embodiments of this disclosure, to enable the initial timer to sense changes in its runtime environment (whether the page is on the front end or back end), this embodiment registers the initial timer with a page visibility listener to obtain the target timer.
[0049] Specifically, a page visibility listener is registered, and the event handler for that event is logically bound to the previously created state management object. This function will call subsequently defined functions based on the file's visibility status, enabling the timer to start and pause. Thus, a target timer integrating state management and environment awareness is initialized and ready to be started, awaiting a user-defined action (such as clicking a button) to trigger its initial startup.
[0050] Through the embodiments of this disclosure, on-demand startup is achieved by only building the management framework and registering listeners during the initialization phase, without starting the actual scheduled tasks. This avoids unnecessary resource consumption when the user has no intention of using the service, while ensuring that a scheduled service with intelligent compensation capabilities can be provided immediately when the user needs it.
[0051] In operation S220, based on the scheduled task request corresponding to the user's target operation within the original page, the target timer is triggered and the first timestamp of the trigger is recorded as the base time of the scheduled task.
[0052] In the embodiments of this disclosure, a target timer is triggered to run a scheduled task based on a user's target action request on a web page. Here, it is understood that the target action refers to an interactive behavior performed by the user on the page with a clear intention to initiate a scheduled task.
[0053] For example, clicking the button triggers a 60-second countdown to send a verification code; this 60-second countdown is a scheduled task. Furthermore, at this moment, the target timer starts, and at the exact instant of its start, it acquires and stores the current timestamp. This timestamp serves as the base time for the entire system, and all subsequent times are based on this base time.
[0054] When operating S230, based on the preset monitoring tool, if the original page is detected to switch to the target page, the target timer is paused and the current second timestamp is recorded; if the target page is detected to switch back to the original page and the target timer is in a state of pending compensation, the target timer is restarted and the current third timestamp is recorded.
[0055] In embodiments of this disclosure, monitoring is performed using a preset monitoring tool, including: determining the switch between the original page and the target page based on preset visibility change events. Specifically, when the visibility file's state is found to be hidden in the visibility change event handler, the original page is determined to switch to the target page. When the visibility file's state is found to be visible in the visibility change event handler, the target page is determined to switch to the original page.
[0056] Understandably, based on the preset page visibility listener, the switch between the original page and the target page is determined by the visibility change event being listened to.
[0057] Specifically, upon detecting a switch from the original page to the target page, the target timer is paused and the current second timestamp is recorded. This page switch is detected by checking if the visibility file is hidden in the visibility change event handler, thus determining that the original page has switched to the target page. At this point, the target timer is paused and the current time is recorded as the second timestamp.
[0058] For example, when a user clicks a button on a web page (i.e., the original page) to send a verification code after a 60-second countdown, during which the user switches the webpage to the background and switches to another news page (i.e., the target page), the original page is invisible. The target timer is paused and the current time is recorded as the second timestamp.
[0059] Understandably, at this point, the page visibility listener detects that the original page is in an invisible state (i.e., a hidden state), and determines that the page is switching from the original page to the target page.
[0060] Furthermore, upon detecting a switch from the target page to the original page and the target timer being in a pending compensation state, the target timer is restarted and the current third timestamp is recorded. It's understandable that the page switch is detected by checking if the visibility file status is visible in the visibility change event handler, thus determining that the target page has switched to the original page. At this point, the target timer's scheduled task is not yet complete and needs to continue; therefore, the target timer is restarted and the current time is recorded as the third timestamp.
[0061] For example, when a user switches to the news page (i.e., the target page) and then switches back to the web page (i.e., the original page), in order to continue the 60-second countdown on the web page, the target timer will change from a paused state to a restarted state and record the restart time as a third timestamp. It can be understood that at this point, the page visibility listener detects that the original page is visible, determining that the page has switched from the target page to the original page.
[0062] By using the browser's native visibility change events and the state of the visibility file to make judgments, the misjudgments and ambiguities that may occur during monitoring are effectively prevented, and accurate detection of the page visibility state is achieved.
[0063] In operation S240, time compensation is performed on the target timer based on the time difference between the second and third timestamps to ensure that the timed task runs continuously.
[0064] Figure 4A flowchart illustrating time compensation for a target timer according to an embodiment of the present disclosure is shown schematically.
[0065] like Figure 4 As shown, in the embodiments of this disclosure, time compensation for the target timer based on the time difference between the second timestamp and the third timestamp may further include operations S410 to S420.
[0066] In operation S410, the time difference between the second and third timestamps is calculated and used as the pause duration.
[0067] Specifically, based on the above, the second timestamp is the precise time when the timer was paused, and the third timestamp is the precise time when the timer resumed operation. By calculating the difference between these two timestamps, the precise pause duration can be obtained. This duration represents the time during which the progress of the scheduled task was halted due to the original page being invisible.
[0068] When operating S420, the next scheduled trigger time of the target timer is compensated in advance based on the pause duration.
[0069] For example, when the target page switches to the original page, the scheduled task restarts. In order to ensure that the target timer's scheduled task can run continuously, the time that was interrupted due to the page switch, i.e. the original page is not visible, is compensated for in the subsequent triggering time of the target timer.
[0070] For example, for a 60-second countdown timer task, when the original page is switched to the target page, the target timer is paused and the current time is recorded as the second timestamp of 15 seconds. When the target page is switched back to the original page and the target timer is in a state of waiting for compensation, the target timer is restarted and the current third timestamp is recorded as 30 seconds. The pause duration can be calculated to be 15 seconds.
[0071] Furthermore, when the target timer is restarted, its trigger time is advanced accordingly, specifically by 15 seconds. This ensures that a 60-second countdown timer will not experience a wait longer than 60 seconds due to page switching.
[0072] Through the embodiments of this disclosure, lost time is recovered by advancing the next trigger time. This mechanism, unlike simple resets or postponements, is key to achieving continuous rather than intermittent operation, ensuring the macroscopic continuity of the task cycle.
[0073] In another embodiment of this disclosure, the next predetermined trigger time of the target timer is compensated in advance, including: obtaining the original interval duration of the target timer; subtracting the pause duration from the original interval duration to obtain the adjusted interval duration; and resetting the target timer based on the adjusted interval duration.
[0074] For example, if the target timer executes by following the original fixed period when completing the timed task, after calculating the pause duration, in order to compensate the target timer for the next time at the predetermined trigger time (i.e., based on the original fixed period), the original fixed period is subtracted from the pause duration to obtain the adjusted interval duration.
[0075] Furthermore, when the target timer is restarted, it will not execute on the original fixed period, but will only wait for the adjusted interval before executing the next task.
[0076] Understandably, proactively adjusting the original fixed period of the target timer can offset the pause time that has already occurred by shortening the next waiting period, thus ensuring that the target timer's scheduled tasks are executed as scheduled as possible.
[0077] In another embodiment of this disclosure, if the target timer executes according to the original fixed cycle when completing its scheduled task, and the time the original page spends processing the invisible state (i.e., the target timer pause time) is too long, compensating for the next cycle in advance may not be sufficient, potentially missing more than one task execution. Based on this, this embodiment proposes calculating a virtual duration to simulate how many tasks should have been executed if the timer had been running continuously in the foreground, and then recovering these expired tasks all at once to ensure data integrity. A detailed description follows.
[0078] Figure 5 A flowchart illustrating the updating of the trigger time of the next timed task according to an embodiment of the present disclosure is shown.
[0079] like Figure 5 As shown, in the embodiments of this disclosure, after restarting the operation of the target timer, operations S510 to S520 may be further included.
[0080] In operation S510, the virtual duration elapsed since the target timer was started is calculated based on the first timestamp, the third timestamp, and the original interval duration of the target timer.
[0081] When operating S520, if it is determined that the virtual duration exceeds one or more scheduled task cycles, the expired scheduled task is executed and the trigger time of the next scheduled task is updated.
[0082] Specifically, based on the first and third timestamps determined above, the virtual duration is calculated. By calculating the number of tasks that should theoretically be executed within the virtual duration and comparing it with the actual number of tasks executed, it is determined whether one or more complete task cycles have been missed within the virtual duration.
[0083] Furthermore, if it is determined that the virtual duration exceeds one or more scheduled task cycles, the expired scheduled tasks are executed. After all expired tasks are executed, the next scheduled time is reset to the correct future time point, instead of immediately following the last reissued task to update the trigger time of the next scheduled task.
[0084] The embodiments disclosed herein ensure that all tasks that should have been triggered during the period are not lost, even after a long pause, greatly enhancing the continuity, robustness, and data reliability of scheduled tasks.
[0085] Based on the above-described method for continuous execution of scheduled tasks, this disclosure also provides a device for continuous execution of scheduled tasks. The following will be combined with... Figure 6 The device is described in detail.
[0086] Figure 6 A schematic block diagram of a timed task continuous operation apparatus according to an embodiment of the present disclosure is shown.
[0087] like Figure 6 As shown, the timed task continuous operation device 600 of this embodiment includes an initialization module 610, a first timestamp recording module 620, a monitoring module 630, and a time compensation module 640.
[0088] The initialization module 610 is used to initialize the target timer set in the original page in response to the user's operation of opening the original page. In one embodiment, the initialization module 610 can be used to perform the operation S210 described above, which will not be repeated here.
[0089] The first timestamp recording module 620 is used to trigger the start of a target timer based on the timed task request corresponding to the user's target operation within the original page, and record the first timestamp at the time of triggering as the base time of the timed task. In one embodiment, the first timestamp recording module 620 can be used to execute the operation S220 described above, which will not be repeated here.
[0090] The monitoring module 630 is used, based on a preset monitoring tool, to pause the execution of the target timer and record the current second timestamp when it detects that the original page has switched to the target page; and to restart the execution of the target timer and record the current third timestamp when it detects that the target page has switched back to the original page and the target timer is in a state awaiting compensation. In one embodiment, the monitoring module 630 can be used to perform the operation S230 described above, which will not be repeated here.
[0091] The time compensation module 640 is used to compensate the target timer based on the time difference between the second and third timestamps, so that the timed task can run continuously. In one embodiment, the time compensation module 640 can be used to perform the operation S240 described above, which will not be repeated here.
[0092] In embodiments of this disclosure, the initialization module 610 includes a basic parameter configuration submodule and a registration submodule.
[0093] The basic parameter configuration submodule is used to initialize an initial timer state management object in response to the user's opening of the original page, and to configure the basic parameters of the initial timer. The initial timer does not start periodic timed tasks. In one embodiment, the basic parameter configuration submodule can be used to perform the operation S310 described above, which will not be repeated here.
[0094] The registration submodule is used to register a page visibility listener for the initial timer after configuring basic parameters, thereby obtaining the target timer. In one embodiment, the registration submodule can be used to perform the operation S320 described above, which will not be repeated here.
[0095] In embodiments of this disclosure, the time compensation module 640 includes a pause duration determination submodule and a compensation submodule.
[0096] The pause duration determination submodule is used to calculate the time difference between the second and third timestamps, and use it as the pause duration. In one embodiment, the pause duration determination submodule can be used to perform the operation S410 described above, which will not be repeated here.
[0097] The compensation submodule is used to advance the next predetermined trigger time of the target timer based on the pause duration. In one embodiment, the compensation submodule can be used to perform the operation S420 described above, which will not be repeated here.
[0098] In embodiments of this disclosure, the timed task continuous operation device 600 further includes an update module, which includes a virtual duration calculation submodule and an update submodule.
[0099] The virtual duration calculation submodule is used to calculate the virtual duration elapsed since the target timer was started, based on the first timestamp, the third timestamp, and the original interval duration of the target timer. In one embodiment, the virtual duration calculation submodule can be used to perform the operation S510 described above, which will not be repeated here.
[0100] The update submodule is used to execute expired scheduled tasks and update the trigger time of the next scheduled task when it is determined that the virtual duration exceeds one or more scheduled task cycles. In one embodiment, the update submodule can be used to perform the operation S520 described above, which will not be repeated here.
[0101] According to embodiments of this disclosure, any plurality of modules of the initialization module 610, the first timestamp recording module 620, the monitoring module 630, and the time compensation module 640 can be combined into one module, or any one of these modules can be split into multiple modules. Alternatively, at least part of the functionality of one or more of these modules can be combined with at least part of the functionality of other modules and implemented in one module. According to embodiments of this disclosure, at least one of the initialization module 610, the first timestamp recording module 620, the monitoring module 630, and the time compensation module 640 can be at least partially implemented as hardware circuitry, such as a field-programmable gate array (FPGA), a programmable logic array (PLA), a system-on-a-chip, a system-on-a-substrate, a system-on-package, an application-specific integrated circuit (ASIC), or implemented in hardware or firmware by any other reasonable means of integrating or packaging the circuitry, or implemented in any one of the three implementation methods of software, hardware, and firmware, or in a suitable combination of any of these. Alternatively, at least one of the initialization module 610, the first timestamp recording module 620, the listening module 630, and the time compensation module 640 can be implemented at least partially as a computer program module, which can perform corresponding functions when the computer program module is run.
[0102] Figure 7 A block diagram schematically illustrates an electronic device suitable for implementing a method for continuous operation of a timed task according to an embodiment of the present disclosure.
[0103] like Figure 7As shown, an electronic device 700 according to an embodiment of the present disclosure includes a processor 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage portion 707 into a random access memory (RAM) 703. The processor 701 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 701 may also include onboard memory for caching purposes. The processor 701 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.
[0104] RAM 703 stores various programs and data required for the operation of electronic device 700. Processor 701, ROM 702, and RAM 703 are interconnected via bus 704. Processor 701 performs various operations of the method flow according to embodiments of the present disclosure by executing programs in ROM 702 and / or RAM 703. It should be noted that programs may also be stored in one or more memories other than ROM 702 and RAM 703. Processor 701 may also perform various operations of the method flow according to embodiments of the present disclosure by executing programs stored in one or more memories.
[0105] According to embodiments of this disclosure, the electronic device 700 may further include an input / output (I / O) interface 705, which is also connected to a bus 704. The electronic device 700 may also include one or more of the following components connected to the I / O interface 705: an input section 706 including a keyboard, mouse, etc.; an output section 707 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 707 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 710 as needed so that computer programs read from it can be installed into the storage section 707 as needed.
[0106] This disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The computer-readable storage medium carries one or more programs that, when executed, implement the method according to the embodiments of this disclosure.
[0107] According to embodiments of this disclosure, the computer-readable storage medium can be a non-volatile computer-readable storage medium, such as including, but not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this disclosure, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to embodiments of this disclosure, the computer-readable storage medium may include ROM 702 and / or RAM 703 and / or one or more memories other than ROM 702 and RAM 703 described above.
[0108] Embodiments of this disclosure also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowchart. When the computer program product is run on a computer system, the program code is used to cause the computer system to implement the methods provided in the embodiments of this disclosure.
[0109] When the computer program is executed by the processor 701, it performs the functions defined in the system / apparatus of this disclosure embodiments. According to embodiments of this disclosure, the systems, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0110] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of signals over a network medium, and may be downloaded and installed via the communication section 709, and / or installed from a removable medium 711. The program code contained in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination thereof.
[0111] In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 709, and / or installed from the removable medium 711. When the computer program is executed by the processor 701, it performs the functions defined in the system of this disclosure embodiment. According to embodiments of this disclosure, the systems, devices, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0112] According to embodiments of this disclosure, program code for executing the computer programs provided in embodiments of this disclosure can be written in any combination of one or more programming languages. Specifically, these computational programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, languages such as Java, C++, Python, "C", or similar programming languages. The program code can execute entirely on a user's computing device, partially on a user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0113] 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 disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing 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, may 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.
[0114] Those skilled in the art will understand that the features described in the various embodiments of this disclosure can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in this disclosure. In particular, the features described in the various embodiments of this disclosure can be combined and / or combined in various ways without departing from the spirit and teachings of this disclosure. All such combinations and / or combinations fall within the scope of this disclosure.
[0115] The embodiments of this disclosure have been described above. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of this disclosure. Although various embodiments have been described above, this does not mean that the measures in the various embodiments cannot be used advantageously in combination. Various substitutions and modifications can be made by those skilled in the art without departing from the scope of this disclosure, and all such substitutions and modifications should fall within the scope of this disclosure.
Claims
1. A method for continuous execution of a timed task, characterized in that, The method includes: In response to the user opening the original page, the target timer set in the original page is initialized; Based on the scheduled task request corresponding to the user's target operation within the original page, the target timer is triggered and the first timestamp at the trigger time is recorded as the base time of the scheduled task. Based on the preset monitoring tool, when the original page is detected to have switched to the target page, the execution of the target timer is paused and the current second timestamp is recorded; when the target page is detected to have switched back to the original page and the target timer is in a state of pending compensation, the execution of the target timer is restarted and the current third timestamp is recorded. The target timer is time-compensated based on the time difference between the second and third timestamps so that the timed task runs continuously.
2. The method for continuous execution of a timed task according to claim 1, characterized in that, The monitoring based on the preset monitoring tool includes: The switching between the original page and the target page is determined by a preset visibility change event; Specifically, when the visibility file is found to be hidden in the visibility change event handler, the original page is switched to the target page; when the visibility file is found to be visible in the visibility change event handler, the target page is switched to the original page.
3. The method for continuous execution of a timed task according to claim 2, characterized in that, When the original page is switched to the target page, the original page is invisible; when the target page is switched back to the original page, the original page is visible.
4. The method for continuous operation of a timed task according to claim 1 or 2, characterized in that, The initialization of the target timer set in the original page in response to the user's operation of opening the original page includes: In response to the user's action of opening the original page, an initial timer state management object is initialized and the basic parameters of the initial timer are configured. The initial timer does not start periodic timed tasks. Register a page visibility listener for the initial timer after configuring the basic parameters to obtain the target timer.
5. The method for continuous operation of a timed task according to claim 1, characterized in that, The step of time compensation for the target timer based on the time difference between the second and third timestamps includes: Calculate the time difference between the second and third timestamps and use it as the pause duration; Based on the pause duration, the next scheduled trigger time of the target timer is compensated in advance.
6. The method for continuous execution of a timed task according to claim 5, characterized in that, The advance compensation for the next predetermined trigger time of the target timer includes: Obtain the original interval duration of the target timer; The adjusted interval duration is obtained by subtracting the pause duration from the original interval duration. The target timer is reset based on the adjusted interval duration.
7. The method for continuous operation of a timed task according to claim 1, characterized in that, After restarting the target timer, the method further includes: Based on the first timestamp, the third timestamp, and the original interval duration of the target timer, the virtual duration elapsed since the target timer was started is calculated; If it is determined that the virtual duration exceeds one or more scheduled task cycles, the expired scheduled task is executed, and the trigger time of the next scheduled task is updated.
8. A timed task continuous operation device, characterized in that, The device includes: An initialization module is used to initialize a target timer set in the original page in response to a user's operation of opening the original page; The first timestamp recording module is used to trigger the start of the target timer based on the timed task request corresponding to the user's target operation in the original page, and record the first timestamp of the trigger as the base time of the timed task. The monitoring module is used to pause the execution of the target timer and record the current second timestamp when the original page is detected to have switched to the target page, based on a preset monitoring tool; and to restart the execution of the target timer and record the current third timestamp when the target page is detected to have switched back to the original page and the target timer is in a state of pending compensation. The time compensation module is used to compensate the target timer based on the time difference between the second timestamp and the third timestamp, so that the timed task can run continuously.
9. An electronic device, comprising: One or more processors; Memory, used to store one or more computer programs. The characteristic feature is that the one or more processors execute the one or more computer programs to implement the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program or instructions stored thereon, characterized in that, When the computer program or instructions are executed by a processor, they implement the steps of the method according to any one of claims 1 to 7.
11. A computer program product, comprising a computer program or instructions, characterized in that, When the computer program or instructions are executed by a processor, they implement the steps of the method according to any one of claims 1 to 7.