public static synchronized void addShutdownHook(String hookName, Runnable hook) { Thread t = new Thread(hook, hookName); addShutdownHook(t); }
/** * Certain situations represent "Die" conditions for the server, and if so, * the reason is logged and the current JVM is killed. * * @param t * The Throwable to log before killing the current JVM */ protected void killCurrentJVM(Throwable t) { t.printStackTrace(System.err); logger.error("JVM state determined to be unstable. Exiting forcefully due to:", t); ShutdownHookUtils.removeAllShutdownHooks(); System.exit(100); } }
closeOnExit.reset(); try { ShutdownHookUtils.removeShutdownHook(closeOnExit); } catch (IllegalStateException e) {
public static synchronized void addShutdownHook(Object object, Runnable hook) { String hookName = object.getClass().getSimpleName() + "-ShutdownHook-" + hooks.size(); addShutdownHook(hookName, hook); }
private void addShutdownHook() { ShutdownHookUtils.addShutdownHook(this, () -> { close(); }); }
private void addShutdownHook() { if (dbSettings.dbCloseOnExit) { try { closeOnExit = new DatabaseCloser(this, 0, true); ShutdownHookUtils.addShutdownHook(closeOnExit); } catch (IllegalStateException | SecurityException e) { // shutdown in progress - just don't register the handler // (maybe an application wants to write something into a // database at shutdown time) } } }
private synchronized void openNioEventLoopAdapter(Map<String, String> config) { if (nioEventLoopAdapter == null) { try { nioEventLoopAdapter = new NioEventLoopAdapter(config, "client_nio_event_loop_interval", 1000); // 默认1秒 ConcurrentUtils.submitTask("Client-Nio-Event-Loop", () -> { NioNetClient.this.run(); }); ShutdownHookUtils.addShutdownHook(this, () -> { close(); }); } catch (IOException e) { throw new RuntimeException("Failed to open NioEventLoopAdapter", e); } } }
private static void startProtocolServer(final ProtocolServer server) throws Exception { server.setServerEncryptionOptions(config.server_encryption_options); server.start(); final String name = server.getName(); ShutdownHookUtils.addShutdownHook(server, () -> { server.stop(); logger.info(name + " stopped"); }); logger.info(name + " started, host: {}, port: {}", server.getHost(), server.getPort()); } }