Issue Details (XML | Word | Printable)

Key: GLASSFISH-17260
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: sfelts
Reporter: jifeng
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
glassfish

There is an exclusive multi-threading problem in create jdbc connection pool

Created: 31/Aug/11 02:37 AM   Updated: 10/Feb/13 09:22 PM
Component/s: jdbc
Affects Version/s: v2.1.1
Fix Version/s: None

Time Tracking:
Not Specified

Environment:

windows 32


Tags: 3_1_2-exclude
Participants: jifeng and sfelts


 Description  « Hide

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。



There are no comments yet on this issue.