// sanity
if ( ! Thread.currentThread().getName().startsWith( "http" )
&& ! Thread.currentThread().getName().startsWith( "pool" )
- && ! Thread.currentThread().getName().equals( "main" ) ) {
+ && ! Thread.currentThread().getName().equals( "main" )
+ && ! Thread.currentThread().getName().equals( "startStop" ) ) {
if ( isSupportedExternalThread( Thread.currentThread().getName() ) ) {
log.debug( "Thread identified as being externally created (external library): the DB " +
"connections allocated to non-request processing threads MUST be " +
"manually released after use" );
} else {
log.error( "Thread identified as request processing thread (parent of thread group is not "
- + "SupplementaryThreadHelper.parentThreadGroup), but name doesn't start with http!"
+ + "SupplementaryThreadHelper.parentThreadGroup), but name doesn't start with http or pool or main or startStop!"
+ " (thread name: " + Thread.currentThread().getName() + ")" );
}
}
if ( conn == null ) {
return;
}
+
+ if ( available == null ) {
+ log.error( "No available connections for " + key + " - already closed?" );
+ return;
+ }
// There are subtle interleaved synchronizations happening here.
// Use a traffic load generator with low preOpenedConnections for all modifications in here!
log.debug( "created connection " + conn + ", since busy size is " + busy.size() );
}
} else {
- // TODO: check if the connection is still alive?
+ try {
+ long time_before = System.currentTimeMillis();
+ conn.createStatement().executeQuery( "SELECT 1" );
+ if ( log.isDebugEnabled() ) {
+ log.debug( ( System.currentTimeMillis() - time_before ) + " ms for: SELECT 1 [connection validation]" );
+ }
+ } catch ( SQLException se ) {
+ log.error( "Validation error for idle connection for " + dbkind + ": " + se
+ + ", will replace connection with a newly created one" );
+ try {
+ conn.close();
+ } catch ( SQLException se2 ) {}
+ conn = dbParams.createConnection();
+ if ( conn == null ) {
+ throw new RuntimeException( "Connection creation not available" );
+ }
+ }
if ( log.isTraceEnabled() ) {
if ( busyKey instanceof ThreadGroup ) {
log.trace( dbkind + ": use available connection for "