@Override public void deconstruct(Object component) { if (component instanceof AbstractComponent) { AbstractComponent abstractComponent = (AbstractComponent) component; if (abstractComponent.isDeconstructable()) ((AbstractComponent) component).deconstruct(); } }}; }
@Override public void deconstruct() { shutdown(); super.deconstruct(); }
@Override public void run() { log.info("Starting deconstruction of component " + component); try { component.deconstruct(); log.info("Finished deconstructing of component " + component); } catch (Exception | NoClassDefFoundError e) { // May get class not found due to it being already unloaded log.log(WARNING, "Exception thrown when deconstructing component " + component, e); } catch (Error e) { try { Duration shutdownDelay = getRandomizedShutdownDelay(); log.log(LogLevel.FATAL, "Error when deconstructing component " + component + ". Will sleep for " + shutdownDelay.getSeconds() + " seconds then restart", e); Thread.sleep(shutdownDelay.toMillis()); } catch (InterruptedException exception) { log.log(WARNING, "Randomized wait before dying disrupted. Dying now."); } com.yahoo.protect.Process.logAndDie("Shutting down due to error when deconstructing component " + component); } catch (Throwable e) { log.log(WARNING, "Non-error not exception throwable thrown when deconstructing component " + component, e); } } }
@Override public void deconstruct() { logger.log(Level.INFO, "Deconstructing FS4ResourcePool with id '" + instanceId + "'."); super.deconstruct(); listeners.close(); timer.cancel(); for (Backend backend : connectionPoolMap.values()) { backend.shutdown(); backend.close(); } executor.shutdown(); scheduledExecutor.shutdown(); try { executor.awaitTermination(10, TimeUnit.SECONDS); scheduledExecutor.awaitTermination(10, TimeUnit.SECONDS); } catch (InterruptedException e) { logger.warning("Executors failed terminating within timeout of 10 seconds : " + e); } }
/** * Shutdown the thread pool, give a grace period of 1 second before forcibly * shutting down all worker threads. */ @Override public void deconstruct() { boolean terminated; super.deconstruct(); threadpool.shutdown(); try { terminated = threadpool.awaitTermination(1, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } if (!terminated) { threadpool.shutdownNow(); } }