您好,登錄后才能下訂單哦!
這篇文章主要講解了“zk服務(wù)器異常報(bào)警和線程服務(wù)關(guān)閉機(jī)制”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“zk服務(wù)器異常報(bào)警和線程服務(wù)關(guān)閉機(jī)制”吧!
主要查看ZooKeeperServer
監(jiān)聽(tīng)與服務(wù)器關(guān)系類(lèi)圖
疑問(wèn):重要線程關(guān)閉或中斷的時(shí)候?這個(gè)監(jiān)聽(tīng)器在什么時(shí)候被調(diào)用呢?
接口 ZooKeeperServerListener
void notifyStopping(String threadName, int errorCode);
實(shí)現(xiàn)類(lèi)ZooKeeperServerListenerImpl
@Override
public void notifyStopping(String threadName, int exitCode) {
LOG.info("Thread {} exits, error code {}", threadName, exitCode);
zkServer.setState(State.ERROR);
}
報(bào)警危機(jī)線程ZooKeeperCriticalThread繼承了ZooKeeperThread
重新實(shí)現(xiàn)了父類(lèi)方法,調(diào)用監(jiān)聽(tīng)通知方法,改變服務(wù)狀態(tài)
@Override protected void handleException(String threadName, Throwable e) { LOG.error("Severe unrecoverable error, from thread : {}", threadName, e); listener.notifyStopping(threadName, ExitCode.UNEXPECTED_ERROR.getValue()); ServerMetrics.getMetrics().UNRECOVERABLE_ERROR_COUNT.add(1); }
處理器實(shí)現(xiàn)ZooKeeperServerShutdownHandler
private final CountDownLatch shutdownLatch;
void handle(State state) { if (state == State.ERROR || state == State.SHUTDOWN) { shutdownLatch.countDown(); } }
把shutdownLatch減去1
1異常處理流程
SessionTrackerImpl 運(yùn)行中如果遇到異常
catch (InterruptedException e) {
handleException(this.getName(), e);
}
2調(diào)用繼承類(lèi)的方法handleException
3方法中調(diào)用監(jiān)聽(tīng)類(lèi)ZooKeeperServerListener的.notifyStopping通知方法
4通知接口實(shí)現(xiàn)ZooKeeperServerListenerImpl具體指定處理
設(shè)置服務(wù)狀態(tài)為zkServer.setState(State.ERROR);
5調(diào)用zkServer.setState方法,內(nèi)部調(diào)用ZooKeeperServerShutdownHandler處理器方法
6處理器中調(diào)用handle方法
void handle(State state) {
if (state == State.ERROR || state == State.SHUTDOWN) {
shutdownLatch.countDown();
}
}
6 計(jì)數(shù)器關(guān)閉ZooKeeperServerMain中注冊(cè)了關(guān)閉服務(wù)處理器
// Registers shutdown handler which will be used to know the
// server error or shutdown state changes.
final CountDownLatch shutdownLatch = new CountDownLatch(1);
zkServer.registerServerShutdownHandler(new ZooKeeperServerShutdownHandler(shutdownLatch));
...
containerManager.start();
// Watch status of ZooKeeper server. It will do a graceful shutdown
// if the server is not running or hits an internal error.
shutdownLatch.await();
感謝各位的閱讀,以上就是“zk服務(wù)器異常報(bào)警和線程服務(wù)關(guān)閉機(jī)制”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)zk服務(wù)器異常報(bào)警和線程服務(wù)關(guān)閉機(jī)制這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。