glassfish
  1. glassfish
  2. GLASSFISH-17260

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

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: v2.1.1
    • Fix Version/s: None
    • Component/s: jdbc
    • Labels:
      None
    • Environment:

      windows 32

      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。

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            sfelts
            Reporter:
            jifeng
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: