在我的嵌入式 Jetty 服務(wù)器應(yīng)用程序中,我想在 linux 中的 kill -9 命令殺死它之前關(guān)閉一些流、執(zhí)行器等。我該如何處理?我觀察到,當我的 jetty 服務(wù)器正在運行時,我發(fā)出 kill -9 命令,然后“Killed”字符串打印在日志中,應(yīng)用程序關(guān)閉。我已經(jīng)添加了作為服務(wù)器連接器的LifeCyCleCleListener,以便如果我的服務(wù)器停止,我可以在應(yīng)用程序關(guān)閉之前進行一些清理。但是在殺戮-9的情況下,這不會被調(diào)用 server = new Server(); loadConnectors(server); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); context.setContextPath("/"); server.setHandler(context); ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*"); jerseyServlet.setInitOrder(0); // Tells the Jersey Servlet which REST service/class to load. jerseyServlet.setInitParameter("jersey.config.server.provider.classnames", Resources.class.getCanonicalName()); server.setStopAtShutdown(true); server.start(); logger.debug("Reached this line"); private void loadConnectors(Server server) { //----Http connection setup------------------ ServerConnector connector = new ServerConnector(server); connector.setPort(9025); connector.addLifeCycleListener(new ConnectorListener()); ..... }
在 Linux 中發(fā)出 kill 命令時優(yōu)雅地停止嵌入式碼頭服務(wù)器
慕碼人2483693
2022-09-14 15:36:06