[GLASSFISH-17260] There is an exclusive multi-threading problem in create jdbc connection pool Created: 31/Aug/11  Updated: 10/Feb/13

Status: Open
Project: glassfish
Component/s: jdbc
Affects Version/s: v2.1.1
Fix Version/s: None

Type: Bug Priority: Major
Reporter: jifeng Assignee: sfelts
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

windows 32


Tags: 3_1_2-exclude

 Description   

package:appserv-core/src/com/sun/enterprise/resource/PoolManagerImpl.java(#createAndInitPool)

This method is not thread-safe,in multithreading environment ,the pool created by thread 1 will be overwritten by thread 2

Precondition:thread 1 and thread 2 use the same poolName
Steps:

  • thread 1 execute getPool(poolName) ( return null)
  • thread 1 create ResourcePool (execute ResourcePoolFactoryImpl.newInstance method)
  • thread 2 execute getPool(poolName) ( return null,because thread 1 is not execute addPool method)
  • thread 1 execute addPool( pool )( add to poolTable )
  • thread 2 execute addPool( pool ) ( add to poolTalbe and overwrite pool )
private ConcurrentHashMap poolTable;

private ResourcePool createAndInitPool(final String poolName, PoolType pt) 
        throws PoolingException 
    {
        ResourcePool pool = getPool( poolName );
	if ( pool == null ) {
            pool = ResourcePoolFactoryImpl.newInstance( poolName, pt );
	    addPool( pool );
	    try {
	        ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
	        if ( runtime.getEnviron() == ConnectorConstants.SERVER ) {
	    	    if (isJdbcPool( poolName ) ) {
	    	        enableJDBCPoolMonitoring(pool, poolName);
	    	    } else {
	    	        enableConnectorConnectionPoolMonitoring(pool, poolName);
	    	    }
	        }
	    } catch( Exception e) {
	        _logger.log(Level.INFO, "poolmon.cannot_reg");
	        _logger.log(Level.FINE, "Exception while registering " +
	    	    "connection pool", e);
	    }
        if (_logger.isLoggable(Level.FINE)){
            _logger.fine( "Created connection  pool  and added it to PoolManager :" + pool);
        }
    }
	return pool;
    }

if overwrite pool,then in enableJDBCPoolMonitoring(pool, poolName) method, Register monitor MBean there will be problems。


Generated at Wed Jul 01 21:50:42 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.