Example usage for org.apache.commons.pool2 ObjectPool getNumIdle

List of usage examples for org.apache.commons.pool2 ObjectPool getNumIdle

Introduction

In this page you can find the example usage for org.apache.commons.pool2 ObjectPool getNumIdle.

Prototype

int getNumIdle();

Source Link

Document

Return the number of instances currently idle in this pool.

Usage

From source file:PoolingDriverExample.java

public static void printDriverStats() throws Exception {
    PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
    ObjectPool<? extends Connection> connectionPool = driver.getConnectionPool("example");

    System.out.println("NumActive: " + connectionPool.getNumActive());
    System.out.println("NumIdle: " + connectionPool.getNumIdle());
}

From source file:edumsg.core.PostgresConnection.java

public static void printDriverStats() throws SQLException {
    ObjectPool<? extends Connection> connectionPool = dbDriver.getConnectionPool(DB_NAME);

    System.out.println("DB Active Connections: " + connectionPool.getNumActive());
    System.out.println("DB Idle Connections: " + connectionPool.getNumIdle());
}

From source file:com.yahoo.athenz.common.server.db.AthenzDataSource.java

@Override
synchronized public void clearPoolConnections() {
    ObjectPool<PoolableConnection> pool = getPool();
    try {/* w ww  .  j av a2  s.com*/
        if (LOG.isDebugEnabled()) {
            LOG.debug("Clearing all active/idle (" + pool.getNumActive() + "/" + pool.getNumIdle()
                    + ") connections from the pool");
        }
        pool.clear();
    } catch (Exception ex) {
        LOG.error("Unable to clear connections from the pool: " + ex.getMessage());
    }
}

From source file:org.apache.omid.tso.TestBatchPool.java

@Test(timeOut = 10_000)
public void testBatchPoolInitializesAllBatchObjectsAsIdle() throws Exception {

    final ObjectPool<Batch> batchPool = injector.getInstance(Key.get(new TypeLiteral<ObjectPool<Batch>>() {
    }));//ww w.j  a v  a2s .co m

    assertEquals(batchPool.getNumActive(), 0);
    assertEquals(batchPool.getNumIdle(), CONCURRENT_WRITERS);

    // Now make all of them active and check it below
    for (int i = 0; i < CONCURRENT_WRITERS; i++) {
        batchPool.borrowObject();
    }

    assertEquals(batchPool.getNumActive(), CONCURRENT_WRITERS);
    assertEquals(batchPool.getNumIdle(), 0);

}

From source file:org.cloudgraph.hbase.connect.Connection.java

public Connection(org.apache.hadoop.hbase.client.Connection conection, ObjectPool<Connection> pool,
        Configuration config) {/*www.j ava 2s . co m*/
    super();
    this.con = conection;
    this.pool = pool;
    this.config = config;
    // FIXME: configure table cache
    this.tableCache = CacheBuilder.newBuilder().maximumSize(20).expireAfterAccess(30, TimeUnit.SECONDS)
            .build(new CacheLoader<TableName, Table>() {
                @Override
                public Table load(TableName tableName) throws Exception {
                    if (log.isDebugEnabled())
                        log.debug("loading table " + this + " " + tableName);
                    return con.getTable(tableName);
                }
            });
    if (log.isDebugEnabled())
        log.debug("created " + this + " pool active/idle " + pool.getNumActive() + "/" + pool.getNumIdle());
}

From source file:za.co.wilderness.WildernessPoolingDriver.java

public Connection GetPoolConnection() throws Exception {

    Connection conn = null;/*from   w  ww.  j  a  v a 2 s . c  om*/

    try {
        long startTime = System.currentTimeMillis();
        conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:" + this.EXTERNAL_SERVICE.name());
        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
        ObjectPool<? extends Connection> connectionPool = driver
                .getConnectionPool(this.EXTERNAL_SERVICE.name());
        logger.log(Level.FINE,
                "NumActive: " + connectionPool.getNumActive() + " NumIdle: " + connectionPool.getNumIdle());
        //System.out.println("NumActive: " + connectionPool.getNumActive() + "  NumIdle: " + connectionPool.getNumIdle());
        if (connectionPool.getNumActive() == config.getMaxActive()) {
            config.setMaxActive(config.getMaxActive() + 50);
            try {
                shutdownDriver();
            } catch (Exception e) {
                logger.log(Level.FINE, e.getMessage());
            }
        }

        long endTime = System.currentTimeMillis();
        //System.out.println("Total connection time: " + this.EXTERNAL_SERVICE.name() + " "  + (endTime - startTime) );
        logger.log(Level.FINE, "Open connection for " + this.EXTERNAL_SERVICE.name());
    } catch (SQLException e) {
        //System.out.println("Create connection failed. " + e.getMessage());
        logger.log(Level.SEVERE, "Create connection failed. ", e);
        throw new Exception(e);
    }
    return conn;
}