protected void threadWatch ( final ConnectionHandle c ) { this . threadFinalizableRefs . put ( c , new FinalizableWeakReference < Thread > ( Thread . currentThread ( ) , this . finalizableRefQueue ) { public void finalizeReferent ( ) { try { if ( ! CachedConnectionStrategy . this . pool . poolShuttingDown ) { logger . debug ( "Monitored thread is dead, closing off allocated connection." ) ; } c . internalClose ( ) ; } catch ( SQLException e ) { e . printStackTrace ( ) ; } CachedConnectionStrategy . this . threadFinalizableRefs . remove ( c ) ; } } ) ; }
Keep track of this handle tied to which thread so that if the thread is terminated we can reclaim our connection handle . We also