/** * Registers a shutdown hook for all current and future ConnectionPoolManager * instances to ensure they are released if the JVM exits with any managers * having not been released. * <p><strong>Note:</strong> All individual shutdown hooks will be unregistered * and replaced with this single shutdown hook. */ public static synchronized void registerGlobalShutdownHook() { if (shutdownHookGlobal != null) return; try { shutdownHookGlobal = new Releaser(); Runtime.getRuntime().addShutdownHook(shutdownHookGlobal); logShared.info("Registered global ConnectionPoolManager shutdown-hook"); // Remove instance hooks. for (ConnectionPoolManager cpm : getInstances()) cpm.removeShutdownHook(); } catch (Exception ex) { logShared.warn("Error registering global ConnectionPoolManager shutdown-hook", ex); } }
/** * Registers a shutdown hook for this ConnectionPoolManager instance * to ensure it is released if the JVM exits */ public synchronized void registerShutdownHook() { if (shutdownHook != null) return; try { shutdownHook = new Releaser(this); Runtime.getRuntime().addShutdownHook(shutdownHook); } catch (Exception ex) { log_warn("Error registering shutdown-hook for " + this, ex); } }
private Releaser() { setDaemon(true); }