编程知识 cdmana.com

How netty achieves graceful service shutdown

1 The common function of elegant closing

The most common , For example, in business development , The service is suddenly abnormal , The user request that just came in is still , By closing gracefully , Give them 30s Time goes on , So as not to report mistakes directly .

2 Netty Gracefully close the flowchart

  • modify NioEventLoop Of State Sign a
  • NioEventLoop Judge State Execute exit

Don't pick it up first , Then try to finish the work at hand ( First off boss Houguan worker: Not a 100% guarantee )

Breaking point , It mainly depends on workGroup The closing of the

  • Two times are introduced here

Why two times ?

  • One for elegance
    DEFAULT_SHUTDOWN_QUIET_PERIOD
  • One for control
    DEFAULT_SHUTDOWN_TIMEOUT

Change from start state to stop state

And then in NioEventLoop To judge the closing position of the break point

  • Carry out the unfinished task , No, it's over .

The purpose of closing the service

Close all connections and Selector

  • java.nio.channels.Selector#keys
    • java.nio.channels.spi.AbstractlnterruptibleChannel#close
    • java.nio.channels. SelectionKey#cancel
  • selector.close()

Close all threads : Exit the circulatory body for (;;)

版权声明
本文为[The official account -JavaEdge]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224214813534g.html

Scroll to Top