CN103324469A - Timer implementation method and device - Google Patents

Timer implementation method and device Download PDF

Info

Publication number
CN103324469A
CN103324469A CN2012100757192A CN201210075719A CN103324469A CN 103324469 A CN103324469 A CN 103324469A CN 2012100757192 A CN2012100757192 A CN 2012100757192A CN 201210075719 A CN201210075719 A CN 201210075719A CN 103324469 A CN103324469 A CN 103324469A
Authority
CN
China
Prior art keywords
timer
triggered time
queue
callback method
newly
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN2012100757192A
Other languages
Chinese (zh)
Inventor
李红波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN2012100757192A priority Critical patent/CN103324469A/en
Publication of CN103324469A publication Critical patent/CN103324469A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Telephonic Communication Services (AREA)

Abstract

The invention discloses a timer implementation method and device, and belongs to the field of computers. The method comprises the steps as follows: newly-built timers are inserted into a preset timer queue for storage according to a triggering time sequence ranked according to a timer order from the earliest to the latest; each timer has a triggering time and a call-back method; a trigger time and a call-back method of a timer ranked at a head of the queue where the timer is located at present are acquired; a timing route is started according to the triggering time and the call-back method; and the timing route calls and executes the call-back method automatically at an appointed time of the triggering time. According to the timer implementation method and device, the timer queue is adopted, the execution of a plurality of the timers is called; at the same time, only a timer with the earliest triggering time is executed, so that no matter how many timers exist in a system, only one timing route is used, and the timer implementation method and device can reduce occupation of system resources remarkably.

Description

Timer realization method and device
Technical field
The present invention relates to computer realm, particularly a kind of timer realization method and device.
Background technology
The application program that includes the clocked flip logic such as alarm clock, calendar prompting is to use comparatively widely a kind of application program.In this class application program, realize that the part of clocked flip scheduled operation can be referred to as timer.
Had a kind of timer realization method in the prior art, this timer realization method mainly comprises: when a timer of needs, triggered time and callback method according to this timer are enabled a timing thread, and this timing thread can be at specified moment Automatically invoked callback method of this triggered time.Wherein, the triggered time is that user or application program wish that timer triggers the time of scheduled operation, such as, the triggered time of the timer in alarm clock application program can be 6:00 in morning.And callback method can think to be timed the function interface of the scheduled operation of triggering, such as, the callback method of the timer in alarm clock application program can be a function interface that is used for 10 seconds function of jingle bell.When different application programs needed timer, when also namely needing a more than timer, a plurality of timing threads that system can open respectively corresponding to required timer number came respectively timing, to realize each timer.
In realizing process of the present invention, the inventor finds that there is following problem at least in prior art: along with the increase of timer, the timing thread that system opens also can increase thereupon, increasing timing thread will take more system resource, causes the shortcomings such as the hydraulic performance decline of system and power consumption quantitative change are large.
Summary of the invention
Take the problem than multi-system resource in order to reduce a plurality of timers to enable simultaneously the timing thread, the embodiment of the invention provides a kind of timer realization method and device.Described technical scheme is as follows:
According to an aspect of the present invention, the embodiment of the invention provides a kind of timer realization method, and described method comprises:
Newly-built timer was stored by early inserting in the timer queue that sets in advance to the order in evening according to the triggered time, and described timer has triggered time and the callback method of self;
Obtain current triggered time and the callback method that in described timer queue, comes the timer of head of the queue;
According to described triggered time and callback method unlatching timing thread, described timing thread is in the described callback method of the moment of described triggered time appointment Automatically invoked and execution.
Further, described newly-built timer was inserted in the timer queue that sets in advance by the order in morning to evening according to the triggered time stored, and specifically comprises:
Obtain a newly-built timer, described newly-built timer has triggered time and the callback method of self;
Judge the morning and evening in the triggered time of each timer of having stored in triggered time of described newly-built timer and the described timer queue;
If judge the triggered time of described newly-built timer early than the triggered time of a part of timer in the described timer queue, when then described newly-built timer being stored into described timer queue, be stored in before described a part of timer;
Be later than the triggered time of another part timer in the described timer queue if judge the triggered time of described newly-built timer, when then described newly-built timer being stored into described timer queue, be stored in after described another part timer.
Further, described according to described triggered time and callback method unlatching timing thread, described timing thread also comprises at the described callback method of the moment of described triggered time appointment Automatically invoked and after carrying out:
The executed timer of the described callback method of deletion from described timer queue;
Continue to carry out triggered time of obtaining the current timer that in described timer queue, comes head of the queue and the step of callback method.
Further, described according to described triggered time and callback method unlatching timing thread, described timing thread also comprises at the described callback method of the moment of described triggered time appointment Automatically invoked and after carrying out:
Whether that judges the executed timer of described callback method has cycle period information;
If so, then obtain cycle period in the described cycle period information;
The triggered time of the executed timer of described callback method is revised as: the former triggered time adds the above cycle period;
Reinsert in the described timer sequence and store revising described timer after the triggered time.
Further, described method also comprises:
Reception acts on the triggered time modification signal of a timer in the described timer queue;
Revise the triggered time of the described timer of modification of signal according to the described triggered time;
Adjust the position of described timer in described timer queue to satisfy the described triggered time by early to late storage order according to the amended triggered time.
According to a further aspect in the invention, the embodiment of the invention also provides a kind of timer implement device, and described device comprises:
Queue management module is used for newly-built timer was stored by early inserting the timer queue that sets in advance to the order in evening according to the triggered time, and described timer has triggered time and the callback method of self;
The acquisition of information module is used for obtaining current triggered time and the callback method that comes the timer of head of the queue at described timer queue;
Regularly execution module is used for opening the timing thread according to described triggered time and callback method, and described timing thread is in the described callback method of the moment of described triggered time appointment Automatically invoked and execution.
Further, described queue management module comprises: timer acquiring unit, triggered time judging unit and timer storage unit;
Described timer acquiring unit is used for obtaining a newly-built timer, and described newly-built timer has triggered time and the callback method of self;
Described triggered time judging unit is for the morning and evening in the triggered time of judging the triggered time of described newly-built timer and each timer that described timer queue has been stored;
Described timer storage unit, if be used for the triggered time of the described newly-built timer of described triggered time judgment unit judges early than the triggered time of a part of timer of described timer queue, when then described newly-built timer being stored into described timer queue, be stored in before described a part of timer;
Described timer storage unit, if the triggered time that also is used for the described newly-built timer of described triggered time judgment unit judges is later than the triggered time of described timer queue another part timer, when then described newly-built timer being stored into described timer queue, be stored in after described another part timer.
Further, described queue management module also specifically comprises: the delete timer unit;
Described delete timer unit is used for from the executed timer of the described timer queue described callback method of deletion;
Described acquisition of information module also is used for continuing to obtain current triggered time and the callback method that comes the timer of head of the queue in described timer queue after the executed timer of the described callback method of described delete timer element deletion.
Further, described queue management module also specifically comprises: cycle criterion unit, cycle acquiring unit and the first triggered time are revised the unit;
Described cycle criterion unit is used for judging whether the executed timer of described callback method has cycle period information;
Described cycle acquiring unit has cycle period information if be used for the executed timer of the described callback method of described cycle criterion unit judges, then obtains the cycle period in the described cycle period information;
Described the first triggered time is revised the unit, is used for the triggered time of described callback method executed timer is revised as: the former triggered time adds the above cycle period;
Described timer storage unit also is used for revising described timer after the triggered time and reinserts described timer sequence and store.
Further, described queue management module also specifically comprises: revise signal receiving unit, the second triggered time modification unit and regulator unit;
Described modification signal receiving unit is used for the triggered time modification signal that reception acts on a timer of described timer queue;
Described the second triggered time is revised the unit, is used for revising according to the described triggered time triggered time of the described timer of modification of signal;
Described regulator unit, be used for according to the amended triggered time adjust described timer in the position of described timer queue to satisfy the described triggered time by early to late storage order.
The beneficial effect that the technical scheme that the embodiment of the invention provides is brought is:
By the execution of adopting timer queue to dispatch a plurality of timers, and only carry out at one time the method for a triggered time timer the earliest, no matter so that there are what timers in the system, also always only enable a timing thread, so that the technical program can obviously reduce taking system resource.
Description of drawings
In order to be illustrated more clearly in the technical scheme in the embodiment of the invention, the accompanying drawing of required use was done to introduce simply during the below will describe embodiment, apparently, accompanying drawing in the following describes only is some embodiments of the present invention, for those of ordinary skills, under the prerequisite of not paying creative work, can also obtain according to these accompanying drawings other accompanying drawing.
Fig. 1 is the method flow diagram of the timer realization method that provides of the embodiment of the invention one;
Fig. 2 is the enforcement schematic diagram of the timer realization method that provides of the embodiment of the invention one;
Fig. 3 is the method flow diagram of the timer realization method that provides of the embodiment of the invention two;
Fig. 4 is the block diagram of the timer implement device that provides of the embodiment of the invention three;
Fig. 5 is the block diagram of the queue management module that provides of the embodiment of the invention three.
Embodiment
For making the purpose, technical solutions and advantages of the present invention clearer, embodiment of the present invention is described further in detail below in conjunction with accompanying drawing.
Embodiment one
Please in conjunction with reference to figure 1 and Fig. 2, it shows respectively the method flow diagram of the timer realization method that the embodiment of the invention one provides and implements schematic diagram.This timer realization method can be used for the terminal that operation has the application program that comprises the clocked flip logic, and this timer realization method comprises:
Step 102 is stored according to the triggered time newly-built timer by early inserting in the timer queue that sets in advance to the order in evening, each timer has triggered time and the callback method of self;
Because in same terminal, may have a plurality of timers needs to carry out.But be different from prior art, in the present embodiment, if there are a plurality of timers to need to carry out in the same terminal, terminal is not all opened respectively a timing thread with all timers simultaneously and is enabled so, and provide a timer queue 20, all timers all are stored in this timer queue 20.Because each timer has the triggered time separately, when being stored into newly-built timer 2 02 in the timer queue 20, can store by early to the order in evening newly-built timer 2 02 being inserted in this timer queue 20 according to the triggered time.
Step 104 is obtained current triggered time and the callback method that comes the timer of head of the queue in timer queue;
Each timer has triggered time and the callback method of oneself usually, in order to carry out successively in order each timer in this timer queue, and only carries out at one time a timer.Can always obtain current triggered time and the callback method that in timer queue, comes the timer 2 04 of head of the queue.Wherein, the triggered time is that user or application program wish that timer triggers the time of scheduled operation, such as, the triggered time of the timer in alarm clock application program can be 6:00 in morning.And callback method can think to be timed the function interface of the scheduled operation of triggering, such as, the callback method of the timer in alarm clock application program can be a function interface that is used for 10 seconds function of jingle bell.
Step 106, according to triggered time and callback method unlatching timing thread, the timing thread is in the moment of triggered time appointment Automatically invoked callback method and execution.
After the triggered time and callback method that get access to the timer 2 04 that comes head of the queue, can open a timing thread, this timing thread is in the moment of triggered time appointment Automatically invoked callback method and execution.After 04 operation of current timer 2 was complete, the next timer 2 06 in this timer queue can become the timer that comes head of the queue again, and then re-executed above-mentioned steps 104 and get final product.
In sum, the execution of the timer realization method that the embodiment of the invention one provides by adopting timer queue to dispatch a plurality of timers, and only carry out at one time the method for a triggered time timer the earliest, no matter so that there are what timers in the system, also always only enable a timing thread, so that the technical program can obviously reduce taking system resource.
Embodiment two
Please refer to Fig. 3, it shows the method flow diagram of the timer realization method that the embodiment of the invention two provides.This timer realization method can be used for the terminal that operation has the application program that comprises the clocked flip logic, and this timer realization method comprises:
Step 301 is stored according to the triggered time newly-built timer by early inserting in the timer queue that sets in advance to the order in evening, each timer has triggered time and the callback method of self;
Because in same terminal, may have a plurality of timers needs to carry out.But be different from prior art, in the present embodiment, if there are a plurality of timers to need to carry out in the same terminal, terminal is not all opened respectively a timing thread with all timers simultaneously and is enabled so, and provide a timer queue, all timers all are stored in this timer queue.Because each timer has the triggered time separately, when being stored into a plurality of timers in the timer queue, can each timer be stored in this timer queue according to the order of triggered time by morning to evening.Specifically, a newly-built timer is stored in the timer queue, can specifically comprises:
The first, obtain a newly-built timer, this timer has triggered time and the callback method of self;
When user or the newly-built timer of application program, terminal can be obtained this newly-built timer.Timer all has triggered time and the callback method of self usually.Wherein, the triggered time is that user or application program wish that timer triggers the time of scheduled operation, such as, the triggered time of the timer in calendar prompting application program can be on Dec 21st, 2012, morning 6:00.And callback method can think to be timed the function interface of the scheduled operation of triggering, can be a function interface that is used for ejecting the function of prompt window such as, the callback method of the timer in calendar prompting application program.Need to prove, triggered time described in the present embodiment is to characterize a moment, when but the user arranges a triggered time in the specific embodiment, may adopt the time interval of " carrying out after XX minute " and so on to express, this moment, system can adopt " current time+XX minute " to calculate the triggered time.This type mode also should belong to protection scope of the present invention.
In certain embodiments, timer can also have cycle period information.When the circulation time that needs of a timer, cycle period information is used for preserving the cycle period of this timer.
Terminal can get access to triggered time, callback method and the cycle period information of this timer when getting access to a newly-built timer.
The second, judge morning and evening in the triggered time of each timer of having stored in triggered time of this timer and this timer queue; If judge the triggered time of this timer early than the triggered time of a part of timer in the timer queue, when then this timer being stored into this timer queue, be stored in before this part timer; Be later than the triggered time of another part timer in this timer queue if judge the triggered time of this timer, when then this timer being stored into this timer queue, be stored in after this another part timer.
In a specific embodiment, stored three timers in the timer queue, the triggered time of first timer is 2012/02/09 6:00; The triggered time of second timer is 2012/02/20 9:35; The triggered time of the 3rd timer is 2012/02/20 23:55.When terminal gets access to a newly-built timer, the triggered time that can get access to this timer is 2012/02/20 14:30, then terminal can be when being stored into timer queue with this timer, this timer is stored in after first timer and the second timer, before the 3rd timer.Terminal can distribute different ID number in order to distinguish for each timer when timer is stored into timer queue.ID such as first timer is 0001, and then newly the ID of the timer of storage can be assigned as 0004.
Need to prove, the timer number of having stored in this timer queue can be zero to a plurality of arbitrarily, when the timer number of having stored in the timer queue is zero, can directly this timer be stored into timer queue.Correspondingly, " a part of timer " described herein and " another part timer " also can be zero to a plurality of arbitrarily.
Step 302 is obtained current triggered time and the callback method that comes the timer of head of the queue in timer queue;
Terminal can at first be obtained triggered time and the callback method of a timer that comes head of the queue in the timer queue.In timer queue, come a timer of head of the queue, that is to say in the timer queue that the triggered time is apart from a current time timer the earliest in all timers.If this timer also has cycle period information, can when the triggered time of obtaining this timer and callback method, obtain simultaneously the cycle period information of this timer.
Step 303, according to triggered time and callback method unlatching timing thread, the timing thread is in the moment of triggered time appointment Automatically invoked callback method and execution;
Terminal can be opened a timing thread according to this triggered time and callback method after the triggered time that gets access to this timer and callback method, this timing thread will be at the moment of triggered time appointment Automatically invoked callback method.This process is the concrete implementation of a timer, and this partial content major part is prior art, gives unnecessary details no longer one by one at this.
Step 304, the executed timer of deletion callback method from timer queue; Continue to carry out triggered time of obtaining the current timer that in timer queue, comes head of the queue and the step of callback method.
After current timer is finished, terminal can be deleted the executed current timer of callback method from timer queue, then the terminal repeated execution of steps 302, also be that the next timer of the executed current timer of callback method in timer queue will be retrieved as by terminal and come a timer of head of the queue in the timer queue this moment, thereby can realize carrying out successively the process of each timer in the timer queue.
Need to prove, in certain embodiments, after current timer was finished, terminal can also judge whether the executed current timer of callback method has cycle period information; If be judged as very, then terminal can be obtained the cycle period in the cycle period information; Then after getting access to cycle period, the triggered time of the executed current timer of callback method is revised as: the former triggered time adds the above cycle period; To revise current timer after the triggered time reinserts in the timer sequence and stores again.In this process, can remain unchanged for the ID that current timer has number.Be the timer in 24 hours the alarm clock application program such as, cycle period, can be after once being finished, (former triggered time+24 hour) as the new triggered time, then again are stored into and wait in line in the timer queue to carry out.Certainly, if the executed current timer of terminal judges callback method does not have cycle period information, then terminal can be deleted the executed current timer of callback method from timer queue.
Also need to prove, be finished and another timer when beginning to carry out at a timer, can adopt former timing thread is closed, then reopen the mode of a timing thread; Can not adopt yet former timing thread is closed, still former timing thread be adjusted the mode of follow-up reforwarding row according to the relevant parameter of another timer.
Step 305 receives the triggered time modification signal that acts on a timer in the timer queue;
User or application program can also be made amendment to the triggered time that is stored into the timer in the timer queue, this moment, terminal can receive the triggered time modification signal that acts on the some timers in the timer queue, and this triggered time is revised the information that generally includes the new triggered time in signal.
Step 306, the triggered time of revising this timer of modification of signal according to the triggered time;
Terminal is receiving after the triggered time revises signal, and the original triggered time that can revise this timer according to the information that the triggered time is revised the new triggered time that comprises in the signal is the new triggered time.
Step 307 is adjusted the position of this timer in timer queue to satisfy the triggered time by early to late order according to the amended triggered time.
Because modification has occured in the triggered time of this timer, then adjust the position of this timer in timer queue to satisfy the triggered time by the order of morning to evening according to the amended triggered time, also be that the timer that terminal needs to revise in the triggered time is stored in the timer queue again, with guarantee each timer in the timer queue be according to the triggered time by early storing to late order.
In sum, the execution of the timer realization method that the embodiment of the invention two provides by adopting timer queue to dispatch a plurality of timers, and only carry out at one time the method for a triggered time timer the earliest, no matter so that there are what timers in the system, also always only enable a timing thread, so that the technical program can obviously reduce taking system resource.Simultaneously, the timer realization method that the embodiment of the invention two provides can also be stored in the timer queue to the timer with cycle period information automatically again, can also adjust its position in timer queue to the timer of revising the triggered time, so that this timer realization method has better applicability.
Embodiment three
Please refer to Fig. 4, it shows the block diagram of the timer implement device that the embodiment of the invention three provides.This timer implement device can be used for the terminal that operation has the application program that comprises the clocked flip logic, and this timer implement device comprises queue management module 420, acquisition of information module 440 and timing execution module 460.
Queue management module 420 is used for newly-built timer was stored by early inserting the timer queue that sets in advance to the order in evening according to the triggered time, and each timer has triggered time and the callback method of self.
Acquisition of information module 440 is used for obtaining current triggered time and the callback method that comes the timer of head of the queue at timer queue;
Regularly execution module 460 is opened the timing thread for the triggered time that gets access to according to acquisition of information module 440 and callback method, and this timing thread is in the moment of triggered time appointment Automatically invoked callback method and execution.
Specifically, queue management module 420 can comprise: timer acquiring unit 421, triggered time judging unit 422 and timer storage unit 423, as shown in Figure 5.Wherein, timer acquiring unit 421 is used for obtaining a newly-built timer, and this timer has triggered time and the callback method of self; Triggered time judging unit 422 is used for the morning and evening in the triggered time of the triggered time of judgement timer and each timer that timer queue has been stored; If being used for triggered time judging unit 422, timer storage unit 423 judges that the triggered time of newly-built timer is early than the triggered time of a part of timer of timer queue, when then newly-built timer being stored into timer queue, be stored in before this part timer; Simultaneously, if also being used for triggered time judging unit 422, timer storage unit 423 judges that the triggered time of newly-built timer is later than the triggered time of timer queue another part timer, when then newly-built timer being stored into timer queue, be stored in after this another part timer.
Queue management module 420 can also specifically comprise: delete timer unit 424, as shown in Figure 5.After timing execution module 460 was carried out the callback method of a timer, delete timer unit 424 was used for from the executed timer of timer queue this callback method of deletion.Simultaneously, acquisition of information module 440 also is used for continuing to obtain current triggered time and the callback method that comes the timer of head of the queue in timer queue after the executed timer of delete timer unit 424 deletion callback methods.
In embodiment further, queue management module 420 can also specifically comprise: cycle criterion unit 425, cycle acquiring unit 426 and the first triggered time are revised unit 427, as shown in Figure 5.After timing execution module 460 was carried out the callback method of a timer, cycle criterion unit 425 was used for judging whether the executed timer of callback method has cycle period information; If cycle criterion unit 425 judges that the executed timer of callback method does not have cycle period information, is then deleted the executed timer of this callback method by delete timer unit 424 from timer queue; If cycle criterion unit 425 judges that the executed timer of callback method has cycle period information, cycle acquiring unit 426 is used for obtaining the cycle period of cycle period information; The first triggered time revised unit 427 and is used for the triggered time of callback method executed timer is revised as: the former triggered time adds the cycle period that cycle acquiring unit 426 gets access to; Timer storage unit 423 also is used for revising described timer after the triggered time and reinserts the timer sequence and store.
In embodiment further, queue management module 420 also specifically comprises: revise signal receiving unit 4281, the second triggered time and revise unit 4282 and regulator unit 4283, as shown in Figure 5.Wherein, revise the triggered time modification signal that signal receiving unit 4281 is used for receiving a timer that acts on timer queue; The second triggered time was revised the triggered time that unit 4282 is used for revising according to the triggered time modification of signal timer; Regulator unit 4283 be used for according to the amended triggered time adjust timer in the position of timer queue to satisfy the triggered time by early to late storage order.
In sum, the execution of the timer implement device that the embodiment of the invention three provides by adopting timer queue to dispatch a plurality of timers, and only carry out at one time the method for a triggered time timer the earliest, no matter so that there are what timers in the system, also always only enable a timing thread, so that the technical program can obviously reduce taking system resource.Simultaneously, the timer implement device that the embodiment of the invention three provides can also be stored in the timer queue to the timer with cyclical information automatically again, can also adjust its position in timer queue to the timer of revising the triggered time, so that this timer implement device has better applicability.
Need to prove: the timer implement device that above-described embodiment provides is in realizing the timer process time, only the division with above-mentioned each functional module is illustrated, in the practical application, can as required the above-mentioned functions distribution be finished by different functional modules, the inner structure that is about to device is divided into different functional modules, to finish all or part of function described above.In addition, timer implement device and timer realization method embodiment that above-described embodiment provides belong to same design, and its specific implementation process sees embodiment of the method for details, repeats no more here.
The all or part of step that one of ordinary skill in the art will appreciate that realization above-described embodiment can be finished by hardware, also can come the relevant hardware of instruction to finish by program, described program can be stored in a kind of computer-readable recording medium, the above-mentioned storage medium of mentioning can be ROM (read-only memory), disk or CD etc.
The above only is preferred embodiment of the present invention, and is in order to limit the present invention, within the spirit and principles in the present invention not all, any modification of doing, is equal to replacement, improvement etc., all should be included within protection scope of the present invention.

Claims (10)

1. a timer realization method is characterized in that, described method comprises:
Newly-built timer was stored by early inserting in the timer queue that sets in advance to the order in evening according to the triggered time, and described timer has triggered time and the callback method of self;
Obtain current triggered time and the callback method that in described timer queue, comes the timer of head of the queue;
According to described triggered time and callback method unlatching timing thread, described timing thread is in the described callback method of the moment of described triggered time appointment Automatically invoked and execution.
2. timer realization method according to claim 1 is characterized in that, described newly-built timer was inserted in the timer queue that sets in advance by the order in morning to evening according to the triggered time stored, and specifically comprises:
Obtain a newly-built timer, described newly-built timer has triggered time and the callback method of self;
Judge the morning and evening in the triggered time of each timer of having stored in triggered time of described newly-built timer and the described timer queue;
If judge the triggered time of described newly-built timer early than the triggered time of a part of timer in the described timer queue, when then described newly-built timer being stored into described timer queue, be stored in before described a part of timer;
Be later than the triggered time of another part timer in the described timer queue if judge the triggered time of described newly-built timer, when then described newly-built timer being stored into described timer queue, be stored in after described another part timer.
3. timer realization method according to claim 1, it is characterized in that, described according to described triggered time and callback method unlatching timing thread, described timing thread also comprises at the described callback method of the moment of described triggered time appointment Automatically invoked and after carrying out:
The executed timer of the described callback method of deletion from described timer queue;
Continue to carry out triggered time of obtaining the current timer that in described timer queue, comes head of the queue and the step of callback method.
4. timer realization method according to claim 1, it is characterized in that, described according to described triggered time and callback method unlatching timing thread, described timing thread also comprises at the described callback method of the moment of described triggered time appointment Automatically invoked and after carrying out:
Whether that judges the executed timer of described callback method has cycle period information;
If so, then obtain cycle period in the described cycle period information;
The triggered time of the executed timer of described callback method is revised as: the former triggered time adds the above cycle period;
Reinsert in the described timer sequence and store revising described timer after the triggered time.
5. according to claim 1 to 4 arbitrary described timer realization method, it is characterized in that, described method also comprises:
Reception acts on the triggered time modification signal of a timer in the described timer queue;
Revise the triggered time of the described timer of modification of signal according to the described triggered time;
Adjust the position of described timer in described timer queue to satisfy the described triggered time by early to late storage order according to the amended triggered time.
6. a timer implement device is characterized in that, described device comprises:
Queue management module is used for newly-built timer was stored by early inserting the timer queue that sets in advance to the order in evening according to the triggered time, and described timer has triggered time and the callback method of self;
The acquisition of information module is used for obtaining current triggered time and the callback method that comes the timer of head of the queue at described timer queue;
Regularly execution module is used for opening the timing thread according to described triggered time and callback method, and described timing thread is in the described callback method of the moment of described triggered time appointment Automatically invoked and execution.
7. timer implement device according to claim 6 is characterized in that, described queue management module comprises: timer acquiring unit, triggered time judging unit and timer storage unit;
Described timer acquiring unit is used for obtaining a newly-built timer, and described newly-built timer has triggered time and the callback method of self;
Described triggered time judging unit is for the morning and evening in the triggered time of judging the triggered time of described newly-built timer and each timer that described timer queue has been stored;
Described timer storage unit, if be used for the triggered time of the described newly-built timer of described triggered time judgment unit judges early than the triggered time of a part of timer of described timer queue, when then described newly-built timer being stored into described timer queue, be stored in before described a part of timer;
Described timer storage unit, if the triggered time that also is used for the described newly-built timer of described triggered time judgment unit judges is later than the triggered time of described timer queue another part timer, when then described newly-built timer being stored into described timer queue, be stored in after described another part timer.
8. timer implement device according to claim 6 is characterized in that, described queue management module also specifically comprises: the delete timer unit;
Described delete timer unit is used for from the executed timer of the described timer queue described callback method of deletion;
Described acquisition of information module also is used for continuing to obtain current triggered time and the callback method that comes the timer of head of the queue in described timer queue after the executed timer of the described callback method of described delete timer element deletion.
9. timer implement device according to claim 6 is characterized in that, described queue management module also specifically comprises: cycle criterion unit, cycle acquiring unit and the first triggered time are revised the unit;
Described cycle criterion unit is used for judging whether the executed timer of described callback method has cycle period information;
Described cycle acquiring unit has cycle period information if be used for the executed timer of the described callback method of described cycle criterion unit judges, then obtains the cycle period in the described cycle period information;
Described the first triggered time is revised the unit, is used for the triggered time of described callback method executed timer is revised as: the former triggered time adds the above cycle period;
Described timer storage unit also is used for revising described timer after the triggered time and reinserts described timer sequence and store.
10. according to claim 6 to 9 arbitrary described timer implement devices, it is characterized in that, described queue management module also specifically comprises: revise signal receiving unit, the second triggered time modification unit and regulator unit;
Described modification signal receiving unit is used for the triggered time modification signal that reception acts on a timer of described timer queue;
Described the second triggered time is revised the unit, is used for revising according to the described triggered time triggered time of the described timer of modification of signal;
Described regulator unit, be used for according to the amended triggered time adjust described timer in the position of described timer queue to satisfy the described triggered time by early to late storage order.
CN2012100757192A 2012-03-21 2012-03-21 Timer implementation method and device Pending CN103324469A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2012100757192A CN103324469A (en) 2012-03-21 2012-03-21 Timer implementation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2012100757192A CN103324469A (en) 2012-03-21 2012-03-21 Timer implementation method and device

Publications (1)

Publication Number Publication Date
CN103324469A true CN103324469A (en) 2013-09-25

Family

ID=49193239

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2012100757192A Pending CN103324469A (en) 2012-03-21 2012-03-21 Timer implementation method and device

Country Status (1)

Country Link
CN (1) CN103324469A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105511879A (en) * 2015-12-11 2016-04-20 北京元心科技有限公司 Multi-system starting method based on timer as well as intelligent terminal
CN105979078A (en) * 2016-04-27 2016-09-28 努比亚技术有限公司 Alarm clock processing method and mobile terminal
CN106250108A (en) * 2016-07-18 2016-12-21 中国电子科技集团公司第二十八研究所 A kind of method hanging time control in thread
CN111694619A (en) * 2020-06-09 2020-09-22 重庆锐云科技有限公司 Method, device and equipment for realizing timer based on refresh rate and storage medium
CN113791944A (en) * 2021-01-18 2021-12-14 北京京东拓先科技有限公司 Monitoring method and device of page timer, medium and electronic equipment
CN115268565A (en) * 2022-06-27 2022-11-01 北京五八信息技术有限公司 Timer control method and device and electronic equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1870767A (en) * 2005-12-14 2006-11-29 华为技术有限公司 Method for managing timer task
CN1873615A (en) * 2006-01-20 2006-12-06 华为技术有限公司 Method for servicing task of timer
CN101216786A (en) * 2007-01-05 2008-07-09 三星电子株式会社 Method, medium and apparatus scheduling tasks in a real time operating system
CN101853047A (en) * 2010-05-18 2010-10-06 瑞斯康达科技发展股份有限公司 Timer realization method and device
CN102270156A (en) * 2011-05-30 2011-12-07 北京华源格林科技有限公司 Method for managing real-time embedded system timers

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1870767A (en) * 2005-12-14 2006-11-29 华为技术有限公司 Method for managing timer task
CN1873615A (en) * 2006-01-20 2006-12-06 华为技术有限公司 Method for servicing task of timer
CN101216786A (en) * 2007-01-05 2008-07-09 三星电子株式会社 Method, medium and apparatus scheduling tasks in a real time operating system
CN101853047A (en) * 2010-05-18 2010-10-06 瑞斯康达科技发展股份有限公司 Timer realization method and device
CN102270156A (en) * 2011-05-30 2011-12-07 北京华源格林科技有限公司 Method for managing real-time embedded system timers

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105511879A (en) * 2015-12-11 2016-04-20 北京元心科技有限公司 Multi-system starting method based on timer as well as intelligent terminal
CN105979078A (en) * 2016-04-27 2016-09-28 努比亚技术有限公司 Alarm clock processing method and mobile terminal
CN106250108A (en) * 2016-07-18 2016-12-21 中国电子科技集团公司第二十八研究所 A kind of method hanging time control in thread
CN106250108B (en) * 2016-07-18 2019-05-17 中国电子科技集团公司第二十八研究所 The method of time control is hung in a kind of thread
CN111694619A (en) * 2020-06-09 2020-09-22 重庆锐云科技有限公司 Method, device and equipment for realizing timer based on refresh rate and storage medium
CN113791944A (en) * 2021-01-18 2021-12-14 北京京东拓先科技有限公司 Monitoring method and device of page timer, medium and electronic equipment
CN115268565A (en) * 2022-06-27 2022-11-01 北京五八信息技术有限公司 Timer control method and device and electronic equipment

Similar Documents

Publication Publication Date Title
CN103324469A (en) Timer implementation method and device
CN109918141B (en) Thread execution method, thread execution device, terminal and storage medium
CN109558234A (en) A kind of timed task dispatching method and device
CN103345415B (en) The terminal power-economizing method of management intervalometer and device
CN104199730B (en) A kind of single thread multi-task processing method based on synchronous i/o multiplexing mechanism
CN107015849B (en) Timed task reminding method and device
CN109766349A (en) The anti-weighing method of task, device, computer equipment and storage medium
CN101667147A (en) Multitasking controllable automatic snapshot method
TW202102952A (en) Robotic resource task cycle management and control method and apparatus
CN107491346A (en) A kind of task processing method of application, apparatus and system
CN103475786A (en) Method and system for setting mobile terminal alarm clock
WO2015168997A1 (en) A method and device for terminal automatically displaying
CN105607904B (en) The Quick Development Framework and its application method of communication software based on Linux platform
CN110286739A (en) The power consumption control method and device of long-haul telemetry terminal
CN112199170A (en) Timing processing method, device and equipment of real-time operating system and storage medium
CN109656693A (en) Method for scheduling task, device, server and storage medium
CN105611074A (en) Method and system for optimizing information pushing time according to alarm clock
CN107704362A (en) A kind of method and device based on Ambari monitoring big data components
CN106775620A (en) A kind of timing method and device
CN114048015A (en) Task scheduling method and device
CN118295778A (en) Task scheduling method and device, electronic equipment and storage medium
CN103401998A (en) Realization method of correlation alarm clock on mobile equipment
CN107506292B (en) Automatic test method for random read time delay under multilevel non-uniform directory
US8335758B2 (en) Data ETL method applied to real-time data ETL system
CN108875017A (en) A kind of massive data synchronization system and method based on Sqoop technology

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20130925

RJ01 Rejection of invention patent application after publication