Timer life cycle management method and device, equipment and storage medium
By setting instance identifier and running status flag fields, a listening coroutine is created to listen to the trigger and stop signal channels of the timer object, which solves the problems of timer object residue and resource leakage, and realizes accurate scheduling of scheduled tasks and stable operation of the system.
Patent Information
- Application Number
- CN202511599897.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-04
- Publication Date
- 2026-02-03
AI Technical Summary
Existing timer mechanisms lack lifecycle management in embedded systems and high-concurrency servers, leading to problems such as timer object residue, repeated triggering, resource leaks, and task misalignment, which affect system stability and task scheduling accuracy.
By acquiring timer management information, setting instance identifier and running status flag fields, and creating listening coroutines to listen to the trigger and stop signal channels of timer objects, the full lifecycle management of timer objects can be realized, including closed-loop control of creation, running, stopping, and resource release.
It enables precise scheduling and unified management of timed tasks, avoids duplicate creation and state confusion, ensures reliable recycling of timer resources, and improves the system's operational stability and the accuracy of task scheduling.
Smart Images

Figure CN121455640A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of timer resource management technology, and in particular to a timer lifecycle management method, apparatus, device, and storage medium. Background Technology
[0002] In embedded systems, IoT devices, and high-concurrency server programs, scheduled tasks are widely used for scenarios such as status monitoring, resource reclamation, periodic communication, and data synchronization. Existing technologies typically employ the system's built-in timer interface or a third-party scheduling framework to trigger and execute periodic tasks. However, with the increasing complexity of system functions and the growing number of tasks, traditional timer mechanisms have revealed various problems in instance management and resource release.
[0003] First, existing timer mechanisms generally lack lifecycle management capabilities. That is, during the creation, operation, stopping, and destruction processes, a unified data association is not established between the timer object and its managed instance. This can lead to the phenomenon of timer object residue or repeated triggering when the system repeatedly creates timed tasks, affecting system stability.
[0004] Secondly, traditional solutions often use unidirectional control logic to stop timed tasks, such as by calling the "stop" interface externally. However, they do not consider internal exception detection or asynchronous channel signal triggering scenarios, which may lead to the inability to terminate the timer thread in time under abnormal or high concurrency conditions, resulting in resource leaks or deadlock risks.
[0005] Furthermore, the execution of scheduled tasks is often strongly dependent on the system state. When system tasks are frequently started and stopped, if the running status flag field and instance identifier field are not designed specifically, task errors or inconsistent state updates may easily occur, increasing the difficulty of maintenance.
[0006] In summary, the problems existing in the current technology urgently need to be solved. Summary of the Invention
[0007] This invention provides a timer lifecycle management method, apparatus, device, and storage medium to address the deficiencies in the prior art and improve the system's operational stability and task scheduling accuracy.
[0008] This invention provides a timer lifecycle management method, comprising: In response to a scheduled task start command, timer management information is obtained, including an instance identifier field, a running status flag field, a stop signal channel field, a timing period field, and a task function field. Read the running status flag field; if the running status flag field indicates that there is currently an active timer, then call the timer stop process to release the system timer object and reset the timer management instance; otherwise, create a new timer management instance and set the running status flag field to running status. Based on the timing period field, a system timer object is created through the timer management instance, and the instance identifier field is written to it; A listening coroutine is started based on the timer management instance to listen for the trigger signal of the system timer object and the stop signal of the stop signal channel field; When an external system or internal detection module issues a stop command, a stop signal is sent to the stop signal channel field to terminate the listening coroutine and release the resources of the system timer object.
[0009] According to a timer lifecycle management method provided by the present invention, the step of obtaining timer management information in response to a timed task start command specifically includes: Upon receiving the scheduled task start command, read the timer configuration data corresponding to the scheduled task start command from the configuration file or database; If any field in the timer management information is found to be missing, the timer management information will be completed using preset default parameters.
[0010] According to a timer lifecycle management method provided by the present invention, the step of creating a new timer management instance specifically includes: Assign a unique instance identifier to each newly created instance; The periodic timing parameters are generated based on the timing period field and written into the timer management instance. A locking mechanism is used to prevent the concurrent creation of multiple timer instances.
[0011] According to a timer lifecycle management method provided by the present invention, the step of creating a system timer object through a timer management instance specifically includes: Generate timer configuration parameters based on the timing period field and task function field; Call the scheduled task interface provided by the operating system to instantiate a system timer object based on the configuration parameters; Register the task function field as a timer callback function to automatically trigger the corresponding task logic when the timer period arrives.
[0012] According to a timer lifecycle management method provided by the present invention, the step of starting a listening coroutine based on the timer management instance specifically includes: Create a listening thread corresponding to the instance identifier field; The thread simultaneously listens for input events in the trigger and stop signal channel fields of the system timer object; When a trigger signal is received, the task logic corresponding to the task function field is invoked; Upon receiving a stop signal, the listening thread is immediately terminated and a resource release operation is triggered.
[0013] According to a timer lifecycle management method provided by the present invention, the stop signal channel field is a bidirectional communication channel for receiving asynchronous stop signals; An external system issues a stop command by sending a control message to the channel. The internal detection module automatically generates a stop signal through an anomaly detection mechanism.
[0014] According to a timer lifecycle management method provided by the present invention, the step of releasing the resources of the system timer object specifically includes: Close the timing thread associated with the system timer object; Release the memory cache and channel handle; The instance identifier field is then set to null to prevent duplicate references.
[0015] The present invention also provides a timer lifecycle management device, comprising: The information acquisition module is used to acquire timer management information in response to the timed task start command. The timer management information includes an instance identifier field, a running status flag field, a stop signal channel field, a timing period field, and a task function field. The field reading module is used to read the running status flag field; if the running status flag field indicates that there is currently an active timer, the timer stop process is invoked to release the system timer object and reset the timer management instance; otherwise, a new timer management instance is created and the running status flag field is set to running status. The timer creation module is used to create a system timer object through the timer management instance based on the timer period field, and write the instance identifier field. The timer monitoring module is used to start a monitoring coroutine based on the timer management instance to monitor the trigger signal of the system timer object and the stop signal of the stop signal channel field; The timer release module is used to send a stop signal to the stop signal channel field when an external system or internal detection module issues a stop command, so as to terminate the listening coroutine and release the resources of the system timer object.
[0016] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the timer lifecycle management method as described above.
[0017] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the timer lifecycle management method as described above.
[0018] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the timer lifecycle management method as described above.
[0019] The timer lifecycle management method, apparatus, device, and storage medium provided by this invention create system timer objects through timer management instances and register timer callback functions in the operating system's timed task interface. When the period corresponding to the timer period field is reached, the task logic in the task function field is automatically triggered, thereby achieving precise scheduling and unified management of timed tasks. By setting instance identifier and running status flag fields in the timer management information, each timer object can be uniquely identified and tracked, avoiding problems such as duplicate creation or state confusion. Furthermore, this invention achieves safe termination of timed tasks and automatic release of resources by listening to stop signals from coroutines during the stopping phase, ensuring reliable timer recycling and stable system operation. Overall, this invention achieves closed-loop control of the entire lifecycle of timer objects through field-based management and event-driven mechanisms, solving problems such as untimely release of timer resources, duplicate instantiation, and chaotic state management in existing technologies, significantly improving the system's operational stability and the accuracy of task scheduling. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0021] Figure 1 This is a flowchart illustrating the timer lifecycle management method provided by the present invention; Figure 2 This is a schematic diagram of the timer lifecycle management device provided by the present invention; Figure 3 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0023] To address the problems in existing technologies, this invention proposes a timer lifecycle management method to improve system stability and task scheduling accuracy. The timer lifecycle management method is described below, as follows: Figure 1 As shown, including but not limited to the following steps: Step 110: In response to the scheduled task start command, obtain timer management information, which includes an instance identifier field, a running status flag field, a stop signal channel field, a timing period field, and a task function field.
[0024] In step 110, when the system receives a timed task start instruction from the task scheduling module or the upper-layer business module, the timer lifecycle management module first obtains the corresponding timer management information. The timer management information includes an instance identifier field, a running status flag field, a stop signal channel field, a timing period field, and a task function field.
[0025] In one optional embodiment, the timer management information can be read from a preset configuration file or database, and the system can match the corresponding timer configuration record according to the task identifier in the timed task start instruction. When any field in the timer management information is detected to be missing, the system automatically calls the default parameter template to complete the field, ensuring the integrity and availability of the timer initialization information.
[0026] Step 120: Read the running status flag field; if the running status flag field indicates that there is currently an active timer, call the timer stop process to release the system timer object and reset the timer management instance; otherwise, create a new timer management instance and set the running status flag field to running status.
[0027] In step 120, the system reads the running status flag field based on the timer management information to determine whether there is an active timer. When the running status flag field indicates that an active timer already exists, the system calls the timer stop procedure to release the current system timer object and reset the timer management instance, thereby avoiding resource contention and logical conflicts caused by repeated instantiation.
[0028] Conversely, when the running status flag field indicates that no active timer exists, the system creates a new timer management instance, assigns a unique instance identifier, and sets the running status flag field to running. Meanwhile, to prevent concurrency conflicts, a locking mechanism can be used during instance creation to restrict concurrent creation operations under the same task identifier.
[0029] Step 130: Based on the timing period field, create a system timer object through the timer management instance and write the instance identifier field.
[0030] In step 130, the system generates timer configuration parameters based on the timing period field and the task function field, and instantiates a system timer object by calling the timer task interface provided by the operating system through the timer management instance.
[0031] In the implementation, the system timer object can be periodically triggered through a high-precision timer interface. Simultaneously, the task function field is registered as a timer callback function to automatically invoke the corresponding task logic when the timer period arrives, thus achieving automatic execution of the scheduled task. After creation, the system writes the allocated instance identifier into the timer management instance for subsequent status tracking and resource release operations.
[0032] Step 140: Start a listening coroutine based on the timer management instance to listen for the trigger signal of the system timer object and the stop signal of the stop signal channel field.
[0033] In step 140, the system starts a listening coroutine based on the timer management instance to simultaneously listen for the trigger signal and the stop signal of the stop signal channel field of the system timer object.
[0034] In one embodiment, the listening coroutine operates using an asynchronous event-driven mechanism. When it receives a trigger signal from a system timer object, it immediately schedules and executes the corresponding task function. When a stop signal is detected in the stop signal channel, it interrupts the current timing loop and enters the resource reclamation phase. This coroutine mechanism enables real-time response and smooth termination of timed tasks, improving the reliability and controllability of system operation.
[0035] Step 150: When an external system or internal detection module issues a stop command, a stop signal is sent to the stop signal channel field to terminate the listening coroutine and release the resources of the system timer object.
[0036] In step 150, when an external system or internal detection module issues a stop command, the timer management module sends a stop signal to the stop signal channel field. Upon receiving this signal, the listening coroutine immediately terminates the current task scheduling and releases the resources of the system timer object.
[0037] Specifically, the system shuts down the timing thread associated with the timer object, releases the memory cache and communication channel handle, and sets the instance identifier field to null to prevent duplicate references or resource leaks. This step achieves complete closed-loop management of the timer object's lifecycle, ensuring the safe release of system resources after the task terminates.
[0038] Through the synergistic effect of the above steps, this invention achieves full-cycle automation and precise control of the timer from creation, operation to termination, effectively avoiding problems such as duplicate instantiation, thread leakage and abnormal occupation, and improving the stability and resource utilization of the system in high-concurrency task scheduling scenarios.
[0039] As a further optional embodiment, the step of obtaining timer management information in response to a timed task start command specifically includes: Upon receiving the scheduled task start command, read the timer configuration data corresponding to the scheduled task start command from the configuration file or database; If any field in the timer management information is found to be missing, the timer management information will be completed using preset default parameters.
[0040] In this embodiment, to ensure system compatibility across different deployment environments, when any field in the timer management information is detected to be missing or has an abnormal value, the system automatically calls a preset default parameter template to complete the missing field. For example, if the stop signal channel field is not defined in the configuration file, the system can automatically generate a bidirectional communication channel; if the timing period field is not detected, the system's default period parameter is used for initialization. Through the above completion process, the integrity and consistency of the timer management information can be guaranteed, thereby avoiding timer initialization failures or logical anomalies caused by missing configurations.
[0041] As a further optional embodiment, the step of creating a new timer management instance specifically includes: Assign a unique instance identifier to each newly created instance; The periodic timing parameters are generated based on the timing period field and written into the timer management instance. A locking mechanism is used to prevent the concurrent creation of multiple timer instances.
[0042] In this embodiment, to prevent the concurrent creation of multiple timer instances in a multi-tasking environment, the system can employ a locking mechanism (such as a mutex lock or atomic operation) to lock the creation operation of the timer management instance. This mechanism ensures that only one instance is created within the same time period, thereby guaranteeing the uniqueness and operational security of the timer management instance and avoiding resource conflicts or duplicate task execution caused by concurrent creation.
[0043] As a further optional embodiment, the step of creating a system timer object through a timer management instance specifically includes: Generate timer configuration parameters based on the timing period field and task function field; Call the scheduled task interface provided by the operating system to instantiate a system timer object based on the configuration parameters; Register the task function field as a timer callback function to automatically trigger the corresponding task logic when the timer period arrives.
[0044] In this embodiment, the task function field is registered as a callback function for the created system timer object. When the timer period arrives, the system automatically triggers the callback function to execute the corresponding timed task logic. This method enables automated periodic execution of timers while ensuring a one-to-one correspondence between each timer object and its managed instance, improving the reliability and controllability of system scheduling.
[0045] As a further optional embodiment, the step of starting the listening coroutine based on the timer management instance specifically includes: Create a listening thread corresponding to the instance identifier field; The thread simultaneously listens for input events in the trigger and stop signal channel fields of the system timer object; When a trigger signal is received, the task logic corresponding to the task function field is invoked; Upon receiving a stop signal, the listening thread is immediately terminated and a resource release operation is triggered.
[0046] In this embodiment, the monitoring coroutine simultaneously monitors the input events of the trigger and stop signal channel fields of the system timer object through continuous looping and event selection mechanisms, thereby achieving real-time response to scheduled task execution and external or internal stop commands. When the coroutine detects a trigger signal, it immediately calls the corresponding task logic in the task function field to execute the specific scheduled task operation; this operation may include data acquisition, status detection, log recording, or business process triggering, etc., and the coroutine continues to monitor the stop signal during task execution to ensure that task execution can be interrupted at any time.
[0047] When a coroutine receives a stop signal, it immediately terminates the loop, stops the listening thread or coroutine from running, and triggers the release of system timer object resources. This includes closing the timing thread associated with the timer object, releasing the memory buffer and channel handle, and resetting or clearing the instance identifier field and running status flag field to avoid duplicate references or residual tasks. Through this mechanism, the entire timer lifecycle management achieves fully automated control from creation, running to stopping and resource reclamation, ensuring the stability and reliability of the system in multi-tasking or high-concurrency environments, while avoiding problems such as resource leaks, duplicate instance conflicts, and inflexible control that exist in traditional timer management.
[0048] As a further optional embodiment, the stop signal channel field is a bidirectional communication channel for receiving asynchronous stop signals; An external system issues a stop command by sending a control message to the channel. The internal detection module automatically generates a stop signal through an anomaly detection mechanism.
[0049] In this embodiment, the stop signal channel field serves as a bidirectional communication channel. It can not only receive control messages from external systems but also feed back the status of the coroutine or timer management module to the external system, enabling bidirectional interaction. When an external system needs to terminate a specific timed task, it can send a stop command message to this channel, triggering the listening coroutine to immediately respond and execute timer stop and resource release operations. Simultaneously, the internal detection module can send a stop signal to the same channel based on anomaly detection mechanisms (such as task execution timeout, error status detection, or resource anomaly monitoring) to achieve automated interruption, thus eliminating the need for manual intervention. Through this mechanism, the system can uniformly manage stop requests from different sources, ensuring that timers can safely and promptly terminate operation and release related resources under any circumstances, improving the system's reliability and controllability.
[0050] As a further optional embodiment, the step of releasing the resources of the system timer object specifically includes: Close the timing thread associated with the system timer object; Release the memory cache and channel handle; The instance identifier field is then set to null to prevent duplicate references.
[0051] In this embodiment, after the timer stop operation is triggered, the timing thread associated with the system timer object is first shut down to ensure that the thread no longer executes the timed task, preventing residual tasks from consuming CPU resources. Then, the memory cache and channel handle used by the system timer object are released, including the storage task function, timing period parameters, and data structures related to the stop signal channel, thereby avoiding memory leaks or channel blockages. Finally, the instance identifier field in the timer management instance is set to null to ensure that the timer instance is not repeatedly referenced or misoperated, providing a clean state foundation for subsequent timer creation. Through these operations, complete management of the timer lifecycle and safe release of resources are achieved, improving system stability and maintainability.
[0052] The timer lifecycle management device provided by the present invention is described below, as shown in Figure x. The timer lifecycle management device described below can be referred to in correspondence with the timer lifecycle management method described above.
[0053] A timer lifecycle management device, comprising: Information acquisition module 210 is used to acquire timer management information in response to a timed task start command. The timer management information includes an instance identifier field, a running status flag field, a stop signal channel field, a timing period field, and a task function field. The field reading module 220 is used to read the running status flag field; if the running status flag field indicates that there is currently an active timer, the timer stop process is invoked to release the system timer object and reset the timer management instance; otherwise, a new timer management instance is created and the running status flag field is set to running status. The timer creation module 230 is used to create a system timer object through the timer management instance according to the timer period field, and write the instance identifier field. The timer monitoring module 240 is used to start a monitoring coroutine based on the timer management instance to monitor the trigger signal of the system timer object and the stop signal of the stop signal channel field; The timer release module 250 is used to send a stop signal to the stop signal channel field when an external system or internal detection module issues a stop command, so as to terminate the listening coroutine and release the resources of the system timer object.
[0054] Figure 3 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 3As shown, the electronic device may include: a processor 310, a communications interface 320, a memory 330, and a communication bus 340, wherein the processor 310, the communications interface 320, and the memory 330 communicate with each other via the communication bus 340. The processor 310 can call logical instructions in the memory 330 to execute a timer lifecycle management method, which includes: In response to a scheduled task start command, timer management information is obtained, including an instance identifier field, a running status flag field, a stop signal channel field, a timing period field, and a task function field. Read the running status flag field; if the running status flag field indicates that there is currently an active timer, then call the timer stop process to release the system timer object and reset the timer management instance; otherwise, create a new timer management instance and set the running status flag field to running status. Based on the timing period field, a system timer object is created through the timer management instance, and the instance identifier field is written to it; A listening coroutine is started based on the timer management instance to listen for the trigger signal of the system timer object and the stop signal of the stop signal channel field; When an external system or internal detection module issues a stop command, a stop signal is sent to the stop signal channel field to terminate the listening coroutine and release the resources of the system timer object.
[0055] Furthermore, the logical instructions in the aforementioned memory 330 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0056] On the other hand, the present invention also provides a computer program product, the computer program product comprising a computer program that can be stored on a non-transitory computer-readable storage medium, wherein when the computer program is executed by a processor, the computer is able to execute the timer lifecycle management method provided by the above methods, the method comprising: In response to a scheduled task start command, timer management information is obtained, including an instance identifier field, a running status flag field, a stop signal channel field, a timing period field, and a task function field. Read the running status flag field; if the running status flag field indicates that there is currently an active timer, then call the timer stop process to release the system timer object and reset the timer management instance; otherwise, create a new timer management instance and set the running status flag field to running status. Based on the timing period field, a system timer object is created through the timer management instance, and the instance identifier field is written to it; A listening coroutine is started based on the timer management instance to listen for the trigger signal of the system timer object and the stop signal of the stop signal channel field; When an external system or internal detection module issues a stop command, a stop signal is sent to the stop signal channel field to terminate the listening coroutine and release the resources of the system timer object.
[0057] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the timer lifecycle management method provided by the methods described above, the method comprising: In response to a scheduled task start command, timer management information is obtained, including an instance identifier field, a running status flag field, a stop signal channel field, a timing period field, and a task function field. Read the running status flag field; if the running status flag field indicates that there is currently an active timer, then call the timer stop process to release the system timer object and reset the timer management instance; otherwise, create a new timer management instance and set the running status flag field to running status. Based on the timing period field, a system timer object is created through the timer management instance, and the instance identifier field is written to it; A listening coroutine is started based on the timer management instance to listen for the trigger signal of the system timer object and the stop signal of the stop signal channel field; When an external system or internal detection module issues a stop command, a stop signal is sent to the stop signal channel field to terminate the listening coroutine and release the resources of the system timer object.
[0058] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0059] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0060] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A timer lifecycle management method, characterized in that, include: In response to a scheduled task start command, timer management information is obtained, including an instance identifier field, a running status flag field, a stop signal channel field, a timing period field, and a task function field. Read the running status flag field; If the running status flag field indicates that there is currently an active timer, then the timer stop process is invoked to release the system timer object and reset the timer management instance; Otherwise, create a new timer management instance and set the running status flag field to running status; Based on the timing period field, a system timer object is created through the timer management instance, and the instance identifier field is written to it; A listening coroutine is started based on the timer management instance to listen for the trigger signal of the system timer object and the stop signal of the stop signal channel field; When an external system or internal detection module issues a stop command, a stop signal is sent to the stop signal channel field to terminate the listening coroutine and release the resources of the system timer object.
2. The timer lifecycle management method according to claim 1, characterized in that, The step of obtaining timer management information in response to a scheduled task start command specifically includes: Upon receiving the scheduled task start command, read the timer configuration data corresponding to the scheduled task start command from the configuration file or database; If any field in the timer management information is found to be missing, the timer management information will be completed using preset default parameters.
3. The timer lifecycle management method according to claim 1, characterized in that, The step of creating a new timer management instance specifically includes: Assign a unique instance identifier to each newly created instance; The periodic timing parameters are generated based on the timing period field and written into the timer management instance. A locking mechanism is used to prevent the concurrent creation of multiple timer instances.
4. The timer lifecycle management method according to claim 1, characterized in that, The step of creating a system timer object through a timer management instance specifically includes: Generate timer configuration parameters based on the timing period field and task function field; Call the scheduled task interface provided by the operating system to instantiate a system timer object based on the configuration parameters; Register the task function field as a timer callback function to automatically trigger the corresponding task logic when the timer period arrives.
5. The timer lifecycle management method according to claim 1, characterized in that, The step of starting the listening coroutine based on the timer management instance specifically includes: Create a listening thread corresponding to the instance identifier field; The thread simultaneously listens for input events in the trigger and stop signal channel fields of the system timer object; When a trigger signal is received, the task logic corresponding to the task function field is invoked; Upon receiving a stop signal, the listening thread is immediately terminated and a resource release operation is triggered.
6. The timer lifecycle management method according to claim 1, characterized in that, The stop signal channel field is a bidirectional communication channel for receiving asynchronous stop signals; An external system issues a stop command by sending a control message to the channel. The internal detection module automatically generates a stop signal through an anomaly detection mechanism.
7. The timer lifecycle management method according to claim 1, characterized in that, The step of releasing the resources of the system timer object specifically includes: Close the timing thread associated with the system timer object; Release the memory cache and channel handle; The instance identifier field is then set to null to prevent duplicate references.
8. A timer lifecycle management device, characterized in that, include: The information acquisition module is used to acquire timer management information in response to the timed task start command. The timer management information includes an instance identifier field, a running status flag field, a stop signal channel field, a timing period field, and a task function field. The field reading module is used to read the running status flag field; If the running status flag field indicates that there is currently an active timer, then the timer stop process is invoked to release the system timer object and reset the timer management instance; Otherwise, create a new timer management instance and set the running status flag field to running status; The timer creation module is used to create a system timer object through the timer management instance based on the timer period field, and write the instance identifier field. The timer monitoring module is used to start a monitoring coroutine based on the timer management instance to monitor the trigger signal of the system timer object and the stop signal of the stop signal channel field; The timer release module is used to send a stop signal to the stop signal channel field when an external system or internal detection module issues a stop command, so as to terminate the listening coroutine and release the resources of the system timer object.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the timer lifecycle management method as described in any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the timer lifecycle management method as described in any one of claims 1 to 7.