Background technology
With computer networking technology flourish, large-scale application system on stream,
Inevitably need to complete some functions using asynchronous system.And the concrete reality of asynchronous system
It is exactly now task system, the asynchronous operation for carrying out will be wished, be packaged into task record, adopts
Timed thread performs task record.Repeatedly retrying for task can so be realized, it is ensured that task
Successful execution.
At present, most tasks carrying is all task scheduling system periodically to tasks carrying system
System is scheduled, i.e., trigger task execution system by the interface of calling task execution system
Corresponding task executing method.Task executing method inquires about pending task list, and traversal should
Task list, performs each task record, if run succeeded, by the task status modification
To complete;If execution is unsuccessful, next time performs again.
Fig. 1 is the process schematic that existing task scheduling system scheduler task is performed, such as Fig. 1
Shown, task scheduling system obtains the task configuration note in tasks carrying allocation list from data base
Record, according to the concurrent thread number that task configures each type tasks in record respective amount is generated
Thread, each thread according to task configure record in tasks carrying mark (holds including task
Line interface is identified) interface of calling task execution system, task is held in triggering task execution system
The execution of row method.As shown in FIG., the configuration in task allocation list, it is assumed that certain species
The concurrent thread number of the task of type is 3, then assign the task to tasks carrying in task scheduling system
3 threads can be generated during system, 3 threads have 2 when interface interchange is carried out
Individual and the above thread can call same task execution system, task execution system 1 such as in figure
(2 threads call task execution system 1 simultaneously).If task execution system 1 is being performed
During task, the burst for not carrying out task is processed (i.e. according to different threads process different task
Mode), the task of will result in is repeatedly executed twice, so as to cause the redundancy (note 1) of data.
Fig. 2 is existing task scheduling implementation procedure flow chart, task scheduling system meeting in the figure
Tasks carrying allocation list in inquiry data base, obtains the configuration record of tasks carrying, and is directed to
Each tasks carrying configuration record opens father's thread timing and detects the tasks carrying configuration record
Whether satisfaction performs the time, if be unsatisfactory for, continues timing and detects;If it is satisfied, then obtaining
Concurrent thread number in task configuration record, meanwhile, generate the corresponding task of concurrent thread number
Sub-line journey is called, each sub-line journey configures the tasks carrying interface in record according to tasks carrying
Configuration, enters calling for line interface.But, during calling interface, task execution system
After receiving interface interchange, when triggering performs task executing method, only in the batch task
Process just can return response results after being fully completed to interface interchange thread, and this period is one
Individual uncontrollable time.If we specify tasks carrying behaviour in tasks carrying configuration record
Work was called once per 10 seconds, it is, the tasks carrying cycle is 10 seconds, then if
Inner joint call result is also not received by within 10 seconds, and task scheduling system will carry out second
Call, now, it may appear that first time interface interchange and second interface interchange are in tasks carrying system
System end performs simultaneously, cause with a batch of task be performed 2 times and more than, that is, repeat
Repeatedly, so as to a plurality of reproducible results record (note 2) can be produced.
From the foregoing, prior art is held in task scheduling system call task execution system
There is a problem of that task record is repeatedly executed in row task process, i.e. problem in note 1, note 2.
Meanwhile, task duplication performs the problem that can cause Data duplication, and also task execution system can be made
Into unnecessary pressure.
The content of the invention
In view of this, the present invention provides a kind of task executing method for preventing from repeating and device,
The execution of the method control task combined using monitoring threshold values and counter variable, can be effective
Avoid repeating for task.
For achieving the above object, according to an aspect of the invention, there is provided one kind prevents from repeating
The task executing method of execution.
A kind of task executing method for preventing from repeating, including:Receive task scheduling system
Interface interchange request after, obtain the monitoring threshold values of task executing method, and judge the monitoring
The state of threshold values, the monitoring threshold is used for determining whether to perform the task executing method
And including opening and closed mode;When the monitoring threshold values is in opening, connect
By the interface interchange of the task scheduling system, and the monitoring threshold values is set to off into closed state;
Pending task record list is obtained, and the task record number of the task record list is assigned
It is worth to counter variable;The task record in the task record list is performed, and is appointed at one
After business record has been performed, the value of the counter variable is successively decreased into 1;When the counter variable
Be worth for 0 when, by it is described monitoring threshold values be set on state to perform interface interchange next time.
Alternatively, also include:When the monitoring threshold values is closed, refusal is described to appoint
The interface interchange of business scheduling system, the task scheduling system will re-start interface interchange.
Alternatively, the step of re-starting interface interchange includes:Timing detects the monitoring threshold values
State, when it is described monitoring threshold values be in opening after, re-request calls the interface;
Or re-request calls the interface of other task execution systems.
Alternatively, the step of performing the task record in the task record list, including:Will
The task record list is divided into multiple lists, and creates the multiple threads for corresponding to number, makes
Each thread performs in the plurality of list.
According to a further aspect in the invention, there is provided a kind of to prevent the tasks carrying for repeating from filling
Put.
A kind of task execution device for preventing from repeating, including:Monitoring threshold values determination module,
After interface interchange for receiving task scheduling system is asked, the prison of task executing method is obtained
Depending on threshold values, and judge the state for monitoring threshold values, the monitoring threshold is used for judging whether to permit
Perhaps the task executing method is performed and including opening and closed mode;Monitoring threshold values is closed
Mold closing block, for when the monitoring threshold values is in opening, receiving the task scheduling system
The interface interchange of system, and the monitoring threshold values is set to off into closed state;Counting variable assignment mould
Block, for obtaining pending task record list, and by the task of the task record list
Record number is assigned to counter variable;Counting variable successively decreases module, for performing the task note
Task record in record list, and after a task record has been performed, the enumerator is become
The value of amount successively decreases 1;Monitoring threshold values opening module, for when the value of the counter variable be 0 when,
The monitoring threshold values is set on into state to perform interface interchange next time.
Technology according to the present invention scheme, the side combined using monitoring threshold values, counter variable
Formula carrys out control task and performs the opening and closing that method is performed, and can be effectively prevented tasks carrying
System is performed a plurality of times to task, so as to avoid the repeat number caused after task is performed a plurality of times
According to, and the pressure for reducing task execution system during tasks carrying.
Specific embodiment
The one exemplary embodiment of the present invention is explained below in conjunction with accompanying drawing, including this
They should be thought only exemplary by the various details of bright embodiment to help understanding.
Therefore, it will be appreciated by those of ordinary skill in the art that, the embodiments described herein can be done
Go out various changes and modifications, without departing from scope and spirit of the present invention.Equally, in order to clear
Chu eliminates the description to known function and structure with concisely in description below.
Technical scheme prevents the weight of task by introducing monitoring threshold values and enumerator
It is multiple to perform.It is closed mode that monitoring threshold values is arranged before execution task is started, and forbids others to connect
Mouthful call in the execution flow process of task execution system, and by the number of the pending task of the batch
Amount is set to the variable of enumerator, a task has often been performed, just by the variate-value in enumerator
Subtract 1, until all tasks carryings of this batch are complete, i.e., the variate-value in enumerator is 0, now
Again monitoring threshold values is set on into state, interface interchange next time can be performed.
Fig. 3 is tasks carrying principle schematic according to embodiments of the present invention.As shown in figure 3,
Mainly include task scheduling system and task execution system two parts in embodiments of the invention.Its
In, task scheduling system is a public service system, and developer can be in the system configuration
The parameters such as interface accessing information, the execution time of task execution system, the scheduling system can be according to
The configuration execution time carrys out the interface method of calling task system, triggers appointing in task execution system
Business execution method.
Task execution system is a concrete system for performing task, there is provided an interface supplies task
Scheduling system is called, to trigger the realization (triggering the execution of task executing method) of interface.
In figure, task execution system includes monitoring that threshold values, counter variable and method perform 3 parts.
Wherein, monitor that threshold values is used for judging whether task executing method allows to perform (i.e.:Interface interchange
It is whether successful), monitoring threshold values only has two states, including opening and closing, during unlatching, appoints
Business execution method can be performed;During closing, task executing method can not be performed.It is logical every time
Interface interchange is crossed into after task executing method, first monitoring threshold values can be arranged to into closed mode,
No longer receive other interface interchanges.The bar number of the pending task record of this batch is inquired afterwards,
And the task record bar number is set to counter variable, during task record is performed,
Often perform a task record and just the value of the counter variable is subtracted 1.So, when this batch is all
After the completion of task record is performed, the value of counter variable is changed into 0, is now arranged to monitoring threshold values
Opening, it is allowed to the carrying out of task scheduling system interface interchange next time.Specific task is held
Row process is as shown in Figure 4.
Fig. 4 is a kind of task executing method for preventing from repeating according to embodiments of the present invention
Key step schematic diagram.As shown in figure 4, the tasks carrying side for preventing from repeating of the present invention
Method mainly includes steps S41 to step S45.
Step S41:After receiving the interface interchange request of task scheduling system, acquisition task is held
The monitoring threshold values of row method, and judge the state of the monitoring threshold values.Wherein, the monitoring threshold
Value is used for determining whether to perform the task executing method and including opening and closing
State.Task scheduling system reads after a collection of task, according to task with confidence from data base
Breath, each task is assigned the task to by way of carrying out interface interchange to task execution system and is held
Row system.Task execution system is received after the interface interchange request of task scheduling system, first
Needs judge whether to receive this time to call.Acquisition task is taken in technical scheme
The monitoring threshold values of the task executing method in execution system, and judge the method for its state carrying out
It is determined that.
Step S42:When the monitoring threshold values is in opening, receive the task scheduling
The interface interchange of system, and the monitoring threshold values is set to off into closed state.At monitoring threshold values
When opening, the interface interchange that can receive this task scheduling system is illustrated, then can be connect
The task record list that task scheduling system sends is received, and monitoring threshold values is set to off into closed state,
Other interface interchanges can not be temporarily received to show.That is, at the monitoring threshold values
When closed mode, refuse the interface interchange of the task scheduling system, now, task scheduling
System will re-start interface interchange.Can be with when task scheduling system re-starts interface interchange
Including two kinds of situations:Timing detects the state of the monitoring threshold values of the task execution system, works as monitoring
After opening, re-request calls the interface to threshold values;Or re-request calls other
The interface of task execution system.
Step S43:Obtain pending task record list, and by the task record list
Task record bar number be assigned to counter variable.Herein, the bar number of task record is assigned to
Counter variable, by enumerator can easily monitor task record implementation status, so as to can
Avoid, because being provided with duty cycle, re-reading task after expiring and causing the repetition of task to be held
OK.
Step S44:The task record in the task record list is performed, and in a task
After record has been performed, the value of the counter variable is successively decreased into 1.Performing the task record row
During task record in table, the task record list can be divided into multiple lists, and be created
Multiple threads of correspondence number are built, makes each thread perform one in the plurality of list.By
In multithreading perform task can faster, it is more efficient, therefore, can be according to being matched somebody with somebody in task allocation list
The concurrent thread number of putting for task, or according to the concrete condition of each batch task, by task
Record list is divided into many parts, is performed by multiple thread parallels.Task record after each segmentation
There can be a plurality of task record in list, it is also possible to only by 1 task record.In the task of carrying out
When record list is split, segmentation rule is set also dependent on concrete condition, for example can be successively
Every task of distribution, also can unbalanced distribution task dispatching.
As shown in figure 5, being that multithreading execution task distribution condition according to embodiments of the present invention is shown
It is intended to.For example the task record list of the batch task can be divided into 4 parts, correspondingly generate 4
Individual thread, each thread distribution is a, and parallel processing task record is highly efficient.And ought have
After task record has been performed, the value of counter variable will subtract 1.
Step S45:When the value of the counter variable is 0, the monitoring threshold values is arranged
It is opening to perform interface interchange next time.When the value of counter variable is kept to 0,
It is believed that the task executed of the batch is finished, interface interchange next time can be received, under process
A collection of task, therefore monitoring threshold values is set on into state, to receive task scheduling system
Interface interchange is asked.
According to above-mentioned step S41 to S45, you can controlled by monitoring threshold values and enumerator
The execution of task, to avoid repeating for task.Can be seen that according to above-mentioned step and appoint
The tasks carrying of business system can be divided into 2 processes, and one is that task record receives process;Two
It is task record processing procedure.The flow chart of the two processes is respectively as shown in Figure 6 and Figure 7.
As shown in fig. 6, being that task record according to embodiments of the present invention receives process flow diagram flow chart.
After tasks carrying starts, when the interface interchange for receiving task scheduling system asks (step S61)
Afterwards, the monitoring threshold values (step S62) of the task executing method of the task execution system is obtained first,
The state (step S63) of monitoring threshold values is judged afterwards.When it is closed mode to monitor threshold values, will
Directly return interface interchange (step S68).When it is opening to monitor threshold values, monitoring is set
Threshold values is closed mode (step S64), and obtains pending task record list (step S65),
Then task record bar number is assigned to into counter variable (step S66);Remembered according to task afterwards
The situation of record list, can also distribute task record list (step S67), and task record is arranged
Table is divided into multiple lists, and generates the thread of corresponding number to realize that it is described that each thread is performed
One in multiple lists.
As shown in fig. 7, being task record process flowchart according to embodiments of the present invention.
With reference to Fig. 6, task record processing procedure is each thread process task record list in Fig. 7
Process.After thread is performed to be started, task record list (step S71) will be first traveled through, be sentenced
It is disconnected to whether there is unenforced task record (step S72), if it does not, illustrating the batch
Task record be processed and finish, then it is opening (step S76) to arrange monitoring threshold values,
Task executing method is performed and terminated;If it is present the task record (step S73) is performed,
And after the task record has been performed, counter variable value is subtracted 1 (step S74), and judge
Whether the value of counter variable is equal to 0 (step S75), if being not equal to 0, execution step
S71, travels through task record list again;If equal to 0, illustrate the task record of the batch all
It is processed to finish, then monitoring threshold values is set for opening (step S76), task executing method
Execution terminates.
Fig. 8 is a kind of task execution device for preventing from repeating according to embodiments of the present invention
Main modular schematic diagram.As shown in figure 8, a kind of of the present invention prevents repeating for task from holding
It is main including monitoring threshold values determination module 81, monitoring threshold values closedown module 82, meter that luggage puts 80
Number variable assignment module 83, counting variable is successively decreased module 84 and monitoring threshold values opening module 85.
Monitoring threshold values determination module 81 is used to receive the interface interchange request of task scheduling system
Afterwards, the monitoring threshold values of task executing method is obtained, and judges the state of the monitoring threshold values, institute
Monitoring threshold is stated for determining whether to perform the task executing method and including unlatching shape
State and closed mode;Monitoring threshold values closedown module 82 is used to open shape when the monitoring threshold values is in
During state, receive the interface interchange of the task scheduling system, and the monitoring threshold values is set to
Closed mode;Counting variable assignment module 83 is used to obtain pending task record list, and
The task record number of the task record list is assigned to into counter variable;Counting variable successively decreases
Module 84 is used to perform the task record in the task record list, and in a task record
After having performed, the value of the counter variable is successively decreased into 1;Monitoring threshold values opening module 85 is used for
When the counter variable value be 0 when, by it is described monitoring threshold values be set on state so as to
Perform interface interchange next time.
Technical scheme according to embodiments of the present invention, is mutually tied using monitoring threshold values, counter variable
The mode of conjunction carrys out control task and performs the opening and closing that method is performed, and can be effectively prevented and appoint
Business execution system is performed a plurality of times to task, so as to avoid what is caused after task is performed a plurality of times
Duplicate data, and reduce the pressure of task execution system during tasks carrying.
Above-mentioned specific embodiment, does not constitute limiting the scope of the invention.This area
Technical staff is it is to be understood that depending on design requirement and other factors, can occur various
The modification of various kinds, combination, sub-portfolio and replacement.It is any within the spirit and principles in the present invention
Modification, equivalent and improvement for being made etc., should be included within the scope of the present invention.