Embodiment
The embodiment of the present application provides the resource regulating method and system of a kind of quick release thread.
In order that those skilled in the art more fully understand the technical scheme in the application, it is real below in conjunction with the application
The accompanying drawing in example is applied, the technical scheme in the embodiment of the present application is clearly and completely described, it is clear that described
Embodiment be only some embodiments of the present application, rather than whole embodiment.Based on the embodiment in the application,
The every other embodiment that those of ordinary skill in the art are obtained under the premise of creative work is not made, all should
Belong to the scope of the application protection.
Fig. 1 is the theory diagram that thread resources scheduling is carried out using Puzzle lock, in the prior art, main thread main
It can be appreciated that scheduling thread, is responsible for initializing Puzzle lock, sets number of tasks N and time-out time T, will
Task is issued in thread pool and performed, and calls Puzzle lock to exercise supervision the mission thread in thread pool.Puzzle lock is opened
Checked whether after beginning work and be provided with time-out time, wait is directly entered if time-out time is not provided with, i.e., until institute
There is task to terminate, Puzzle lock zero setting when just exit, if there is provided entering the overtime wait of band, i.e. institute if time-out time
There is task to terminate, Puzzle lock zero setting or stand-by period reach that time-out time then exits wait.In waiting process every time
Mission thread has renewal main thread to be all waken up, and checks whether count value is zeroed:
If a) be not zeroed, and there is time-out time, then calculate whether remaining time-out time is more than zero:
If remaining time-out time is more than zero, it is continuing with remaining time-out time and is waited;
If remaining time-out time is less than zero, directly return, and it is time-out to set result;
If b) be not zeroed, and without time-out time, then continue waiting for;
If c) be zeroed, wait is directly exited, and return.
On the basis of above-mentioned counting lock mechanism, each mission thread, which to be changed, can all recorded Puzzle lock and wake up main line
Journey checks count value, but above-mentioned existing resource dispatching method is only applicable to the multiple tasks of nonexistence results correlation
Execution, it is this when the implementing result of all tasks can all be affected when there is a mission failure in a group task
The higher group task of results relevance will can not discharge other mission threads in a mission failure, cause money
The inessential occupancy in source, Puzzle lock and main thread, which are not all set up, responds rapidly to this mechanism individually failed, so that nothing
The resource of method rapidly shared by release.
Fig. 2 is the schematic flow sheet of the resource regulating method for the quick release thread that the embodiment of the application one is proposed, at this
In embodiment shown in figure, failure information and wakeup schedule thread are sent to Puzzle lock by mission thread so that scheduling
Thread identification mission can fail rapidly, discharge other related mission threads.As shown in Fig. 2 this method includes:
Step 201, scheduling thread distributes multiple tasks to mission thread.
Step 202, Puzzle lock records the task performance of the multiple mission thread.
Step 203, when there is the failure of at least one tasks carrying in the multiple task, corresponding mission thread is to institute
State Puzzle lock and send failure information, and wake up the scheduling thread.
Step 204, scheduling thread obtains the failure information of the Puzzle lock record, and discharges other related timess
Business thread.
Wherein, failure information can include execution status of task and failure cause.Execution status of task is, for example, that task is lost
Lose, failure cause there can be a variety of situations, fed back available for generation system journal or as operation etc..Failure information can
To be marked using special identifier, the application is not limited this.
According to existing scheduling mechanism, scheduling thread is referred to as main thread, is locked in count initialized and divides task
It is assigned to after mission thread, main thread can enter dormancy, and subtract Puzzle lock when mission thread completes task and wake up in the lump
Whether main thread checks count value zero setting.
Embodiments in accordance with the present invention, also failure information can be sent when task thread execution task fails to Puzzle lock
And main thread is waken up, Puzzle lock records the status of fail and failure cause of the mission thread, and main thread is looked into after being waken up
Puzzle lock is seen, situation about being recorded first according to Puzzle lock terminates the execution of other tasks, discharges other related task lines
Journey, so can all mission failures caused by one mission failure of quick response, resource is discharged in time, it is to avoid need not
The resource occupation wanted;In addition, the failure cause that main thread is recorded by Puzzle lock can obtain corresponding feedback, favorably
System is improved according to the reason for mission failure, and then improves the automatization level of system.
According to one embodiment of the application, at least one described tasks carrying unsuccessfully includes at least one described task weight
Try to fail after preset times, or, at least one described task is not carried out success in preset time.For example, can be with
Pre-set each task and retry and no longer retried after how many times, regard as mission failure, one can also be pre-set and appointed
Business time, the time equivalent to default time-out time in Puzzle lock or can be individually for each task and set
The time-out time put, when task execution time exceedes the preset time, task is identified as failure.So in system
During the mechanism that middle presence entirety is retried, the number of retries of overall task can be reduced as far as possible, and the task to a thread is entered
Row repeatedly retry or time-out after just stop the progress of other tasks, effectively reduce resource and repeat occupancy, improve efficiency.
According to one embodiment of the application, the task performance of the multiple mission thread is recorded in the Puzzle lock
Afterwards, methods described also includes:The mission thread sends task status information after completion task to the Puzzle lock;
The Puzzle lock is waited according to task quantity, the task status information and parameter preset.For example in mission thread
Notifications count is locked and wakes up main thread after running succeeded, and often has tasks carrying success count value to subtract one, until count value is
Lock is discharged when zero.Wherein, parameter preset can be a time out time or number of retries etc..
According to one embodiment of the application, when at least one tasks carrying fails, when at least one tasks carrying loses
When losing, the count value of the Puzzle lock is set to default particular value;When the success of all tasks carryings, the Puzzle lock
Count value zero setting.For example, the lock zero setting release of tasks carrying success count, Puzzle lock when having a tasks carrying failure
Same release, but a particular value can be set to, -1 or other particular value is for example set to, so that host process can be known
The Puzzle lock is not normal release or abnormal release.
According to one embodiment of the application, the Puzzle lock includes default structural data mapping, described right
The mission thread answered is sent to the Puzzle lock after failure information, and the Puzzle lock records the failure information in institute
State in the corresponding structural data mapping of mission thread.Structural data mapping e.g. build in advance chart,
Form etc., is corresponded with the mark of each thread, after failure information is received, and Puzzle lock can recognize the transmission mistake
The mark of the mission thread of information is lost, such as the numbering of thread, corresponding knot is found according to the mark of the mission thread
Structure data are mapped, and the failure information received is correspondingly write in the mapping, and the information of record is, for example,:Thread
Numbering, implementing result, implementation progress, failure cause etc., wherein, implementing result needs reason based on failure
Solution, can also be recorded when running succeeded by the mapping, so that implementing result can also be success, this
Invention is no longer explained;Failure cause can be the mistake that mission thread is got during execution task
Code or error message by mistake, such as performed task is the accounts information that A accounts are obtained to server A, is being held
Mission thread can grab the error message of server A return, error message by feasible means during row failure
E.g. server connection time-out, accounts information are not present, ask out of date etc..Mapped and remembered by structural data
The related failure information of each mission thread is recorded, effective error message can be carried out after task terminates and is summarized and anti-
Feedback, is easy to the error correction and improvement of program.
Embodiments in accordance with the present invention, discharge Puzzle lock when can have a mission failure in associated task,
, being capable of one mission failure of quick response and related other of wakeup schedule thread release are not carried out the mission thread terminated
Caused all mission failures, discharge resource in time, it is to avoid unnecessary resource occupation;In addition, main thread passes through meter
The failure cause of number lock record can obtain corresponding feedback, be conducive to changing system according to the reason for mission failure
Enter, and then improve the automatization level of system, improve efficiency.
Based on same inventive concept, the embodiment of the present invention additionally provides a kind of resource scheduling system of quick release thread,
It can be used for realizing the method described by above-described embodiment, as described in the following examples.Due to quick release thread
The principle that resource scheduling system solves problem is similar to the resource regulating method of quick release thread, therefore quick release line
The implementation of the resource scheduling system of journey may refer to the implementation of the resource scheduling system of quick release thread, repeat part not
Repeat again.It is used below, term " unit " or " module " can realize predetermined function software and/or
The combination of hardware.Although the system described by following examples is preferably realized with software, hardware, or soft
The realization of the combination of part and hardware is also that may and be contemplated.
Fig. 3 is the structural representation of the resource scheduling system of the quick release thread of the embodiment of the application one.The present embodiment
System can be realize corresponding function logical block constitute, or operation have corresponding function software electronics set
Standby, the system of the present embodiment can be that operating system can also be computer program etc..
As shown in figure 3, the resource scheduling system of the quick release thread includes:Scheduling thread 100, Puzzle lock 200
With mission thread 300.
Wherein, scheduling thread 100 is used to distribute multiple tasks to mission thread, and obtains the meter after being waken up
The failure information of number lock record, and discharge other related mission threads.
Puzzle lock 200 is used for the task performance for recording the multiple mission thread;
Mission thread 300 is used for the performing scheduling thread distribution of the task, and when the tasks carrying fails, to institute
State Puzzle lock and send failure information, and wake up the scheduling thread.
According to one embodiment of the application, the failure information includes execution status of task and failure cause.
According to one embodiment of the application, at least one described tasks carrying unsuccessfully includes at least one described task weight
Try to fail after preset times, or, at least one described task is not carried out success in preset time.
According to one embodiment of the application, the mission thread is additionally operable to after completion task send to the Puzzle lock
Task status information;The Puzzle lock is additionally operable to be carried out according to task quantity, the task status information and parameter preset
Wait.
According to one embodiment of the application, the Puzzle lock is additionally operable to:, will when at least one tasks carrying fails
Count value is set to default particular value;When the success of all tasks carryings, count value is set to zero.
According to one embodiment of the application, the Puzzle lock also includes logging modle, for by the mission thread
The failure information record is in the mapping of corresponding structural data.
Embodiments in accordance with the present invention, discharge Puzzle lock when can have a mission failure in associated task,
, being capable of one mission failure of quick response and related other of wakeup schedule thread release are not carried out the mission thread terminated
Caused all mission failures, discharge resource in time, it is to avoid unnecessary resource occupation;In addition, main thread passes through meter
The failure cause of number lock record can obtain corresponding feedback, be conducive to changing system according to the reason for mission failure
Enter, and then improve the automatization level of system, improve efficiency.
Specifically, it is that the execution block schematic illustration quickly failed is realized using Puzzle lock as shown in Figure 4:
Step 1, count initialized is locked, and assigns the initial value N of currently one task groups quantity of lock.Wherein, in a tool
In body embodiment, time-out time can also be initialized for Puzzle lock, when overall task, which performs the time, exceedes time-out time,
Puzzle lock zero setting.
Step 2, task is assigned to mission thread and starts to perform by main thread.
Specifically, the mission thread in main thread scheduling thread pond performs corresponding task, Puzzle lock record multiple tasks
The task performance of thread.
Step 3, main thread dormancy, waits Puzzle lock release.
Step 4, when mission thread performs Mission Success, count value is subtracted one by mission thread control Puzzle lock, and is called out
Awake main thread checks counting lock status.
Step 5, when mission thread performs mission failure, mission thread sends failure information to Puzzle lock, will count
Value is set to default particular value, and wakes up main thread.
Specifically, mission thread can be by the preset interface of Puzzle lock to the corresponding structuring of the thread in Puzzle lock
Data mapping is modified or mission thread sends failure information to Puzzle lock, and Puzzle lock is unsuccessfully believed according to this
The mark of breath and mission thread changes corresponding structural data mapping, and changes count value accordingly.
In the particular embodiment, mission failure can be judged by setting time-out time, can also be by performed
Task code return value in itself judge mission failure, still unsuccessfully judge after preset times by that can also be retried
Mission failure.These modes can be realized by the way that task code is configured or changed in itself, no longer be gone to live in the household of one's in-laws on getting married herein
State.
Step 6, counting lock status is checked after main thread is waken up, judges whether Puzzle lock normally discharges.
Wherein, default particular value for example can be negative, decimal or other non-zero positive integer values between N
Deng the present embodiment is illustrated exemplified by -1.
Specifically, normal release can be judged whether by the count value of Puzzle lock, if count value is 1 to N
Between conventional integer value, then judge that Puzzle lock not yet discharges, perform step 3;If count value is 0, judge
Puzzle lock is normal release, and all mission threads are finished and run succeeded, and perform step 7;If count value is
- 1, then judge that Puzzle lock discharges to be abnormal, perform step 8.
Step 7, main thread discharges, and returns to task action result.
Step 8, main thread cancels other related tasks, discharges corresponding mission thread.
Step 9, main thread obtains the information of Puzzle lock record, according to the returning result log of each mission thread.
Wherein step 9 is optional, and the returning result generation daily record of each mission thread can be obtained by step 9, is led to
Later arrangement of the phase to daily record is summarized, and task code or system etc. are improved.
It is the account for obtaining the A accounts being stored on N platform servers with task in the specific embodiment of the application
Exemplified by information, the task can be divided into N number of parallel task and distribute to N number of mission thread, Mei Geren by main thread
The content of business is to obtain the part accounts information of A accounts storage on that server to wherein one server.Meanwhile,
Main thread constructs an initial count value and the tasks carrying situation of each mission thread is carried out for N Puzzle lock counter
Supervision.
Mission thread starts after execution task, and main thread enters dormancy, and Puzzle lock is started counting up, and Puzzle lock can be set
Time-out time, mission failure is judged after more than default time-out time, can also be not provided with time-out time, only be existed
The count value of Puzzle lock just discharges main thread when being preset value.Preset value is, for example, 0 or default particular value.
Whenever there is tasks carrying success, corresponding mission thread can send the information that task is completed to Puzzle lock, and pass through
Notification signal notify wakes up main thread and checks Puzzle lock.Puzzle lock is instructed according to the information by countDown () will
Count value subtracts one, until the success of all tasks carryings, and count value is kept to 0, and task overall execution is finished, and main thread is released
Put, and return to implementing result.
When one of mission thread fails, then the accounts information of A accounts, therefore this can not be completely got
The overall failure of business, it is necessary that remaining unfinished inter-related task thread is not just all continued executing with.Now, failure
Mission thread failure information (such as failure cause, error code) recorded in Puzzle lock by preset interface
In corresponding structural data mapping, and Puzzle lock, main thread root are checked by notification signal notify wake-up main threads
Judge Puzzle lock counting of abnormal according to the count value of Puzzle lock for -1, quick release Puzzle lock stops other related tasks,
Discharge related mission thread.Judge the method for tasks carrying failure with reference to step 5.Further, it is also possible to according to structure
Change the related daily record of the content generation recorded in data mapping and carry out error analysis.
The count value of Puzzle lock is set to default by the present embodiment when can have a mission failure in associated task
Particular value, and wake up other related mission threads of main thread release, can one mission failure of quick response cause
All mission failures, resource is discharged in time, it is to avoid unnecessary resource occupation;In addition, main thread passes through Puzzle lock
The failure cause of record can obtain corresponding feedback, be conducive to being improved system according to the reason for mission failure,
And then the automatization level of system is improved, improve efficiency.
It should be noted that in the description of the present application, term " first ", " second " etc. are only used for describing purpose, and
It is not intended that indicating or implying relative importance.In addition, in the description of the present application, it is unless otherwise indicated, " many
It is individual " it is meant that two or more.
Any process described otherwise above or method description are construed as in flow chart or herein, represent to include
The module of the code of one or more executable instructions for the step of realizing specific logical function or process, fragment
Or part, and the scope of the preferred embodiment of the application includes other realization, wherein can not by shown or
The order of discussion, including according to involved function by it is basic simultaneously in the way of or in the opposite order, carry out perform function,
This should be understood by embodiments herein person of ordinary skill in the field.
It should be appreciated that each several part of the application can be realized with hardware, software, firmware or combinations thereof.Upper
State in embodiment, multiple steps or method can be performed in memory and by suitable instruction execution system with storage
Software or firmware realize.If for example, being realized with hardware, with another embodiment, this can be used
Any one of following technology known to field or their combination are realized:With for realizing logic to data-signal
The discrete logic of the logic gates of function, the application specific integrated circuit with suitable combinational logic gate circuit, can
Program gate array (PGA), field programmable gate array (FPGA) etc..
Those skilled in the art are appreciated that to realize all or part of step that above-described embodiment method is carried
Rapid to can be by program to instruct the hardware of correlation to complete, described program can be stored in a kind of computer-readable and deposit
In storage media, the program upon execution, including one or a combination set of the step of embodiment of the method.
In the description of this specification, reference term " one embodiment ", " some embodiments ", " example ", " specifically show
The description of example " or " some examples " etc. means with reference to the embodiment or the specific features of example description, structure, material
Or feature is contained at least one embodiment of the application or example.In this manual, above-mentioned term is shown
The statement of meaning property is not necessarily referring to identical embodiment or example.Moreover, description specific features, structure, material or
Person's feature can in an appropriate manner be combined in any one or more embodiments or example.
Although embodiments herein has been shown and described above, it is to be understood that above-described embodiment is example
Property, it is impossible to the limitation to the application is interpreted as, one of ordinary skill in the art within the scope of application can be right
Above-described embodiment is changed, changed, replacing and modification.