コード例 #1
0
  public DataSource createMCSConnectionPool(
      MCSConnectionPoolConfiguration configuration, DataSource dataSource)
      throws RepositoryException {

    // Create and configure a Connection pool if there is one.
    if (configuration == null || !configuration.isEnabled()) {
      return dataSource;
    }

    int maxConnections = configuration.getMaxConnections();
    int maxFreeConnections = configuration.getMaxFreeConnections();
    // int optimalFreeConnections;
    int minFreeConnections = configuration.getMinFreeConnections();
    int initialConnections = configuration.getInitialConnections();

    boolean keepConnectionsAlive = configuration.isKeepAliveActive();
    ConnectionPool connectionPool = new ConnectionPool(dataSource);
    if (keepConnectionsAlive) {
      connectionPool.setKeepConnectionsAlive(true);
      int connectionPollInterval = configuration.getKeepAlivePollInterval();
      if (connectionPollInterval > 0) {
        connectionPool.setConnectionPollInterval(connectionPollInterval);
      }
    }

    connectionPool.setMaxConnections(maxConnections);
    connectionPool.setMaxFreeConnections(maxFreeConnections);
    // connectionPool.setOptimalFreeConnections (optimalFreeConnections);
    connectionPool.setMinFreeConnections(minFreeConnections);
    connectionPool.setInitialConnections(initialConnections);

    connectionPool.start();

    return connectionPool;
  }
コード例 #2
0
ファイル: DatabaseManage.java プロジェクト: kinzohuny/test
 private static synchronized Connection getConnect() throws SQLException {
   if (connectionPool == null) {
     connectionPool = new ConnectionPool(driverClassName, url, username, password);
     connectionPool.setTestTable("dual");
     if (initConn > 0 && incConn > 0 && maxConn > 0 && maxConn > initConn) {
       connectionPool.setInitialConnections(initConn);
       connectionPool.setIncrementalConnections(incConn);
       ;
       connectionPool.setMaxConnections(maxConn);
       ;
     }
     try {
       connectionPool.createPool();
     } catch (Exception e) {
       logger.fatal("can not create connection pool!system will exit..", e);
       System.exit(1);
     }
   }
   return connectionPool.getConnection();
 }