@SuppressWarnings("synthetic-access") public void finalizeReferent() { try { pool.getFinalizableRefs().remove(internalDBConnection); if (internalDBConnection != null && !internalDBConnection.isClosed()){ // safety! logger.warn("BoneCP detected an unclosed connection "+ConnectionPartition.this.poolName + "and will now attempt to close it for you. " + "You should be closing this connection in your application - enable connectionWatch for additional debugging assistance or set disableConnectionTracking to true to disable this feature entirely."); internalDBConnection.close(); updateCreatedConnections(-1); } } catch (Throwable t) { logger.error("Error while closing off internal db connection", t); } } });
/** * Adds a free connection. * * @param connectionHandle * @throws SQLException on error */ protected void addFreeConnection(ConnectionHandle connectionHandle) throws SQLException{ connectionHandle.setOriginatingPartition(this); // assume success to avoid racing where we insert an item in a queue and having that item immediately // taken and closed off thus decrementing the created connection count. updateCreatedConnections(1); if (!this.disableTracking){ trackConnectionFinalizer(connectionHandle); } // the instant the following line is executed, consumers can start making use of this // connection. if (!this.freeConnections.offer(connectionHandle)){ // we failed. rollback. updateCreatedConnections(-1); // compensate our createdConnection count. if (!this.disableTracking){ this.pool.getFinalizableRefs().remove(connectionHandle.getInternalConnection()); } // terminate the internal handle. connectionHandle.internalClose(); } }
/** Update counters and call hooks. * @param handle connection handle. */ protected void postDestroyConnection(ConnectionHandle handle){ ConnectionPartition partition = handle.getOriginatingPartition(); if (this.finalizableRefQueue != null && handle.getInternalConnection() != null){ //safety this.finalizableRefs.remove(handle.getInternalConnection()); // assert o != null : "Did not manage to remove connection from finalizable ref queue"; } partition.updateCreatedConnections(-1); partition.setUnableToCreateMoreTransactions(false); // we can create new ones now, this is an optimization // "Destroying" for us means: don't put it back in the pool. if (handle.getConnectionHook() != null){ handle.getConnectionHook().onDestroy(handle); } }
/** * Update counters and call hooks. * * @param handle connection handle. */ protected void postDestroyConnection(ConnectionHandle handle) { ConnectionPartition partition = handle.getOriginatingPartition(); if (this.finalizableRefQueue != null && handle.getInternalConnection() != null) { //safety check this.finalizableRefs.remove(handle.getInternalConnection()); // o != null : "Did not manage to remove connection from finalizable ref queue"; } partition.updateCreatedConnections(-1); // we can create new ones now, this is an optimization partition.setUnableToCreateMoreTransactions(false); // "Destroying" for us means: don't put it back in the pool. if (handle.getConnectionHook() != null) { handle.getConnectionHook().onDestroy(handle); } }