List of usage examples for org.apache.commons.dbcp2 BasicDataSource getMaxTotal
@Override public synchronized int getMaxTotal()
Returns the maximum number of active connections that can be allocated at the same time.
From source file:uk.co.platosys.db.jdbc.ConnectionBroker.java
protected Connection getConnection(String databaseName) throws PlatosysDBException { Connection connect;//from w w w . j a va2s . c o m while (!done) { } //wait for databases to be set up. try { if (dataSources.containsKey(databaseName)) { BasicDataSource dataSource = dataSources.get(databaseName); /* GenericObjectPool<PoolableConnection> pool = pools.get(databaseName);*/ //logger.log("1 "+databaseName+" has "+dataSource.getNumIdle()+" idle plus "+dataSource.getNumActive()+" borrowed"); Connection connection = dataSource.getConnection(); if (connection != null) { //logger.log("2 "+databaseName+" has "+dataSource.getNumIdle()+" idle plus "+dataSource.getNumActive()+" borrowed"); connect = connection; } else { logger.log("dataSource returned a null connection"); return null; } } else { logger.log("not found first time, reloading datasources"); done = false; init(); while (!done) { } // if (dataSources.containsKey(databaseName)) { BasicDataSource dataSource = dataSources.get(databaseName); /*GenericObjectPool<PoolableConnection> pool = pools.get(databaseName);*/ //logger.log("3 "+databaseName+" has "+dataSource.getNumIdle()+" idle plus "+dataSource.getNumActive()+" borrowed"); Connection connection = dataSource.getConnection(); if (connection != null) { // logger.log("4 "+databaseName+" has "+dataSource.getNumIdle()+" idle plus "+dataSource.getNumActive()+" borrowed"); connect = connection; } else { logger.log("dataSource returned a null connection"); return null; } } else { logger.log(2, "CB - Database " + databaseName + " is not known "); throw new PlatosysDBException("CB says Database " + databaseName + " is not known"); } } //refresh connection counters: int idleConnections = 0; int activeConnections = 0; int totalConnections = 0; int maxTotal = 0; for (BasicDataSource bds : dataSet) { idleConnections = idleConnections + bds.getNumIdle(); activeConnections = activeConnections + bds.getNumActive(); maxTotal = maxTotal + bds.getMaxTotal(); } totalConnections = idleConnections + activeConnections; logger.log("CB has " + totalConnections + "; of which " + activeConnections + " active and " + idleConnections + " idle"); return connect; } catch (Exception e) { throw new PlatosysDBException("ConnectionBroker issues", e); } }