A kind of method for supervising of multithreading and device
Technical field
The present invention relates to the multithreading field, relate in particular to a kind of method for supervising and device of multithreading.
Background technology
Along with development of science and technology, more and more to the functional requirement of system, the complexity of system is multiplication thereupon also, in order to satisfy the functional demand of system, can use multithreading in system.In the multi-threaded system of a complexity, inter-thread communication and thread synchronization etc. is operated in and occupies sizable ratio in the total system, and thread situations such as the dead trivial or thread of thread withdraws from unusually takes place providing in the middle of the service through regular meeting.If certain thread is unusual, namely fail normally to provide service, but other thread still sends message request to this thread, so just be easy to cause task buffering effect of flood business service, and then cause system crash, influenced the reliability of system widely.
At present, for above-mentioned situation takes place the thread in the anti-locking system, generally adopt following manner that the multithreading in the system is monitored: setting a thread is monitoring thread, and other thread is monitored thread; Monitoring thread arranges a timer, and timed events one arrives, and sends roll-call message to all monitored threads, to know the duty of each thread; After each monitored thread is received roll-call message, respond the roll-call response message in real time, with duty and the out of Memory of reporting this thread; Reply when overtime when monitored thread takes place to call the roll, the add up expired times of monitored thread of monitoring thread when expired times surpass preset value, just become monitored thread the ossified state of doing, simultaneously the master control thread of reporting system.
There is following shortcoming in above-mentioned method for supervising to thread: owing to monitoring thread is not monitored, can not guarantee the monitoring thread operate as normal, if monitoring thread itself occurs unusual, can't notify system with unusual thread, the existence of unusual thread just can't be learnt by system, thereby has influenced the reliability of system.
Summary of the invention
The embodiment of the invention provides a kind of method for supervising and device of multithreading, in order to solve the not high problem of existing multithreading method for supervising reliability.
The embodiment of the invention provides a kind of method for supervising of multithreading, comprising:
Overall situation availability manager is monitored the running status of at least one local availability manager; Described local availability manager is used for monitoring to the running status of the service thread of its registration;
Described overall availability manager carries out recovery operation to described local availability manager when determining local availability manager misoperation.
The embodiment of the invention provides a kind of supervising device of multithreading, comprising:
Overall situation availability manager is used for the running status of at least one local availability manager of monitoring, when determining local availability manager misoperation, described local availability manager is carried out recovery operation;
At least one local availability manager is used for monitoring to the running status of the service thread of its registration.
The beneficial effect of the embodiment of the invention comprises:
The method for supervising of a kind of multithreading that the embodiment of the invention provides and device, overall situation availability manager is monitored the running status of at least one local availability manager, when determining local availability manager misoperation, local availability manager is carried out recovery operation; Wherein, local availability manager is used for monitoring to the running status of the service thread of its registration.Monitor the Two monitor levels structure of local availability manager, local availability manager monitor service thread owing to adopt overall availability manager, monitor service thread effectively, avoid service thread and monitoring thread all to occur when unusual, the existence of unusual service thread can't be learnt by system, cause system that the situation of normal service can't normally be provided, improved the reliability of system.
Description of drawings
The process flow diagram of the method for supervising of the multithreading that Fig. 1 provides for the embodiment of the invention;
The overall availability manager that Fig. 2 provides for the embodiment of the invention is monitored the process flow diagram of the running status of local availability manager;
The process flow diagram of the running status of the local availability manager monitor service thread that Fig. 3 provides for the embodiment of the invention;
The synoptic diagram of the example that Fig. 4 provides for the embodiment of the invention;
Fig. 5 provides the structural representation of the supervising device of multithreading for the embodiment of the invention.
Embodiment
Below in conjunction with accompanying drawing, the method for supervising of the multithreading that the embodiment of the invention is provided and the embodiment of device are described in detail.
The method for supervising of a kind of multithreading that the embodiment of the invention provides, as shown in Figure 1, idiographic flow may further comprise the steps:
S101, overall availability manager are monitored the running status of at least one local availability manager; Wherein, this this locality availability manager is used for monitoring to the running status of the service thread of its registration;
Whether normally S102, overall availability manager judge the operation of local availability manager; If determine that local availability manager normally moves, turn to step S101; If determine local availability manager misoperation, execution in step S103;
S103, overall availability manager carry out recovery operation to local availability manager; Turn to step S101.
Specific implementation to above steps is described in detail below.
Particularly, before the step S101 of the above-mentioned multithreading monitoring that the execution embodiment of the invention provides, also need to set the operation of monitor task, for example: initialization overall situation availability manager, create the record cell of the heartbeat message that is used for the local availability manager of storage, the local availability manager of initialization is created service thread etc.Service thread can provide log-on messages such as policer operation interface to local availability manager before startup, like this, local availability manager just can use the running status of this service thread of policer operation interface monitoring.
Particularly, for each local availability manager, overall availability manager can be by the monitoring of following step realization to its running status in above-mentioned steps S101, and as shown in Figure 2, concrete steps are as follows:
S201, overall availability manager periodically obtain the heartbeat message of local availability manager;
In the specific implementation, can use timer to carry out timing, for example: can set timing and be spaced apart TS1, behind the TS1 duration, overall availability manager all can obtain the operation of the heartbeat message of local availability manager.
The heartbeat message of the local availability manager that S202, basis are obtained judges whether the heartbeat of local availability manager beats; If, execution in step S203; If not, execution in step S204;
In the specific implementation, can create a heartbeat state cell to each local availability manager, specifically can comprise in each unit: information such as the title of local availability manager, ID, current Heart rate meters, last Heart rate meters and anomalous counts device.Local availability manager will change the heartbeat message of self after the task of executing the monitor service thread, namely trigger current Heart rate meters counting.Like this, can more current Heart rate meters whether identical with the numerical value of last Heart rate meters, if identical, think then that heartbeat does not have to beat; If different, then thinking has heartbeat to beat.Below just illustrate the judgement whether heartbeat that how to realize local availability manager beats, those skilled in the art also can use other modes to realize, do not do restriction at this.
S203, determine that local availability manager normally moves, with the anomalous counts device zero clearing of the available manager in this locality; Turn to step S201;
S204, think that local availability manager might withdraw from or take place endless loop unusually, disconnected for fear of erroneous judgement, can send apply for information to local availability manager;
Particularly, move normal local availability manager behind the apply for information that receives overall availability manager transmission, will change the heartbeat message of self, like this, after next time, overall availability manager obtained the heartbeat message of this this locality availability manager, will judge this this locality availability manager and have heartbeat, confirm that this this locality availability manager normally moves, and with its anomalous counts device zero clearing.
The anomalous counts device of S205, the local availability manager of triggering is counted; In the specific implementation, can increase a numerical value in anomalous counts device original numerical value;
Whether S206, the numerical value of judging the anomalous counts device of local availability manager surpass first and set threshold value, and particularly, this first is set threshold value and for example can be set to 3 times, does not do restriction at this; If, execution in step S207; If not, turn to step S201;
S207, determine local availability manager misoperation.
After execution above-mentioned steps S207 determines local availability manager misoperation, overall situation availability manager will carry out recovery operation to this this locality availability manager, can avoid effectively like this because local availability manager misoperation, generation is the situation of monitor service thread normally, thereby has improved the reliability of system.Because recovery operation belongs to prior art, does not do detailed description at this.
Particularly, in the said method that the embodiment of the invention provides, local availability manager is used for monitoring to the running status of the service thread of its registration, and the monitoring flow process that its monitoring flow process and overall availability manager are carried out is similar, as shown in Figure 3, detailed process can realize by following step:
S301, local availability manager periodically travel through the service thread to its registration, carry out following operation at each service thread:
S302, obtain the heartbeat message of service thread;
Similarly, in the specific implementation, can use timer to carry out timing, for example: can set timing and be spaced apart TS2, behind the TS2 duration, local availability manager all can obtain the operation of the heartbeat message of service thread.
The heartbeat message of the service thread that S303, basis are obtained judges whether the heartbeat of this service thread beats; If, execution in step S304; If not, execution in step S305;
Similarly, in the specific implementation, can create a heartbeat state cell to each service thread, specifically can comprise in each unit: the information such as handle of the title of service thread, ID, current Heart rate meters, last Heart rate meters, anomalous counts device and communication information formation.Service thread will change the heartbeat message of self after executing service role, namely trigger current Heart rate meters counting.Like this, can more current Heart rate meters whether identical with the numerical value of last Heart rate meters, if identical, think then that heartbeat does not have to beat; If different, then thinking has heartbeat to beat.Below just illustrate the judgement whether heartbeat that how to realize service thread beats, those skilled in the art also can use other modes to realize, do not do restriction at this.
S304, determine that service thread normally moves, with the anomalous counts device zero clearing of service thread; Turn to step S301;
S305, think that service thread might withdraw from or take place endless loop unusually, disconnected for fear of erroneous judgement, send apply for information to service thread; This apply for information is used for just often changing in service thread the heartbeat message of service thread;
Particularly, move normal service thread behind the apply for information that receives local availability manager transmission, will change the heartbeat message of self, like this, after next time, local availability manager obtained the heartbeat message of this service thread, will judge this service thread and have heartbeat, confirm that this service thread normally moves, and with its anomalous counts device zero clearing.
The anomalous counts device of S306, triggering service thread is counted; In the specific implementation, can increase a numerical value in anomalous counts device original numerical value;
Whether S307, the numerical value of judging the anomalous counts device of service thread surpass second and set threshold value, particularly, this second setting threshold value can be arranged to identical numerical value, for example 3 times with the first setting threshold value, also can be arranged to different numerical value, not do restriction at this; If, execution in step S308; If not, turn to step S301;
S308, determine the service thread misoperation.
After carrying out above-mentioned steps S308, can also carry out local availability manager unusual service thread is carried out recovery operation, perhaps local availability manager directly reports system with unusual service thread, or unusual service thread reported system by overall availability manager, sent processing such as warning information by system, do not do restriction at this.
Multithreading monitoring flow process of the prior art, monitoring thread is not considered the loading condition of monitored thread, as long as regularly one arrive, just send roll-call message to all monitored threads, like this, can increase the load of monitored thread, influence the processing power of service thread.
In the prior art, service thread had generally both comprised the periodic service thread that system service regularly is provided, and comprised again by external event to drive and provide the aperiodicity service thread that the system service time can't expect.Because the periodic service thread is only carried out a service role at each timing cycle when normal operation, its heartbeat also will be ensued and beat; Only taking place under the unusual situation, heartbeat just can stop to beat, therefore, for the periodic service thread, need not to increase any operation, just can realize whether unusual accurate judgement, with respect to needing only timing in the above-mentioned prior art once to for all monitored thread transmission roll-call message, can not increase the load of monitored thread, just can not influence the processing power of service thread yet.
Because the aperiodicity service thread is in the monitoring period of a local availability manager, its heartbeat state might be beated, and also might not change.Have only when the service thread heartbeat is not beated, local availability manager just can send apply for information to change the heartbeat message of service thread to it.Like this, local availability manager is several monitoring periods afterwards, judge whether its heartbeat state changes, finally judge whether service thread is unusual, send roll-call message, the load that also can alleviate the aperiodicity service thread with respect to needing only in the above-mentioned prior art regularly once the monitored thread that arrives to all.
Fig. 4 is an instantiation that uses the multithreading method for supervising that the embodiment of the invention provides, as shown in Figure 4, constitute first order monitoring by local availability manager monitor service thread, monitor local availability manager by overall availability manager and constitute second level monitoring, like this, overall situation availability manager and local availability manager can adopt function singleness, mode simple in structure to realize, stability is high.And adopt the structure of Two monitor levels, monitor service thread effectively avoids service thread and monitoring thread all to occur when unusual, and the existence of unusual service thread can't be learnt by system, cause system that the situation of normal service can't normally be provided, improved the reliability of system.
In addition, the above-mentioned multithreading method for supervising that the embodiment of the invention provides can be applied to various operating systems, for example: Windows, VxWorks and Linux etc.
Based on same inventive concept, the embodiment of the invention also provides a kind of supervising device of multithreading, because the principle of this device solves problem is similar to the method for supervising that aforementioned a kind of multithreading gets, so the enforcement of this device can repeat part and repeat no more referring to the enforcement of method.
The supervising device of a kind of multithreading that the embodiment of the invention provides as shown in Figure 5, comprising:
Overall situation availability manager 501 is used for the running status of at least one local availability manager 502 of monitoring, when determining local availability manager 502 misoperations, described local availability manager 502 is carried out recovery operation;
At least one local availability manager 502 is used for monitoring to the running status of the service thread 503 of its registration.
Further, the overall availability manager 501 in the said apparatus that the embodiment of the invention provides, the concrete heartbeat message that is used for periodically obtaining local availability manager 502; According to the heartbeat message of the local availability manager 502 that obtains, judge whether the heartbeat of local availability manager 502 beats; If determine that this this locality availability manager 502 normally moves, with the anomalous counts device zero clearing of the available manager 502 in this locality; If not, send apply for information to local availability manager 502, triggering the anomalous counts device of local availability manager 502 counts, and the numerical value of judging the anomalous counts device 502 of local availability manager behind counting surpasses first when setting threshold value, determines this this locality availability manager 502 misoperations.
Further, above-mentioned local availability manager 502 also is used for when receiving the apply for information of overall availability manager 501 transmissions, or after the task of each execution monitor service thread 503, changes the heartbeat message of self.
Further, local availability manager 502 in the said apparatus that the embodiment of the invention provides, the concrete service thread 503 that is used for periodically traveling through to its registration, carry out following operation at each service thread 503: according to the heartbeat message of the service thread of obtaining 503, judge whether the heartbeat of service thread 503 beats; If determine that this service thread 503 normally moves, with the anomalous counts device zero clearing of service thread 503; If not, send the apply for information that is used for just often changing in service thread 503 heartbeat message of service thread 503 to this service thread 503, triggering the anomalous counts device of service thread 503 counts, and the numerical value of judging the anomalous counts device of service thread 503 behind counting surpasses second when setting threshold value, determines this service thread 503 misoperations.
Further, above-mentioned local availability manager 502 also is used for when definite service thread 503 misoperations this service thread 503 being carried out recovery operation.
Further, the above-mentioned local availability manager 502 that the embodiment of the invention provides, concrete being used for receives the log-on message that service thread 503 sends in service thread 503 registration processes, and this log-on message comprises the policer operation interface that service thread 503 provides to local availability manager 502; Use the running status of policer operation interface monitoring service thread 503.
Through the above description of the embodiments, those skilled in the art can be well understood to the embodiment of the invention and can realize by hardware, also can realize by the mode that software adds necessary general hardware platform.Based on such understanding, the technical scheme of the embodiment of the invention can embody with the form of software product, it (can be CD-ROM that this software product can be stored in a non-volatile memory medium, USB flash disk, portable hard drive etc.) in, comprise some instructions with so that computer equipment (can be personal computer, server, the perhaps network equipment etc.) carry out the described method of each embodiment of the present invention.
It will be appreciated by those skilled in the art that accompanying drawing is the synoptic diagram of a preferred embodiment, the module in the accompanying drawing or flow process might not be that enforcement the present invention is necessary.
It will be appreciated by those skilled in the art that the module in the device among the embodiment can be distributed in the device of embodiment according to the embodiment description, also can carry out respective change and be arranged in the one or more devices that are different from present embodiment.The module of above-described embodiment can be merged into a module, also can further split into a plurality of submodules.
The invention described above embodiment sequence number does not represent the quality of embodiment just to description.
The method for supervising of a kind of multithreading that the embodiment of the invention provides and device, overall situation availability manager is monitored the running status of at least one local availability manager, when determining local availability manager misoperation, local availability manager is carried out recovery operation; Wherein, local availability manager is used for monitoring to the running status of the service thread of its registration.Monitor the Two monitor levels structure of local availability manager, local availability manager monitor service thread owing to adopt overall availability manager, monitor service thread effectively, avoid service thread and monitoring thread all to occur when unusual, the existence of unusual service thread can't be learnt by system, cause system that the situation of normal service can't normally be provided, improved the reliability of system.
Obviously, those skilled in the art can carry out various changes and modification to the present invention and not break away from the spirit and scope of the present invention.Like this, if of the present invention these are revised and modification belongs within the scope of claim of the present invention and equivalent technologies thereof, then the present invention also is intended to comprise these changes and modification interior.