A kind of method for supervising of multithreading and device
Technical field
The present invention relates to multi-thread technical field, particularly relate to a kind of method for supervising and device of multithreading.
Background technology
Along with the development of science and technology, get more and more to the functional requirement of system, the complexity of system also doubles thereupon, in order to meet the functional requirements of system, can use multithreading in systems in which.In a complicated multi-threaded system, the work such as inter-thread communication and thread synchronization occupies sizable ratio in the entire system, and thread the extremely trivial or thread of the thread abnormal situation such as to exit often can occur providing in the middle of service.If certain thread is abnormal, namely fail normally to provide service, but other thread still sends message request to this thread, is so just easy to cause task Buffer Overflow to affect business service, and then causes system crash, have impact on the reliability of system widely.
At present, in order to above-mentioned situation occurs the thread in anti-locking system, the general following manner that adopts is monitored the multithreading in system: 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 know the duty of each thread to all monitored threads; After each monitored thread receives roll-call message, respond roll-call response message in real time, to report duty and the out of Memory of this thread; When monitored thread occurs to call the roll response time-out, monitoring thread adds up the expired times of monitored thread, when expired times exceed preset value, is just become by monitored thread and does ossified state, notify the master control thread of system simultaneously.
There is following shortcoming in the above-mentioned method for supervising to thread: owing to not monitoring monitoring thread, can not ensure that monitoring thread normally works, if monitoring thread itself occurs abnormal, abnormal thread cannot be notified system, system just cannot learn the existence of abnormal thread, thus have impact on the reliability of system.
Summary of the invention
Embodiments provide 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.
Embodiments provide a kind of method for supervising of multithreading, comprising:
Overall situation availability manager monitors the running status of at least one local availability manager; Described local availability manager is for monitoring the running status of the service thread to its registration;
Described overall availability manager, when determining local availability manager misoperation, carries out recovery operation to described local availability manager.
Embodiments provide a kind of supervising device of multithreading, comprising:
Overall situation availability manager, for monitoring the running status of at least one local availability manager, when determining local availability manager misoperation, carries out recovery operation to described local availability manager;
At least one local availability manager, for monitoring the running status of the service thread to its registration.
The beneficial effect of the embodiment of the present invention comprises:
The method for supervising of a kind of multithreading that the embodiment of the present invention provides and device, overall situation availability manager monitors the running status of at least one local availability manager, when determining local availability manager misoperation, recovery operation is carried out to local availability manager; Wherein, local availability manager is for monitoring the running status of the service thread to its registration.Due to the Two monitor levels structure adopting overall availability manager to monitor local availability manager, local availability manager monitor service thread, can monitor service thread effectively, when avoiding service thread and monitoring thread all to occur abnormal, system cannot learn the existence of exception service thread, cause system normally cannot provide the situation of normal service, improve the reliability of system.
Accompanying drawing explanation
The process flow diagram of the method for supervising of the multithreading that Fig. 1 provides for the embodiment of the present invention;
Fig. 2 monitors the process flow diagram of the running status of local availability manager for overall availability manager that the embodiment of the present invention provides;
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 present invention;
The schematic diagram of the example that Fig. 4 provides for the embodiment of the present invention;
Fig. 5 provides the structural representation of the supervising device of multithreading for the embodiment of the present invention.
Embodiment
Below in conjunction with accompanying drawing, the method for supervising of the multithreading that the embodiment of the present invention provides and the embodiment of device are described in detail.
The method for supervising of a kind of multithreading that the embodiment of the present invention provides, as shown in Figure 1, idiographic flow comprises the following steps:
S101, overall availability manager monitor the running status of at least one local availability manager; Wherein, this local availability manager is for monitoring the running status of the service thread to its registration;
S102, overall availability manager judge whether local availability manager normally runs; If determine, local availability manager normally runs, and turns to step S101; If determine local availability manager misoperation, perform step S103;
S103, overall availability manager carry out recovery operation to local availability manager; Turn to step S101.
Below the specific implementation of above steps is described in detail.
Particularly, before the step S101 performing the above-mentioned multithreading monitoring that the embodiment of the present invention provides, also need the operation carrying out setting monitor task, such as: initialization overall situation availability manager, create the record cell of the heartbeat message for storing local availability manager, the local availability manager of initialization, creates service thread etc.Service thread before activation, can provide the log-on messages such as policer operation interface to local availability manager, and like this, local availability manager just can monitor the running status of this service thread by usage monitoring operation-interface.
Particularly, for each local availability manager in above-mentioned steps S101, overall availability manager can by the monitoring of following step realization to its running status, 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, timer can be used to carry out timing, such as: can set timed interval is TS1, after TS1 duration, overall availability manager all can carry out the operation of the heartbeat message obtaining local availability manager.
S202, according to the heartbeat message of local availability manager obtained, judge whether the heartbeat of local availability manager beats; If so, step S203 is performed; If not, step S204 is performed;
In the specific implementation, a heart beat status unit can be created to each local availability manager, specifically can comprise in each unit: the title of local availability manager, ID, current heartbeat counter, the information such as last Heart rate meters and anomalous counts device.Local availability manager, after the task of executing monitor service thread, will change the heartbeat message of self, namely triggers current heartbeat rolling counters forward.Like this, current heartbeat counter can being compared whether identical with the numerical value of last Heart rate meters, if identical, then thinking that heartbeat is without beating; If different, then think and have heartbeat to beat.Below just illustrate that the judgement whether heartbeat how realizing local availability manager beats, those skilled in the art also can use other modes to realize, do not limit at this.
S203, determine that local availability manager normally runs, the anomalous counts device of available for this locality manager is reset; Turn to step S201;
S204, think that local availability manager likely extremely exits or endless loop occurs, in order to avoid erroneous judgement, apply for information can be sent to local availability manager;
Particularly, the local availability manager of normal operation is after the apply for information receiving the transmission of overall availability manager, the heartbeat message of self will be changed, like this, after next time, overall availability manager obtained the heartbeat message of this local availability manager, will judge that this local availability manager exists heartbeat, confirm that this local availability manager normally runs, and its anomalous counts device is reset.
S205, the anomalous counts device triggering local availability manager count; In the specific implementation, a numerical value can be increased at the original numerical value of anomalous counts device;
S206, judge that whether the numerical value of anomalous counts device of local availability manager is more than the first setting threshold value, particularly, this first setting threshold value such as can be set to 3 times, does not limit at this; If so, step S207 is performed; If not, step S201 is turned to;
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 local availability manager, can effectively avoid like this due to local availability manager misoperation, generation can not the situation of normal monitor service thread, thus improves the reliability of system.Because recovery operation belongs to prior art, do not describe in detail at this.
Particularly, in the said method that the embodiment of the present invention provides, local availability manager is for monitoring the running status of the service thread to its registration, and the monitoring flow process that its monitoring flow process and overall availability manager perform is similar, as shown in Figure 3, detailed process can be realized by following step:
S301, local availability manager periodically travel through the service thread to its registration, perform following operation for each service thread:
The heartbeat message of S302, acquisition service thread;
Similarly, in the specific implementation, timer can be used to carry out timing, such as: can set timed interval is TS2, after TS2 duration, local availability manager all can carry out the operation of the heartbeat message obtaining service thread.
S303, according to the heartbeat message of service thread obtained, judge whether the heartbeat of this service thread beats; If so, step S304 is performed; If not, step S305 is performed;
Similarly, in the specific implementation, a heart beat status unit can be created to each service thread, specifically can comprise in each unit: the information such as handle of the title of service thread, ID, current heartbeat counter, last Heart rate meters, anomalous counts device and communication information queue.Service thread, after executing service role, will change the heartbeat message of self, namely triggers current heartbeat rolling counters forward.Like this, current heartbeat counter can being compared whether identical with the numerical value of last Heart rate meters, if identical, then thinking that heartbeat is without beating; If different, then think and have heartbeat to beat.Below just illustrate that the judgement whether heartbeat how realizing service thread beats, those skilled in the art also can use other modes to realize, do not limit at this.
S304, determine that service thread is normally run, the anomalous counts device of service thread is reset; Turn to step S301;
S305, think that service thread likely extremely exits or endless loop occurs, in order to avoid erroneous judgement, send apply for information to service thread; This apply for information is used for the heartbeat message changing service thread when service thread is normal;
Particularly, the service thread of normal operation is after the apply for information receiving the transmission of local availability manager, the heartbeat message of self will be changed, like this, after next time, local availability manager obtained the heartbeat message of this service thread, will judge that this service thread exists heartbeat, confirm that this service thread is normally run, and its anomalous counts device is reset.
The anomalous counts device of S306, Trigger services thread counts; In the specific implementation, a numerical value can be increased at the original numerical value of anomalous counts device;
S307, judge that whether the numerical value of anomalous counts device of service thread is more than the second setting threshold value, particularly, this second setting threshold value can be arranged to identical numerical value, such as 3 times with the first setting threshold value, also can be arranged to different numerical value, not limit at this; If so, step S308 is performed; If not, step S301 is turned to;
S308, determine service thread misoperation.
After execution above-mentioned steps S308, local availability manager can also be carried out recovery operation is carried out to the service thread of exception, or the service thread of exception is directly reported system by local availability manager, or the service thread of exception is reported system by overall availability manager, sent the process such as warning information by system, do not limit at this.
Multithreading monitoring flow process of the prior art, monitoring thread does not consider the loading condition of monitored thread, as long as timing one is arrived, just send roll-call message to all monitored threads, like this, the load of monitored thread can be increased, affect the processing power of service thread.
In prior art, service thread had generally both comprised the periodic service thread that timing provides system service, comprised again and was driven and the aperiodicity service thread providing the system service time to expect by external event.Because periodic service thread is when normally running, only perform a service role at each timing cycle, its heartbeat also will be ensued and beat; Only when occurring abnormal, heartbeat just can stop beating, therefore, for periodic service thread without the need to increasing any operation, just can realize whether abnormal accurate judgement, as long as relative to timing in above-mentioned prior art once to for all monitored thread transmission roll-call message, the load of monitored thread can not be increased, also would not affect the processing power of service thread.
Because aperiodicity service thread is in the monitoring period of a local availability manager, its heart beat status is likely beated, and does not also likely change.Only have when 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 can several monitoring periods afterwards, judge whether its heart beat status changes, finally judge that service thread is whether abnormal, as long as relative to timing in above-mentioned prior art once sending roll-call message to all monitored threads, the load of aperiodicity service thread also can be alleviated.
Fig. 4 is the instantiation of the multithreading method for supervising that uses the embodiment of the present invention to provide, as shown in Figure 4, form the first order by local availability manager monitor service thread to monitor, monitor local availability manager by overall availability manager and form second level monitoring, like this, overall situation availability manager and local availability manager can adopt the simple mode of function singleness, structure to realize, and stability is high.And adopt the structure of Two monitor levels, can monitor service thread effectively, when avoiding service thread and monitoring thread all to occur abnormal, system cannot learn the existence of exception service thread, cause system normally cannot provide the situation of normal service, improve the reliability of system.
In addition, the above-mentioned multithreading method for supervising that the embodiment of the present invention provides can be applied to various operating system, such as: Windows, VxWorks and Linux etc.
Based on same inventive concept, the embodiment of the present invention additionally provides a kind of supervising device of multithreading, the principle of dealing with problems due to this device is similar to the method for supervising that aforementioned a kind of multithreading obtains, and therefore the enforcement of this device see the enforcement of method, can repeat part and repeat no more.
The supervising device of a kind of multithreading that the embodiment of the present invention provides, as shown in Figure 5, comprising:
Overall situation availability manager 501, for monitoring the running status of at least one local availability manager 502, when determining local availability manager 502 misoperation, carries out recovery operation to described local availability manager 502;
At least one local availability manager 502, for monitoring the running status of the service thread 503 to its registration.
Further, the overall availability manager 501 in the said apparatus that the embodiment of the present invention provides, specifically for periodically obtaining the heartbeat message of local availability manager 502; According to the heartbeat message of the local availability manager 502 obtained, judge whether the heartbeat of local availability manager 502 beats; If so, determine that this local availability manager 502 normally runs, the anomalous counts device of available for this locality manager 502 is reset; If not, apply for information is sent to local availability manager 502, the anomalous counts device triggering local availability manager 502 counts, and when judging the numerical value of the anomalous counts device 502 of local availability manager after counting more than the first setting threshold value, determine this local availability manager 502 misoperation.
Further, above-mentioned local availability manager 502, also for when receiving the apply for information that overall availability manager 501 sends, 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 present invention provides, specifically for periodically traveling through the service thread 503 to its registration, following operation is performed: according to the heartbeat message of the service thread 503 obtained, judge whether the heartbeat of service thread 503 beats for each service thread 503; If so, determine that this service thread 503 is normally run, the anomalous counts device of service thread 503 is reset; If not, the apply for information being used for changing the heartbeat message of service thread 503 when service thread 503 is normal is sent to this service thread 503, the anomalous counts device of Trigger services thread 503 counts, and when judging the numerical value of the anomalous counts device of service thread 503 after counting more than the second setting threshold value, determine this service thread 503 misoperation.
Further, above-mentioned local availability manager 502, also for when determining service thread 503 misoperation, carries out recovery operation to this service thread 503.
Further, the above-mentioned local availability manager 502 that the embodiment of the present invention provides, specifically for receiving the log-on message that service thread 503 sends in service thread 503 registration process, this log-on message comprises the policer operation interface that service thread 503 provides to local availability manager 502; The running status of usage monitoring operation-interface monitor service thread 503.
Through the above description of the embodiments, those skilled in the art can be well understood to the embodiment of the present invention can by hardware implementing, and the mode that also can add necessary general hardware platform by software realizes.Based on such understanding, the technical scheme of the embodiment of the present 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 and perform method described in each embodiment of the present invention in order to make a computer equipment (can be personal computer, server, or the network equipment etc.).
It will be appreciated by those skilled in the art that accompanying drawing is the schematic diagram of a preferred embodiment, the module in 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 in embodiment can carry out being distributed in the device of embodiment according to embodiment description, also can carry out respective change and be arranged in the one or more devices being different from the present embodiment.The module of above-described embodiment can merge into a module, also can split into multiple submodule further.
The invention described above embodiment sequence number, just to describing, does not represent the quality of embodiment.
The method for supervising of a kind of multithreading that the embodiment of the present invention provides and device, overall situation availability manager monitors the running status of at least one local availability manager, when determining local availability manager misoperation, recovery operation is carried out to local availability manager; Wherein, local availability manager is for monitoring the running status of the service thread to its registration.Due to the Two monitor levels structure adopting overall availability manager to monitor local availability manager, local availability manager monitor service thread, can monitor service thread effectively, when avoiding service thread and monitoring thread all to occur abnormal, system cannot learn the existence of exception service thread, cause system normally cannot provide the situation of normal service, improve the reliability of system.
Obviously, those skilled in the art can carry out various change and modification to the present invention and not depart from the spirit and scope of the present invention.Like this, if these amendments of the present invention and modification belong within the scope of the claims in the present invention and equivalent technologies thereof, then the present invention is also intended to comprise these change and modification.