Timer operation method, device, electronic device and storage medium
By grouping and sorting timers, monitoring and executing all timers in the timer set, the problems of increasing timer management difficulty and program lag in the prior art are solved, and the efficiency of timer operation is improved.
Patent Information
- Application Number
- CN202411458954.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-18
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2044-10-18
AI Technical Summary
In the prior art, as the number of business modules increases, the number of task timers that need to be created also increases, resulting in increased difficulty in sorting and managing timers, which may cause program lag.
By grouping multiple timers according to the trigger timestamp of the timer, multiple timers are obtained; sorting the timer set based on the order of the trigger timestamps to obtain a set sequence; monitoring the execution timing of the first timer set in the set sequence according to the execution timestamp, and executing all timers in the timer set when the execution time is satisfied.
By grouping and sorting timers, the number of times to detect the execution time of the timer is reduced, the efficiency of timer operation is improved, and the program is avoided due to excessive timer management.
Smart Images

Figure CN118963976B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a timer operation method, device, electronic device and storage medium. Background Art
[0002] Usually, in an operating system or application, it is necessary to create a large number of task timers and build a timer collection. Each task timer is used to control the scheduling and execution of a function at a certain time point in the future to trigger the execution of a target task.
[0003] The more business modules there are, the more task timers need to be created. In order to trigger the task trigger on time to execute the target task, the prior art performs various management operations on the task timers, including creating a set of task timers to monitor the trigger time of each task timer. By deleting the timed task timers and inserting new task timers, the effect of dynamically adjusting the timer set is achieved. The more task managers are created at the same time, the more difficult it is to sort the task timers. The more task timers are triggered at the same time, the more program jams will occur. Summary of the invention
[0004] One purpose of the present application is to provide a timer operation method, device, electronic device and storage medium to improve the efficiency of timer operation.
[0005] According to one aspect of an embodiment of the present application, a timer operation method is provided, including:
[0006] Grouping the multiple timers according to the trigger timestamps of the timers to obtain multiple timer sets;
[0007] Sorting the plurality of timer sets based on the order of the trigger timestamps to obtain a set sequence;
[0008] monitoring the execution timing of the first timer set in the set sequence according to the execution timestamp, wherein the execution timestamp is used to compare with the trigger timestamp to monitor the execution timing of the timer set;
[0009] When the first-ranked timer set meets the execution timing, all timers in the timer set are executed.
[0010] According to one aspect of an embodiment of the present application, a timer operation device is provided, including:
[0011] A grouping module, used for grouping a plurality of timers according to trigger timestamps of the timers to obtain a plurality of timer sets;
[0012] A sorting module, used to sort the multiple timer sets based on the order of triggering timestamps to obtain a set sequence;
[0013] a detection module, configured to monitor the execution timing of the first timer set in the set sequence according to an execution timestamp, wherein the execution timestamp is used to compare with the trigger timestamp to monitor the execution timing of the timer set;
[0014] The timer execution module is used to execute all timers in the timer set when the first-ranked timer set meets the execution opportunity.
[0015] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device implements the methods provided in the above-mentioned various optional implementation modes.
[0016] According to one aspect of an embodiment of the present application, a computer program medium is provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer executes the methods provided in the above-mentioned various optional implementations.
[0017] According to one aspect of the embodiments of the present application, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the above various optional implementations.
[0018] In the present application, multiple timers are grouped according to the trigger timestamps of the timers to obtain multiple timer sets; based on the order of the trigger timestamps, multiple timer sets are sorted to obtain a set sequence; according to the execution timestamp, the execution timing of the timer set ranked first in the set sequence is monitored, and the execution timestamp is used to compare with the trigger timestamp to monitor the execution timing of the timer set; when the timer set ranked first meets the execution timing, all timers in the timer set are executed. In the present application, timers are divided into multiple timer sets according to the trigger timestamps, and the timer sets are sorted according to the order of the trigger timestamps to obtain a set sequence. Therefore, only the timer set ranked first in the set sequence is used, and the execution timing of the timer set is monitored. By grouping the timers, the number of times the execution timing of the timers is detected is reduced, and the operating efficiency of the timers is improved.
[0019] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.
[0020] It should be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The above and other objects, features and advantages of the present application will become more apparent by describing in detail exemplary embodiments thereof with reference to the attached drawings.
[0022] Figure 1 A schematic diagram of the application environment of the timer operation method of this embodiment is shown.
[0023] Figure 2 A schematic flow chart of a timer operation method according to an embodiment of the present application is shown.
[0024] Figure 3 A schematic structural diagram of a timer operating device according to an embodiment of the present application is shown.
[0025] Figure 4 A schematic structural diagram of an electronic device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0026] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these example embodiments are provided so that the description of the present application will be more comprehensive and complete and the concepts of the example embodiments will be fully conveyed to those skilled in the art. The accompanying drawings are only schematic illustrations of the present application and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.
[0027] In addition, the described features, structures or characteristics may be combined in one or more example embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the example embodiments of the present application. However, those skilled in the art will appreciate that the technical solution of the present application may be practiced while omitting one or more of the specific details, or other methods, components, steps, etc. may be adopted. In other cases, known structures, methods, implementations or operations are not shown or described in detail to avoid obscuring the present application and making the various aspects of the present application obscure.
[0028] Some of the blocks shown in the accompanying drawings are functional entities that do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0029] The timer operation method provided in this embodiment can be applied to Figure 1 In an application environment, a terminal device communicates with a server through a network. The terminal device may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices. The server may be implemented as an independent server or a server cluster consisting of multiple servers.
[0030] The system framework 100 may include a terminal device, a network and a server. The network is used to provide a medium for a communication link between the terminal device and the server. The network may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0031] Users can use terminal devices to interact with the server through the network to receive or send messages, etc.
[0032] Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Eperts Group Audio Layer III), MP4 (Moving Picture Eperts Group Audio Layer IV) players, laptop computers, desktop computers, etc.
[0033] The server 105 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal devices 101 , 102 , and 103 .
[0034] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only illustrative. According to the implementation requirements, there may be any number of terminal devices, networks and servers. The terminal devices in the embodiment of the present invention may specifically correspond to application systems in actual production.
[0035] Figure 2 A schematic diagram of a flow chart of a timer operation according to an embodiment of the present application is shown, and the method comprises the following steps:
[0036] S100, grouping multiple timers according to the trigger timestamps of the timers to obtain multiple timer sets.
[0037] Specifically, grouping the timers means grouping the timers with the same triggering timestamp into one group according to the triggering timestamps of the timers, thereby obtaining a plurality of timer sets.
[0038] The grouping basis of each timer set may be grouping according to time points, and finally a specific number of timer sets are obtained.
[0039] S200, sorting multiple timer sets based on the order of trigger timestamps to obtain a set sequence.
[0040] Specifically, multiple timer sets are sorted according to the sequence of triggering timestamps to obtain a set sequence.
[0041] The trigger timestamp is used to indicate the execution time of the timer. The timer set is sorted in the order of execution time to obtain a set sequence.
[0042] S300: monitor the execution timing of the first timer set in the set sequence according to the execution timestamp, where the execution timestamp is used to compare with the trigger timestamp to monitor the execution timing of the timer set.
[0043] Specifically, the execution timing of the timer set ranked first in the set sequence is detected according to the execution timestamp. The execution timestamp is used to compare with the trigger timestamp to monitor the execution timing of the timer set.
[0044] Specifically, by comparing the execution timestamp with the trigger timestamp, it is determined whether the execution timing of the timer set has been reached.
[0045] Furthermore, the timer sets in the set sequence are sorted based on the order of the trigger timestamps. The execution timestamp indicates the current time, and the trigger timestamp and execution timestamp of the timer set ranked first in the set sequence are the smallest. In the process of monitoring the execution time of the timer set ranked first, if the timer set ranked first does not reach the execution time, it means that the other timer sets in the set sequence have not reached the execution time.
[0046] In this process, only the execution timing of the first-ranked timer set needs to be monitored, and only one timing determination is needed, thereby achieving the effect of efficiently detecting the timer execution timing.
[0047] S400: When the first-ranked timer set meets the execution timing, all timers in the timer set are executed.
[0048] Specifically, when the timer set ranked first meets the execution timing, all timers in the timer set are executed.
[0049] In this embodiment, multiple timers are grouped according to the trigger timestamps of the timers to obtain multiple timer sets; based on the order of the trigger timestamps, multiple timer sets are sorted to obtain a timer sequence; based on the execution timestamps, the execution timing of the timer set ranked first in the set sequence is detected, and when the timer set ranked first meets the execution timing, all timers in the timer set are executed. Only when the timer set ranked first is detected, if the timer set ranked first does not reach the execution timing, it means that the other timer sets in the set sequence have not reached the execution timing, which can reduce the number of times the execution timing of the timer is determined, and effectively improve the monitoring efficiency of the timer execution timing; in addition, according to the trigger timestamp, timers with the same execution time are grouped in the same timer set, which can not only reduce the number of monitoring timer execution timing, but also quickly locate the executed timer when the timer set meets the execution timing, which improves the operation efficiency of the timer to a certain extent.
[0050] Further, S100, multiple timers are grouped according to the trigger timestamps of the timers to obtain multiple timer sets, including:
[0051] S110: Determine the trigger time level of each timer according to the trigger timestamp.
[0052] S120: Based on the trigger time level, obtain timers with the same trigger time level to generate a timer linked list.
[0053] S130, in multiple timer linked lists, sort the timers based on the size of the trigger timestamp to obtain multiple timer sets.
[0054] A timestamp is an absolute time standard that records the number of seconds since January 1, 1970 (UTC), which can be converted into a human-readable date and time.
[0055] The trigger time level indicates the density of moments that a timestamp can represent. For example, a standard timestamp only records information at the second level.
[0056] According to the trigger time level, the time from 0 to 59 seconds is divided into 60 groups. Each timer will fall into one of the 60 groups.
[0057] By performing a modulo operation on the trigger timestamp of each timer and 60, the grouping of each timer can be determined.
[0058] Exemplarily, the trigger timestamp of the first timer is timestamp=1723198140, and the date and time corresponding to the trigger timestamp are 2024 / 08 / 09 10:09:00. The trigger timestamp of the second timer is timestamp=1723198200, and the date and time corresponding to the trigger timestamp are 2024 / 08 / 09 10:10:00.
[0059] It can be seen that the trigger timestamps of the above two timers have a second level of 0 seconds, and the two timers can be divided into a timer linked list with a second level of 0.
[0060] In the timer chain list with a second value of 0, the timers are sorted in the order of the trigger timestamps, so the first timer should be before the second timer.
[0061] Furthermore, in each timer chain list, timers with the same trigger timestamp are divided into sub-chain lists of each timer chain list.
[0062] Further, S300, monitoring the execution timing of the first timer set in the set sequence according to the execution timestamp, includes:
[0063] S310, determining the ratio of the execution timestamp to the trigger timestamp of the first-ranked timer set.
[0064] S320: Determine the execution timing of the first-ranked timer set according to the ratio.
[0065] Specifically, the execution timestamp is used to indicate the standard of execution time and is used to indicate the current moment.
[0066] It is understandable that the execution timestamp will keep changing. When the ratio of the execution timestamp to the trigger timestamp indicates that the execution timestamp is consistent with the trigger timestamp, it means that the execution timing of the timer has been reached.
[0067] Further, in S400, when the first-ranked timer set meets the execution timing, all timers in the timer set are executed, including:
[0068] S410, obtaining the execution types of all timers in the timer set.
[0069] S420: After the timers in the timer set are executed, corresponding processing operations are performed on the timers according to the execution types of the timers.
[0070] Specifically, after the timer is executed, the processing operation corresponding to the execution type of the timer is different. Further, the execution type includes a cyclic execution type and a single execution type.
[0071] When the execution type is a cyclic execution type, S400 includes the following steps:
[0072] Gets the number of loops and the time interval of a timer whose execution type is loop execution type.
[0073] After the timer is executed, the number of loops is decremented by one.
[0074] The timer is inserted into the unexecuted timer set according to the time interval, and the interval between the trigger timestamp of the unexecuted timer set and the trigger timestamp of the currently executed timer set is equal to the time interval.
[0075] Specifically, when the execution type is a cyclic execution type, the number of cycles and the time interval of the timer are obtained.
[0076] The trigger timestamp of the next execution of the timer is determined according to the time interval, and the number of cycles is used to perform a minus-one operation.
[0077] When the timer is executed, the timer is inserted into the corresponding timer set according to the determined trigger timestamp.
[0078] When the execution type is a single execution type, S400 includes the following steps:
[0079] After the execution of a timer with a single execution type is completed, the timer is deleted.
[0080] Specifically, after the timer with the execution type of the word execution type is executed, the timer is deleted.
[0081] Further, S100, multiple timers are grouped according to the trigger timestamps of the timers to obtain multiple timer sets, including:
[0082] If the number of the timer set is greater than a preset number threshold, the grouping interval of the trigger timestamp is adjusted and then the multiple timers are grouped.
[0083] Specifically, if the number of the timer sets is greater than a preset number threshold, the grouping interval of the trigger timestamp is adjusted.
[0084] As an optional implementation, grouping is performed based on the relationship between the minimum unit of the trigger timestamp and the length of a period of time.
[0085] For example, the minimum unit of time corresponding to the trigger timestamp is seconds, and the length of a period of time is one hour, then 1 hour = 3600 seconds.
[0086] The timers can be grouped into 3600 groups.
[0087] The time units are one hour and the seconds are grouped, and the program for grouping timers is further refined to achieve more sophisticated group management.
[0088] Figure 3 A schematic diagram of the structure of a timer operating device according to an embodiment of the present application is shown, and the timer operating device includes:
[0089] A grouping module 31, used to group multiple timers according to the triggering timestamps of the timers to obtain multiple timer sets;
[0090] A sorting module 32, used to sort multiple timer sets based on the order of triggering timestamps to obtain a set sequence;
[0091] A detection module 33, configured to monitor the execution timing of the first timer set in the set sequence according to the execution timestamp, wherein the execution timestamp is used to compare with the trigger timestamp to monitor the execution timing of the timer set;
[0092] The timer execution module 34 is configured to execute all timers in the timer set when the first-ranked timer set meets the execution opportunity.
[0093] Furthermore, the grouping module 31 is configured as follows:
[0094] According to the trigger timestamp, determine the trigger time level of each timer;
[0095] Generate a timer linked list for timers with the same trigger time level;
[0096] In the multiple timer linked lists, the timers are sorted based on the size of the trigger timestamp to obtain multiple timer sets.
[0097] Furthermore, the detection module 33 is configured as follows:
[0098] Determine the ratio of the execution timestamp to the trigger timestamp of the first-ranked timer set;
[0099] The execution timing of the first-ranked timer set is determined according to the ratio.
[0100] Furthermore, the timer execution module 34 is configured to:
[0101] Get the execution type of all timers in the timer collection;
[0102] After the timers in the timer set are executed, corresponding processing operations are performed on the timers according to the execution type of the timers.
[0103] Furthermore, the execution type includes a cyclic execution type and a single execution type.
[0104] When the execution type is a cyclic execution type, the timer execution module 34 is configured as follows:
[0105] Get the number of cycles and time interval of a timer whose execution type is a cyclic execution type;
[0106] After the execution of the timer is completed, the number of loops is reduced by one;
[0107] The timer is inserted into the unexecuted timer set according to the time interval, and the interval between the trigger timestamp of the unexecuted timer set and the trigger timestamp of the currently executed timer set is equal to the time interval.
[0108] When the execution type is a single execution type, the timer execution module 34 is configured as follows:
[0109] After the execution of a timer with a single execution type is completed, the timer is deleted.
[0110] Furthermore, the grouping module 31 is configured as follows:
[0111] If the number of the timer set is greater than a preset number threshold, the grouping interval of the trigger timestamp is adjusted and then the multiple timers are grouped.
[0112] Reference below Figure 4 An electronic device 50 according to an embodiment of the present application is described. Figure 4 The electronic device 50 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0113] like Figure 4 As shown, the electronic device 50 is in the form of a general computing device. The components of the electronic device 50 may include but are not limited to: at least one processing unit 510, at least one storage unit 520, and a bus 530 connecting different system components (including the storage unit 520 and the processing unit 510).
[0114] The storage unit stores program codes, which can be executed by the processing unit 510, so that the processing unit 510 executes the steps according to various exemplary embodiments of the present application described in the description of the exemplary method described above in this specification. For example, the processing unit 510 can execute the following steps: Figure 1 The steps shown in .
[0115] The storage unit 520 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 5201 and / or a cache storage unit 5202 , and may further include a read-only storage unit (ROM) 5203 .
[0116] The storage unit 520 may also include a program / utility 5204 having a set (at least one) of program modules 5205, such program modules 5205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0117] Bus 530 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0118] The electronic device 50 may also communicate with one or more external devices 600 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 50, and / or communicate with any device that enables the electronic device 50 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 550. The input / output (I / O) interface 550 is connected to a display unit 540. In addition, the electronic device 50 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 560. As shown, the network adapter 560 communicates with other modules of the electronic device 50 via a bus 530. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 50, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0119] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation method of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes a number of instructions to enable a computing device (which can be a personal computer, a mobile terminal, etc.) to execute the timer operation method according to the implementation method of the present application.
[0120] In an exemplary embodiment of the present application, a computer-readable storage medium is further provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer executes the timer operation method described in the above method embodiment.
[0121] According to one embodiment of the present application, a program product for implementing the method in the above method embodiment is also provided, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present application is not limited thereto, and in this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0122] The program product may adopt any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0123] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0124] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0125] Program code for performing the operations of the present application may be written in any combination of one or more programming languages, including object-oriented programming languages, such as JAVA, C++, etc., and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).
[0126] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0127] In addition, although the steps of the method in the present application are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0128] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation method of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes a number of instructions to enable a computing device (which can be a personal computer, a mobile terminal, etc.) to execute the method according to the implementation method of the present application.
[0129] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the appended claims.
Claims
1. A timer operation method, characterized in that: include: According to the trigger timestamps of the timers, the multiple timers are grouped to obtain multiple timer sets, and the trigger timestamps of the timers in each timer set are the same; The grouping of the multiple timers to obtain multiple timer sets includes: determining a trigger time level for each of the timers; Based on the trigger time level, obtaining the timers with the same trigger time level to generate a timer linked list; In the multiple timer linked lists, the timers are sorted based on the size of the trigger timestamp to obtain the multiple timer sets; Sorting the plurality of timer sets based on the order of the trigger timestamps to obtain a set sequence; monitoring, according to the execution timestamp, the execution timing of the timer set ranked first in the set sequence, wherein the execution timestamp is used to compare with the trigger timestamp to monitor the execution timing of the timer set, and the set sequence is used to sort the timer sets based on the order of the trigger timestamps; When the first-ranked timer set meets the execution timing, all timers in the timer set are executed.
2. The timer operation method according to claim 1, characterized in that: The step of monitoring the execution timing of the first-order timer set in the set sequence according to the execution timestamp includes: Determine a ratio of the execution timestamp to the trigger timestamp of the first-ranked timer set; The execution timing of the first-ranked timer set is determined according to the ratio.
3. The timer operation method according to claim 1, characterized in that: When the first-ranked timer set meets the execution timing, all timers in the timer set are executed, including: Get the execution type of all timers in the timer set; After the timers in the timer set are executed, corresponding processing operations are performed on the timers according to the execution types of the timers.
4. The timer operation method according to claim 3, characterized in that: The execution type includes a loop execution type; and the performing a corresponding processing operation on the timer according to the execution type of the timer includes: Get the number of cycles and time interval of a timer whose execution type is a cyclic execution type; After the timer is executed, the number of cycles is reduced by one; The timer is inserted into an unexecuted timer set according to the time interval, and the interval between the trigger timestamp of the unexecuted timer set and the trigger timestamp of the currently executed timer set is equal to the time interval.
5. The timer operation method according to claim 3, characterized in that: The execution type is a single execution type; After the timer with the execution type of a single execution type is executed, the timer is deleted.
6. The timer operation method according to claim 1, characterized in that: The method of grouping the plurality of timers according to the trigger timestamps of the timers to obtain a plurality of timer sets includes: If the number of the timer set is greater than a preset number threshold, the grouping interval of the trigger timestamp is adjusted and then the multiple timers are grouped.
7. A timer operating device, characterized in that: The device comprises: A grouping module, used for grouping a plurality of the timers according to the trigger timestamps of the timers to obtain a plurality of timer sets, wherein the trigger timestamps of the timers in each of the timer sets are the same; The grouping module also includes: determining a trigger time level for each of the timers; Based on the trigger time level, obtaining the timers with the same trigger time level to generate a timer linked list; In the multiple timer linked lists, the timers are sorted based on the size of the trigger timestamp to obtain the multiple timer sets; A sorting module, used to sort the multiple timer sets based on the order of triggering timestamps to obtain a set sequence, wherein the set sequence sorts the timer sets based on the order of triggering timestamps; a detection module, configured to monitor the execution timing of the first timer set in the set sequence according to an execution timestamp, wherein the execution timestamp is used to compare with the trigger timestamp to monitor the execution timing of the timer set; The timer execution module is used to execute all timers in the timer set when the first-ranked timer set meets the execution opportunity.
8. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, enables the electronic device to implement the timer operation method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the timer operation method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Processing method and processing device of timer
CN103106222A
Timing task management method and device, equipment and medium
CN116360947A
Wake-up management method, timer management method, and terminal device
WO2019174025A1