CN106775620B - Timing method and device - Google Patents

Timing method and device Download PDF

Info

Publication number
CN106775620B
CN106775620B CN201610999432.7A CN201610999432A CN106775620B CN 106775620 B CN106775620 B CN 106775620B CN 201610999432 A CN201610999432 A CN 201610999432A CN 106775620 B CN106775620 B CN 106775620B
Authority
CN
China
Prior art keywords
timing
type
timer
function
task
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.)
Active
Application number
CN201610999432.7A
Other languages
Chinese (zh)
Other versions
CN106775620A (en
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.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology 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 Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Priority to CN201610999432.7A priority Critical patent/CN106775620B/en
Publication of CN106775620A publication Critical patent/CN106775620A/en
Application granted granted Critical
Publication of CN106775620B publication Critical patent/CN106775620B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • G06F8/22Procedural

Abstract

The invention provides a timing method and a timing device, wherein the method comprises the following steps: detecting whether a program contains a timer function in real time when the program is operated; when detecting that the program contains a timer function, determining the timing type of the current timing task according to the type parameters carried by the timer function; and executing the current timing task by adopting a timing mode corresponding to the timing type according to the timing parameters carried by the timer function. According to the invention, the common android timers are divided into two timing types, namely a short-term timing type and a long-term timing type, developers do not need to master the use methods of various timers, only need to clearly determine whether short-term timing or long-term timing is needed, and set the type parameters and the timing parameters of the timer function, when the program is operated, the timing type is automatically determined according to the type parameters of the timer function, and the timing mode corresponding to the timing type is adopted for timing, so that the use of the timers by the developers is simplified, the complexity of program development is reduced, and the maintenance difficulty of the program is reduced.

Description

Timing method and device
Technical Field
The invention relates to the technical field of computers, in particular to a timing method and a timing device.
Background
At present, developers often use timers in the android development process, and an android system provides various timers. For example, a timer using a sleep method of Handler and a thread, a timer using a postDelayed method of Handler, a timer using a method of Handler combining a timer and a TimerTask, and an alarmmmanager.
Due to the variety of timers provided by the android system, developers need to spend a lot of time to learn and master the use methods of various timers before using the timers, so that the time cost for flexibly using the timers is very high. The use of multiple timers also creates the complexity of developing programs, so that the processing of the timers by developers when developing programs becomes complex and changeable, and the difficulty of maintaining the programs increases as the types of the timers used by the programs increase.
Disclosure of Invention
In view of this, an object of the embodiments of the present invention is to provide a timing method and apparatus, where an android common timer is divided into two types, namely a short-term timing type and a long-term timing type, and a developer does not need to master the use methods of multiple timers, and only needs to explicitly determine whether short-term timing or long-term timing is needed, and set the type parameters and timing parameters of a timer function, and when a program is run, the timing type is automatically determined according to the type parameters of the timer function, and timing is performed in a timing manner corresponding to the timing type.
In a first aspect, an embodiment of the present invention provides a timing method, where the method includes:
detecting whether a program contains a timer function in real time when the program is operated;
when detecting that a program contains a timer function, determining a timing type to which a current timing task belongs according to a type parameter carried by the timer function;
and executing the current timing task by adopting a timing mode corresponding to the timing type according to the timing parameters carried by the timer function.
With reference to the first aspect, an embodiment of the present invention provides a first possible implementation manner of the first aspect, where, when the timing type is a short-term type, the executing, by using a timing mode corresponding to the timing type, the current timing task according to a timing parameter carried by the timer function includes:
starting a timing thread through a thread pool;
determining the timing parameters carried by the timer function as parameters of a sleep function;
and executing the sleep function through the timing thread to time the current timing task.
With reference to the first aspect, an embodiment of the present invention provides a second possible implementation manner of the first aspect, where, when the timing type is a long-term type, the executing, by using a timing mode corresponding to the timing type, the current timing task according to a timing parameter carried by the timer function includes:
determining the timing parameters carried by the timer functions as the parameters of the repeated alarm clock functions in the global timer AlarmManager;
and calling the repeated alarm clock function in the AlarmManager to time the current timing task.
With reference to the first aspect, an embodiment of the present invention provides a third possible implementation manner of the first aspect, where after the executing the current timing task by using the timing mode corresponding to the timing type according to the timing parameter carried by the timer function, the method further includes:
when the current timing task is overtime, packaging event parameters carried by the timer function into timer overtime information;
and calling a broadcast sending function to send the timer overtime information to a preset position.
With reference to the third possible implementation manner of the first aspect, an embodiment of the present invention provides a fourth possible implementation manner of the first aspect, where the method further includes:
when the timer overtime information is detected to exist at the preset position, analyzing event parameters from the timer overtime information;
and determining a timing task with overtime timing according to the event parameters.
In a second aspect, an embodiment of the present invention provides a timing device, where the timing device includes:
the detection module is used for detecting whether the program contains a timer function in real time when the program is operated;
the determining module is used for determining the timing type of the current timing task according to the type parameters carried by the timer function when the detecting module detects that the program contains the timer function;
and the execution module is used for executing the current timing task by adopting a timing mode corresponding to the timing type according to the timing parameters carried by the timer function.
With reference to the second aspect, an embodiment of the present invention provides a first possible implementation manner of the second aspect, where when the timing type is a short-term type, the executing module includes:
the starting unit is used for starting the timing thread through the thread pool;
a first determining unit, configured to determine a timing parameter carried by the timer function as a parameter of a sleep function;
and the first timing unit is used for executing the sleep function through the timing thread and timing the current timing task.
With reference to the second aspect, an embodiment of the present invention provides a second possible implementation manner of the second aspect, where when the timing type is a long-term type, the executing module includes:
a second determining unit, configured to determine a timing parameter carried by the timer function as a parameter of a repeating alarm clock function in an global timer alarmmmanager;
and the second timing unit is used for calling the repeated alarm clock function in the AlarmManager and timing the current timing task.
With reference to the second aspect, an embodiment of the present invention provides a third possible implementation manner of the second aspect, where the apparatus further includes:
the overtime broadcasting module is used for encapsulating the event parameters carried by the timer function into the overtime information of the timer when the current timing task is overtime; and calling a broadcast sending function to send the timer overtime information to a preset position.
With reference to the third possible implementation manner of the second aspect, an embodiment of the present invention provides a fourth possible implementation manner of the second aspect, where the apparatus further includes:
the task determining module is used for analyzing event parameters from the timer overtime information when the timer overtime information is detected to exist at the preset position; and determining a timing task with overtime timing according to the event parameters.
In the method and the device provided by the embodiment of the invention, when the program is operated, whether the program contains a timer function is detected in real time; when detecting that the program contains a timer function, determining the timing type of the current timing task according to the type parameters carried by the timer function; and executing the current timing task by adopting a timing mode corresponding to the timing type according to the timing parameters carried by the timer function. According to the invention, the common android timers are divided into two timing types, namely a short-term timing type and a long-term timing type, developers do not need to master the use methods of various timers, only need to clearly determine whether short-term timing or long-term timing is needed, and set the type parameters and the timing parameters of the timer function, when the program is operated, the timing type is automatically determined according to the type parameters of the timer function, and the timing mode corresponding to the timing type is adopted for timing, so that the use of the timers by the developers is simplified, the complexity of program development is reduced, and the maintenance difficulty of the program is reduced.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention, and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained from the drawings without inventive effort.
Fig. 1 is a flow chart of a timing method provided in embodiment 1 of the present invention;
fig. 2 is a schematic flow chart of short-term timing provided in embodiment 1 of the present invention;
fig. 3 is a schematic flow chart of long-term timing provided in embodiment 1 of the present invention;
fig. 4 is a schematic structural diagram illustrating a timing device provided in embodiment 2 of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a developer in the art without inventive step, are within the scope of the present invention.
In consideration of the fact that in the prior art, the types of timers provided by the android system are various, developers need to spend a lot of time to learn and master the use methods of various timers before using the timers, and time cost for flexibly using the timers is high. The various timers increase the complexity of developing programs, so that the processing of the timers by developers during the program development becomes complicated and changeable, and the maintenance difficulty of the programs is increased along with the increase of the types of the timers used by the programs. Based on this, the embodiment of the present invention provides a timing method and apparatus, which are described below by way of embodiments.
Example 1
The embodiment of the invention provides a timing method.
In the android development process, a timer is often used. The android provides timers that are roughly four:
(1) timing mode using a sleep function sleep () of Handler and thread
The Handler is a class used for communication between the main thread and the sub-thread, and can open the sub-thread, execute a sleep function sleep () in the sub-thread, and notify the timeout of the timer of the main thread through the Handler after the sleep time is completed.
When the timer is used, the timing length can be adjusted by adjusting the sleep time of the sleep function sleep (), so that the timing function is realized. However, if the sleep time is too long, memory leakage may occur, and the application part memory may not be released. In addition, when the system enters the sleep state, the timer cannot perform the timing task because the system is already sleeping. The main usage scenario of this timer is to perform a short timed timing task. For a timing task with long-term timing, the timer has certain limitation and even cannot complete timing.
(2) Timing mode of postdelay function postDelayed () adopting Handler
The timing principle of the timer is similar to that of the timer (1), and only the sleep function sleep () is encapsulated by one layer through the post delay function postDelayed (), so that the function of the timer can be completed only by transmitting a time parameter into the timer. Since the timer is similar to the timer of type (1) in the idea logic, the main usage scenario of the timer is also a timing task for short-term timing.
(3) A timer mode combining Handler, timer and TimerTask
Compared with the timing modes (1) and (2), the advantage of using the Handler in combination with the Timer and the TimerTask is that the timing task is not based on the sleep mode to record time, but records timing information through the Timer provided by the system, so the timing mode does not cause memory leakage, but cannot avoid the problem of Timer failure caused by the system sleep, and therefore the timing mode can only be applied to the timing task with short-term timing.
(4) AlarmManager (Global timer)
When using the alarmmmanager, if the timer is overtime in the system sleep state, the system is automatically awakened to trigger the timing task. The alarmmmanager has a function of waking up a Central Processing Unit (CPU), and can ensure that the CPU can normally work each time a specific task needs to be executed, so the alarmmmanager can be applied to both short-term timing tasks and long-term timing tasks.
As can be seen from the above description, the timers in the (1), (2) and (3) are all Handler-based timers, and the system will not be available after sleeping and can only be applied to timing tasks with short-term timing. The timer in the (4) is based on an AlarmManager, can still be used after the system is dormant, and is suitable for a timing task timed in a short term and a timing task timed in a long term.
Based on the various timers, the embodiment of the invention divides the timing task into two timing types of a short-term type and a long-term type, uniformly packages the timers by a global timer function SetGlobalTimer (), and processes the timing task by adopting a timing mode corresponding to the type parameter according to the type parameter carried by the timer function SetGlobalTimer ().
Referring to fig. 1, the method specifically includes the following steps:
step 101: when the program is running, whether the timer function is included in the program is detected in real time.
When a developer needs to use a timer to execute a timing task during android development, the developer determines whether the timing task is a long-term timing task or a short-term timing task, writes a timer function SetGlobalTimer () in a program, and assigns values to each parameter of the timer function SetGlobalTimer ().
In the embodiment of the present invention, the parameters of the timer function include a type parameter, a timing parameter, and an event parameter, and the specific function design of the timer function setglobaltimeter () is as follows:
SetGlobalTimer(int type,long startTime,long intervalTime,int counts,string event)
wherein type is a type parameter, and int indicates that the data type of the type parameter type is integer. The value of Type is used to distinguish whether the timed task is a short-term Type or a long-term Type. Since the timer can be divided into two categories, one is a Handler-based timer, and the other is an alarmmmanager-based timer, the value of TYPE in the embodiment of the present invention may be TYPE _ handle or TYPE _ ALARM _ MANAGER.
TYPE _ handle is a defined constant, a constant value can be preset to be 0 or 1, etc., and is used for indicating that the timing TYPE of the current timing task is a short-term TYPE, and the timer required to be used is a timer implemented based on a HANDLER.
TYPE _ ALARM _ MANAGER is another constant defined, a constant value may be preset to 2 or 3, etc., for indicating that the timing TYPE of the current timing task is a long-term TYPE, and the required eleven-numbered timer is a timer implemented based on alarmmmanager.
In the timer function setglobalttimer (), the parameters startTime, intervalTime, and counts are timing parameters. The data type of the parameter startTime is long integer long, which represents the first execution time of the alarm clock and takes milliseconds as a unit. The data type of the parameter intervalTime is also long integer long, representing the time interval between two alarm clock executions, also in milliseconds. The data type of the parameter counts is integer int, which indicates the number of times the timer is executed, i.e. the number of times the timed task is repeatedly executed.
The parameter event is an event parameter of a timer function SetGlobalTimer (), and the data type of the parameter event is a character type string, which represents a timed task.
When a developer writes a program, the developer calls a timer function SetGlobalttimer () at a position where a timing task needs to be executed, and assigns values to the type parameters and the timing function. When the running program is compiled, the terminal detects whether the currently running program contains a timer function in real time, and when the currently running program contains the timer function, the current timing task corresponding to the timer function is executed through the following operations of steps 102 and 103.
Step 102: and when detecting that the program contains the timer function, determining the timing type of the current timing task according to the type parameters carried by the timer function.
And when detecting that the program contains a timing function, acquiring the value of the TYPE parameter TYPE carried by the timer function from the timer function, and if the value of the TYPE parameter TYPE is TYPE _ HANDLER, determining that the timing TYPE to which the current timing task belongs is a short-term TYPE. And if the TYPE parameter TYPE is taken as TYPE _ ALARM _ MANAGER, determining that the timing TYPE to which the current timing task belongs is a long-term TYPE.
Step 103: and executing the current timing task by adopting a timing mode corresponding to the timing type according to the timing parameters carried by the timer function.
When detecting that the program contains the timing function, the timer function also obtains the timing parameters startTime, intervaltimeand counts carried by the timer function. When the step 102 determines that the timing type to which the current timing task belongs is a short-term type, the current timing task is executed in the following manner, specifically including:
starting a timing thread through a thread pool; determining a timing parameter carried by a timer function as a parameter of a sleep function; and executing the sleep function through the timing thread to time the current timing task.
To prevent a timing task from affecting the operation of a main thread, embodiments of the invention perform a timing process in a sub-thread. In addition, in order to facilitate the management of the threads, the thread pool is used for starting the sub-threads, and the timing thread is started through the thread pool, so that the operation of continuously creating new threads is avoided, the system resources are saved, and certain pressure and performance overhead on the system are avoided.
In the embodiment of the present invention, for a short-term type timing task, a sleep () sleep function provided by JDK (Java Development Kit, software Development Kit in scripting language) is used to implement the whole timing process. When the timing thread executes the sleep function sleep (), the timing thread is in a waiting state, and only after the sleep function sleep () is timed, the subsequent operation can be executed.
When the step 102 determines that the timing type to which the current timing task belongs is a long-term type, the current timing task is executed in the following manner, specifically including:
determining a timing parameter carried by a timer function as a parameter of a repetition alarm clock function setrising () in an alarmmmanager; and calling a repetition alarm clock function setalarm () in the AlarmManager to time the current timing task.
The timing parameters startTime, intervalTime and counts are transferred to the repetition alarm function settiming (), and the whole timing process of the current timing task is realized through the repetition alarm function settiming () provided by the alarmmmanager.
In the embodiment of the invention, whether the timing type of the current timing task is a short-term type or a long-term type, whether the timing is overtime needs to be judged in real time in the process of executing the current timing task, and when the current timing task is overtime, an event parameter event carried by a timer function is encapsulated into the overtime information of the timer; and calling a broadcast sending function to send the timer timeout information to a preset position.
And when the timing task is overtime, the timer overtime information is broadcasted in a broadcasting mode. All timing overtime information is broadcasted to the preset position, so that the processing of all timers can be effectively ensured to be processed in the same place, and the maintainability and the robustness of the program can be improved. Since the tasks after the timing timeout are processed in the same file, different timing tasks need to be distinguished, and event parameter events are encapsulated in the timing timeout information for broadcasting, so that different timing tasks can be judged by different event receiving places.
The android system provides a broadcast delivery function sendbroadcast (intgent) for broadcast delivery. Wherein, the parameter Intgent is used for storing data which needs to be carried by the broadcast. The embodiment of the invention stores the event parameter event into the event, and the specific storage mode is to call a function putExtra () in the event and store the event parameter event into the event. Then, the broadcast sending function sendbroadcast (intgent) is called to send out the broadcast.
The terminal detects whether timer overtime information exists at a preset position in real time, and when the timer overtime information exists at the preset position, event parameter events are analyzed from the timer overtime information; and determining the timed task with timed overtime according to the event parameter event.
The specific parsing process for parsing out the event parameter event is to obtain the passed event parameter event by calling a function getExtra () in the event.
In the embodiment of the present invention, if the current timing task is timing for multiple times, the value of the timing parameter Counts is decremented by 1 every time a timing operation is performed. And when the timing is overtime, judging whether the timing is finished according to the value of the timing parameter Counts, and if the value of the Counts is greater than 0, continuing to repeat the timing task. If the value of Counts is 0, it is determined that the current timing task has been completed and no further processing is required.
In the embodiment of the invention, the timing tasks are divided into short-term types and long-term types, and different timing modes are adopted for timing different types of timing tasks. As shown in the flow diagram of short-term timing shown in fig. 2, when the timing type to which the timing task belongs is a short-term type, the thread pool starts a timing thread, executes a sleep function sleep () through the timing thread, broadcasts a global notification when the timing is over, then judges whether the current timing task is timed for multiple times, and if so, returns to continuously execute the sleep function sleep () for timing. If not, the timing is determined to be complete.
As shown in the flowchart of long-term timing shown in fig. 3, when the timing type to which the timing task belongs is a long-term type, the repetition alarm function setalarm () is executed to perform timing counting, and when the timing is timed out, the global notification is broadcasted.
The embodiment of the invention uniformly processes common timer schemes in android and realizes different timing tasks according to different parameters transmitted by a user in a timer function. Meanwhile, the timing overtime information is broadcasted uniformly after timing overtime, and notification processing logic after the task of each timer arrives is specified. By integrating various timers of the system and optimizing the notification of the arrival of the timing tasks, developers can conveniently use any timing task in the system, and the place for processing all the timing tasks is fixed, so that the developed program structure is clearer, and the later maintenance and expansion are easier.
In the embodiment of the invention, when the program is operated, whether the program contains a timer function is detected in real time; when detecting that the program contains a timer function, determining the timing type of the current timing task according to the type parameters carried by the timer function; and executing the current timing task by adopting a timing mode corresponding to the timing type according to the timing parameters carried by the timer function. According to the invention, the common android timers are divided into two timing types, namely a short-term timing type and a long-term timing type, developers do not need to master the use methods of various timers, only need to clearly determine whether short-term timing or long-term timing is needed, and set the type parameters and the timing parameters of the timer function, when the program is operated, the timing type is automatically determined according to the type parameters of the timer function, and the timing mode corresponding to the timing type is adopted for timing, so that the use of the timers by the developers is simplified, the complexity of program development is reduced, and the maintenance difficulty of the program is reduced.
Example 2
Referring to fig. 4, an embodiment of the present invention provides a timing device, configured to execute the timing method provided in embodiment 1. The device specifically includes:
a detection module 201, configured to detect whether a timer function is included in a program in real time when the program is running;
a determining module 202, configured to determine, when the detecting module 201 detects that the program includes a timer function, a timing type to which the current timing task belongs according to a type parameter carried by the timer function;
and the execution module 203 is configured to execute the current timing task in a timing manner corresponding to the timing type according to the timing parameter carried by the timer function.
When the timing type is a short-term type, the execution module 203 includes:
the starting unit is used for starting the timing thread through the thread pool;
the first determining unit is used for determining the timing parameters carried by the timer function as the parameters of the sleep function;
and the first timing unit is used for executing the sleep function through the timing thread and timing the current timing task.
When the timing type is a long-term type, the execution module 203 includes:
a second determining unit, configured to determine a timing parameter carried by the timer function as a parameter of a repetition alarm clock function setreporting in an global timer alarmmmanager;
and the second timing unit is used for calling setcommunicating in the AlarmManager to time the current timing task.
In an embodiment of the present invention, the apparatus further includes:
the overtime broadcasting module is used for encapsulating the event parameters carried by the timer function into the overtime information of the timer when the current timing task is overtime; and calling a broadcast sending function to send the timer timeout information to a preset position.
The task determining module is used for analyzing event parameters from the timer overtime information when the timer overtime information is detected to exist at the preset position; and determining the timed task with timed overtime according to the event parameters.
In the implementation of the invention, when the program is operated, whether the program contains a timer function is detected in real time; when detecting that the program contains a timer function, determining the timing type of the current timing task according to the type parameters carried by the timer function; and executing the current timing task by adopting a timing mode corresponding to the timing type according to the timing parameters carried by the timer function. According to the invention, the common android timers are divided into two timing types, namely a short-term timing type and a long-term timing type, developers do not need to master the use methods of various timers, only need to clearly determine whether short-term timing or long-term timing is needed, and set the type parameters and the timing parameters of the timer function, when the program is operated, the timing type is automatically determined according to the type parameters of the timer function, and the timing mode corresponding to the timing type is adopted for timing, so that the use of the timers by the developers is simplified, the complexity of program development is reduced, and the maintenance difficulty of the program is reduced.
The timing device provided by the embodiment of the present invention may be specific hardware on the device, or software or firmware installed on the device, etc. The device provided by the embodiment of the present invention has the same implementation principle and technical effect as the method embodiments, and for the sake of brief description, reference may be made to the corresponding contents in the method embodiments without reference to the device embodiments. It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the foregoing systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments provided by the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus once an item is defined in one figure, it need not be further defined and explained in subsequent figures, and moreover, the terms "first", "second", "third", etc. are used merely to distinguish one description from another and are not to be construed as indicating or implying relative importance.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present invention, which are used for illustrating the technical solutions of the present invention and not for limiting the same, and the protection scope of the present invention is not limited thereto, although the present invention is described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: modifications or changes can be easily made to the technical solutions described in the foregoing embodiments by anyone skilled in the art within the technical scope of the present disclosure, or equivalents of some technical features of the technical solutions can be substituted; such modifications, changes or substitutions do not depart from the spirit and scope of the present invention in its spirit and scope. Are intended to be covered by the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.

Claims (10)

1. A timing method, characterized in that the method comprises:
detecting whether a program contains a timer function in real time when the program is operated;
when detecting that a program contains a timer function, determining a timing type to which a current timing task belongs according to a type parameter carried by the timer function; the timing type includes one of a short-term type and a long-term type; the value of the type parameter carried by the short-term type is a processor type, and the value of the type parameter carried by the long-term type is a global timer type;
and executing the current timing task by adopting a timing mode corresponding to the timing type according to the timing parameters carried by the timer function.
2. The method according to claim 1, wherein when the timing type is a short-term type, the executing the current timing task in a timing manner corresponding to the timing type according to the timing parameter carried by the timer function comprises:
starting a timing thread through a thread pool;
determining the timing parameters carried by the timer function as the parameters of the sleep function in the processor;
and executing the sleep function through the timing thread to time the current timing task.
3. The method according to claim 1, wherein when the timing type is a long-term type, the executing the current timing task in a timing manner corresponding to the timing type according to the timing parameter carried by the timer function comprises:
determining the timing parameters carried by the timer functions as the parameters of the repeated alarm clock functions in the global timer;
and calling the repeated alarm clock function in the global timer to time the current timing task.
4. The method according to claim 1, wherein after the executing the current timing task in the timing manner corresponding to the timing type according to the timing parameter carried by the timer function, the method further comprises:
when the current timing task is overtime, packaging event parameters carried by the timer function into timer overtime information;
and calling a broadcast sending function to send the timer overtime information to a preset position.
5. The method of claim 4, further comprising:
when the timer overtime information is detected to exist at the preset position, analyzing event parameters from the timer overtime information;
and determining a timing task with overtime timing according to the event parameters.
6. A timing device, the device comprising:
the detection module is used for detecting whether the program contains a timer function in real time when the program is operated;
the determining module is used for determining the timing type of the current timing task according to the type parameters carried by the timer function when the detecting module detects that the program contains the timer function; the timing type includes one of a short-term type and a long-term type; the value of the type parameter carried by the short-term type is a processor type, and the value of the type parameter carried by the long-term type is a global timer type;
and the execution module is used for executing the current timing task by adopting a timing mode corresponding to the timing type according to the timing parameters carried by the timer function.
7. The apparatus of claim 6, wherein when the timing type is a short-term type, the execution module comprises:
the starting unit is used for starting the timing thread through the thread pool;
a first determining unit, configured to determine a timing parameter carried by the timer function as a parameter of a sleep function in a processor;
and the first timing unit is used for executing the sleep function through the timing thread and timing the current timing task.
8. The apparatus of claim 6, wherein when the timing type is a long-term type, the execution module comprises:
a second determining unit, configured to determine a timing parameter carried by the timer function as a parameter of a repeating alarm clock function in a global timer;
and the second timing unit is used for calling the repeated alarm clock function in the global timer to time the current timing task.
9. The apparatus of claim 6, further comprising:
the overtime broadcasting module is used for encapsulating the event parameters carried by the timer function into the overtime information of the timer when the current timing task is overtime; and calling a broadcast sending function to send the timer overtime information to a preset position.
10. The apparatus of claim 9, further comprising:
the task determining module is used for analyzing event parameters from the timer overtime information when the timer overtime information is detected to exist at the preset position; and determining a timing task with overtime timing according to the event parameters.
CN201610999432.7A 2016-11-14 2016-11-14 Timing method and device Active CN106775620B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610999432.7A CN106775620B (en) 2016-11-14 2016-11-14 Timing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610999432.7A CN106775620B (en) 2016-11-14 2016-11-14 Timing method and device

Publications (2)

Publication Number Publication Date
CN106775620A CN106775620A (en) 2017-05-31
CN106775620B true CN106775620B (en) 2020-05-12

Family

ID=58972087

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610999432.7A Active CN106775620B (en) 2016-11-14 2016-11-14 Timing method and device

Country Status (1)

Country Link
CN (1) CN106775620B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109213577B (en) * 2017-06-30 2020-09-08 武汉斗鱼网络科技有限公司 Thread sleep method and device and computer equipment
CN109542598B (en) * 2018-11-08 2021-03-16 泰康保险集团股份有限公司 Timed task management method and device
CN112463125B (en) * 2020-12-09 2023-09-15 百富计算机技术(深圳)有限公司 Timing method and equipment of virtual timer
CN114691343B (en) * 2022-06-02 2022-08-26 深圳依时货拉拉科技有限公司 Polling task execution method and device, computer equipment and readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1928817A (en) * 2006-09-30 2007-03-14 华为技术有限公司 Timer implementation method
CN102129393A (en) * 2011-03-09 2011-07-20 南京恩瑞特实业有限公司 Universal timed task management realization method
CN103106222A (en) * 2011-11-15 2013-05-15 阿里巴巴集团控股有限公司 Processing method and processing device of timer
CN105718257A (en) * 2016-01-13 2016-06-29 上海理工大学 Embedded system-based timer device and timing method

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20110136943A (en) * 2010-06-16 2011-12-22 김휘향 Misson alram service
KR20150057040A (en) * 2013-11-18 2015-05-28 류경빈 User snooze set up alarm application system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1928817A (en) * 2006-09-30 2007-03-14 华为技术有限公司 Timer implementation method
CN102129393A (en) * 2011-03-09 2011-07-20 南京恩瑞特实业有限公司 Universal timed task management realization method
CN103106222A (en) * 2011-11-15 2013-05-15 阿里巴巴集团控股有限公司 Processing method and processing device of timer
CN105718257A (en) * 2016-01-13 2016-06-29 上海理工大学 Embedded system-based timer device and timing method

Also Published As

Publication number Publication date
CN106775620A (en) 2017-05-31

Similar Documents

Publication Publication Date Title
US10061631B2 (en) Detecting unresponsiveness of a process
CN106775620B (en) Timing method and device
CN109739727B (en) Service monitoring method and device in micro-service architecture
CN106681811B (en) Multithreading scheduling method and device based on thread pool
EP2992431B1 (en) Activity based sampling of diagnostics data
US20130080502A1 (en) User interface responsiveness monitor
CN107678782B (en) Process protection method, device, equipment and computer readable storage medium
US9552221B1 (en) Monitoring application execution using probe and profiling modules to collect timing and dependency information
US20040060043A1 (en) Method and apparatus for instrumentation ON/OFF
US8453013B1 (en) System-hang recovery mechanisms for distributed systems
CN110795311B (en) Event playback method and device
CN111625425A (en) Data monitoring method, device and system
US11736776B2 (en) Monitoring operating system methods to facilitate unobtrusive display of media content on portable devices
CN106155746B (en) A kind of installation file processing method and processing device, server
US9727351B2 (en) Method and device for setting status of application
AU2018264137A1 (en) Intelligent code quality monitoring
EP3289455A1 (en) Automatic task tracking
CN110851294B (en) Method and device for remedying program running crash
CN111949511A (en) Application program pause processing method and device, terminal and storage medium
CN114090198A (en) Distributed task scheduling method and device, electronic equipment and storage medium
US10922125B2 (en) Capability liveness of containerized services
CN111949512A (en) Application program jamming detection method and device, terminal and medium
CN109491771B (en) Task processing method based on system performance optimization and related equipment
CN110795239A (en) Application memory leakage detection method and device
CN110489318A (en) Grasping means, device, storage medium and the terminal of systrace information

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant