@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); } } });
connectionHandle.getPool().getFinalizableRefs().put(internalDBConnection, new FinalizableWeakReference<ConnectionHandle>(connectionHandle, connectionHandle.getPool().getFinalizableRefQueue()) { @SuppressWarnings("synthetic-access") public void finalizeReferent() {
pool.getFinalizableRefs().remove(this.connection);
/** * 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(); } }
this.finalizableRefs = pool.getFinalizableRefs(); this.defaultReadOnly = pool.getConfig().getDefaultReadOnly(); this.defaultCatalog = pool.getConfig().getDefaultCatalog();