BoneCP implements Serializable, Closeable { public synchronized void shutdown(){ if (!this.poolShuttingDown){ logger.info("Shutting down connection pool..."); this.poolShuttingDown = true; this.shutdownStackTrace = captureStackTrace(SHUTDOWN_LOCATION_TRACE); this.keepAliveScheduler.shutdownNow(); this.maxAliveScheduler.shutdownNow(); this.connectionsScheduler.shutdownNow(); this.asyncExecutor.shutdownNow(); try { this.connectionsScheduler.awaitTermination(5, TimeUnit.SECONDS); this.maxAliveScheduler.awaitTermination(5, TimeUnit.SECONDS); this.keepAliveScheduler.awaitTermination(5, TimeUnit.SECONDS); this.asyncExecutor.awaitTermination(5, TimeUnit.SECONDS); if (this.closeConnectionExecutor != null){ this.closeConnectionExecutor.shutdownNow(); this.closeConnectionExecutor.awaitTermination(5, TimeUnit.SECONDS); } } catch (InterruptedException e) { } this.connectionStrategy.terminateAllConnections(); unregisterDriver(); registerUnregisterJMX(false); if (finalizableRefQueue != null) { finalizableRefQueue.close(); } logger.info("Connection pool has been shutdown."); } } BoneCP(BoneCPConfig config); synchronized void shutdown(); void close(); Connection getConnection(); ListenableFuture<Connection> getAsyncConnection(); boolean isConnectionHandleAlive(ConnectionHandle connection); int getTotalLeased(); int getTotalFree(); int getTotalCreatedConnections(); BoneCPConfig getConfig(); Statistics getStatistics(); AtomicBoolean getDbIsDown(); static final String MBEAN_CONFIG; static final String MBEAN_BONECP; }
@Test public void testShutdownCoverageClose() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InterruptedException { expect(mockConnectionsScheduler.awaitTermination(5, TimeUnit.SECONDS)).andThrow(new InterruptedException()).once(); replay(mockConnectionsScheduler); try{ testClass.shutdown(); } catch(Exception e){ } }
@Test public void testShutdown() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException { testShutdownClose(true); }