Summary of the invention
To defective that exists in the prior art and deficiency, the present invention proposes a kind of method and apparatus, makes when application program for mobile terminal is developed, can manage effectively each task.
To achieve these goals, the present invention proposes a kind of task management method that is used for the portable terminal development system, and said task management method comprises:
Step 1: set up the timer at least two repeating query time intervals with different accuracy and the task pool corresponding respectively with said timer;
Step 2: for each application task, successively the execution time interval of application task and the repeating query of timer are compared task time at interval,, be dispensed to corresponding task pool according to comparative result;
Step 3:, carry out in the said task pool to the task of execution time according to the corresponding task pool of the said timer of repeating query time interval repeating query that timer is set.
Preferred as technique scheme, said step 2 comprises:
Step 21: the execution time interval that obtains program task;
Step 22:, the said execution time is compared with the repeating query time interval at interval from the repeating query time interval of minimum precision; If the said execution time at interval greater than the said repeating query time interval, is then created this program task in the pairing task pool of timer of said repeating query time interval correspondence; If the said execution time, then the high-precision repeating query time interval compared again with slightly at interval less than the said repeating query time interval.
Preferred as technique scheme if the said execution time at interval less than the repeating query time interval of full accuracy, is then changed the repeating query time interval of this full accuracy, makes the said execution time at interval greater than repeating query time interval of the full accuracy after the change.
Preferred as technique scheme; Said step 2 also comprises the step of setting the task pool task attribute; Said task attribute comprises: the call back function that the call back function that the current state of task ID, each task executions number of times, each task executions time interval, each task, the time interval number of each task, each task are carried out and each task discharge, wherein said time interval number are the said execution time to round gained divided by the repeating query time interval of timer at interval.
Preferred as technique scheme, in the said step 3, the every repeating query task pool of timer one time subtracts 1 with the time interval number of the task in the task pool, and when the said time interval, number reduced to 0, then this task was to the execution time.
The present invention also proposes a kind of task management device that is used for the portable terminal development system, and said task management device comprises:
Set up timer and task pool module, be used to set up the timer at least two repeating query time intervals with different accuracy and the task pool corresponding respectively with said timer;
The creation task module; Be used for beginning from the repeating query time interval of minimum precision; The task executions time interval and the repeating query time interval are compared: if this task greater than the said repeating query time interval, is then created in interval of said execution time in the pairing task pool of timer of said repeating query time interval correspondence; If the said execution time, then the high-precision repeating query time interval compared again with slightly at interval less than the said repeating query time interval;
Processing module is used for the corresponding task pool of the said timer of repeating query time interval repeating query according to the timer setting, carries out in the said task pool to the task of execution time.
Preferred as technique scheme; Also comprise change repeating query time interval unit in the said creation task module; Be used for as if the repeating query time interval of said execution time interval less than full accuracy; Then change the repeating query time interval of this full accuracy, make the repeating query time interval of said execution time interval greater than the full accuracy after changing.
Preferred as technique scheme; Said device also comprises sets task pool task attribute module; Wherein, Said task attribute comprises: the call back function that the call back function that the current state of task ID, each task executions number of times, each task executions time interval, each task, the time interval number of each task, each task are carried out and each task discharge, wherein said time interval number are the said execution time to round gained divided by the repeating query time interval of timer at interval.
Preferred as technique scheme; Said setting task pool task attribute module also is used for working as the every repeating query task pool of said processing module timer one time; The time interval number of the task in the task pool is subtracted 1, and when the said time interval, number reduced to 0, said processing module was carried out this task.
Preferred as technique scheme, said processing module and creation task module while independent operating.
Timer and the corresponding task pool thereof of the method that the present invention proposes through setting up different accuracy; Can the execution time of a plurality of tasks according to them be assigned in the appropriate task pool at interval rationally, effectively, and automatically carry out repeating query and the task of execution time can be carried out by timer.So the present invention has realized when application program for mobile terminal is developed, a plurality of development tasks being managed effectively and being called.
Below in conjunction with accompanying drawing, specific embodiments of the invention is done further to specify.For the person of ordinary skill in the field, from detailed description of the invention, above-mentioned and other purposes of the present invention, feature and advantage will be obvious.
Embodiment
As shown in Figure 1, the preferred embodiment of the task management method that the present invention proposes comprises:
Step 1: set up the timer at least two repeating query time intervals with different accuracy and the task pool corresponding respectively with said timer;
Step 2: for each application task, successively the execution time interval of application task and the repeating query of timer are compared task time at interval, according to comparative result, be dispensed to corresponding task pool, concrete grammar is:
Begin from the repeating query time interval of minimum precision; The task executions time interval and the repeating query time interval are compared: if this task greater than the said repeating query time interval, is then created in interval of said execution time in the pairing task pool of timer of said repeating query time interval correspondence; If the said execution time, then the high-precision repeating query time interval compared again with slightly at interval less than the said repeating query time interval;
Step 3:, carry out in the said task pool to the task of execution time according to the corresponding task pool of the said timer of repeating query time interval repeating query that timer is set.
In above-mentioned steps 2,, make the repeating query time interval of said execution time interval greater than the full accuracy after changing if the said execution time at interval less than the repeating query time interval of full accuracy, is then changed the repeating query time interval of this full accuracy.
Wherein, Said method also comprises the step of setting the task pool task attribute; Said task attribute comprises: the call back function that the call back function that the current state of task ID, each task executions number of times, each task executions time interval, each task, the time interval number of each task, each task are carried out and each task discharge, wherein said time interval number are the said execution time to round gained divided by the repeating query time interval of timer at interval.The for example a certain task executions time interval is 60MS, is assigned to the task pool of low precision 50MS, then 60 divided by 50 1.2, said task time, space-number was 2.
In step 3, the every repeating query task pool of timer one time, the time interval number of the task in the task pool will subtract 1, and when the said time interval, number reduced to 0, then this task then was to the execution time.
In the technique scheme, said step 2 and said step 3 while independent operating.
Shown in Figure 2 is according to a specific embodiment of the present invention:
Step S1: apply for two timers and for each timer distributes the task pool of a correspondence, and timer and task pool are carried out initialization.
In two timers, one is high-resolution timer, and another is low precision timer; Carry out initialization then, initialization can comprise: for timer distributes ID, set the time interval of repeating query task pool; Set the task pool storage space, timer starts sign or the like.
For example: the time of setting high-resolution timer repeating query task pool is 10MS (promptly every separated 10MS repeating query is its corresponding task pool once), and the task pool space is 3 tasks, and the timer startup is designated True and starts, and Fasle closes; The time of setting low precision timer repeating query task pool is 50MS, and the task pool space is 3 tasks, and the timer startup is designated True and starts, and Fasle closes.During initialization, acquiescence is made as startup with the sign of timer.
Step S2: the execution time interval that obtains the application task of user's establishment.
For example; The execution time that gets access to application task 1 is spaced apart 70MS; The execution time of application task 2 is spaced apart 60MS, and the execution time of application program 3 is spaced apart 50MS, and the execution time of application program 4 is spaced apart 30MS; The execution time of application program 5 is spaced apart 20MS, and the execution time of application program 6 is spaced apart 10MS.
Step S3: for each application task, successively the execution time interval of application task and the repeating query of timer are compared task time at interval, according to comparative result, be dispensed to corresponding task pool, and the task attribute of task pool is set.
In the time of relatively, the timer of elder generation and low precision compares, if the execution time of certain application task is at interval greater than the repeating query time interval of hanging down precision; Then in this task pool, create this application task; If less than the repeating query time interval of low precision, then continuation and high-precision timer compare, if the execution time of this application task is at interval greater than high-precision repeating query interval task time; Then in this task pool, create this task; If ineligible, then change the high-precision repeating query time interval, make task executions interval greater than the high-precision repeating query time interval.
The task attribute of task pool comprises the current state of task ID (for example task 1, task 2, task 3 etc.), each task executions number of times, each task executions time interval, task, the time interval number of each task, the call back function of each task execution and the call back function that each task discharges etc.Wherein, the time interval number of said task is the repeating query time interval resulting number of each task executions time interval divided by timer, if aliquant, then rounds.For example the time interval of application task 2 is 60MS, is assigned to the task pool of low precision, then 60 divided by 50 1.2, said task time, space-number was 2.
The every repeating query task pool of timer one time, then the time interval number of the task in the task pool subtracts 1 automatically.
After task was carried out once, that carries out the number of times correspondence subtracted 1.When the execution number of times was 0, then expression task was finished, and was-1 if carry out number of times, and then expression does not limit the execution number of times.
Step S4: the startup sign through timer judges whether to have started this timer, if then if execution in step S5 not, then finishes;
Step S5: the task pool that scanning is corresponding, judge whether this task pool is empty, if, then close corresponding timer, and the startup sign of timer is done corresponding modification, if not, execution in step S6 then;
Step S6: whether the execution number of times of judging the application task scan is 0, if then the call back function that discharges of calling task is deleted this task from task pool, the task of back moves forward one, if deny, and execution in step S7 then;
Step S7: whether judge the application task that scans to the execution time, if, then carry out step S8, if not, then continue the task of scanning back; Wherein, judge the application task scan whether to the concrete mode of execution time be: judge task time, whether interval counter was 0;
Step S8: call the corresponding execution call back function of this application task, carry out this task, and in task list, change the corresponding state of this task.
In above-mentioned steps, the user can add new task, and the time interval of new application task execution and the repeating query of timer are compared task time at interval; According to comparative result; Be dispensed to corresponding task pool, the attribute of this task is set, the position of getting the last place side by side.
Timer and the corresponding task pool thereof of the method that the present invention proposes through setting up different accuracy; Can the execution time of a plurality of tasks according to them be assigned in the appropriate task pool at interval rationally, effectively, and automatically carry out repeating query and the task of execution time can be carried out by timer.So the present invention has realized when application program for mobile terminal is developed, a plurality of development tasks being managed effectively and being called.
Corresponding to said method, the present invention also proposes a kind of task management device that is used for the portable terminal development system, and is as shown in Figure 3, and said task management device comprises:
Set up timer and task pool module 31, be used to set up the timer at least two repeating query time intervals with different accuracy and the task pool corresponding respectively with said timer;
Creation task module 32; Be used for beginning from the repeating query time interval of minimum precision; The task executions time interval and the repeating query time interval are compared: if this task greater than the said repeating query time interval, is then created in interval of said execution time in the pairing task pool of timer of said repeating query time interval correspondence; If the said execution time, then the high-precision repeating query time interval compared again with slightly at interval less than the said repeating query time interval;
Processing module 33 is used for the corresponding task pool of the said timer of repeating query time interval repeating query according to the timer setting, carries out in the said task pool to the task of execution time.
Wherein, Also comprise change repeating query time interval unit in the said creation task module; Be used for as if the repeating query time interval of said execution time interval less than full accuracy; Then change the repeating query time interval of this full accuracy, make the repeating query time interval of said execution time interval greater than the full accuracy after changing.
Wherein, Said device can also comprise sets task pool task attribute module; Wherein, Said task attribute comprises: the call back function that the call back function that the current state of task ID, each task executions number of times, each task executions time interval, each task, the time interval number of each task, each task are carried out and each task discharge, wherein said time interval number are the said execution time to round gained divided by the repeating query time interval of timer at interval.
Said setting task pool task attribute module also is used for when the every repeating query task pool of said processing module timer one time, and the time interval number of the task in the task pool is subtracted 1, and when the said time interval, number reduced to 0, said processing module was carried out this task.
Said processing module and creation task module be independent operating simultaneously.
Though; The present invention clearly demonstrates through above embodiment and accompanying drawing thereof; Yet under the situation that does not deviate from spirit of the present invention and essence thereof; The person of ordinary skill in the field works as can make various corresponding variations and correction according to the present invention, but these corresponding variations and correction all should belong to the protection domain of claim of the present invention.