Example usage for org.apache.commons.pool2.impl GenericObjectPool GenericObjectPool

List of usage examples for org.apache.commons.pool2.impl GenericObjectPool GenericObjectPool

Introduction

In this page you can find the example usage for org.apache.commons.pool2.impl GenericObjectPool GenericObjectPool.

Prototype

public GenericObjectPool(PooledObjectFactory<T> factory) 

Source Link

Document

Create a new GenericObjectPool using defaults from GenericObjectPoolConfig .

Usage

From source file:com.bigdata.hbaseConsultor.Consultor.java

/**
 * @param args the command line arguments
 *//*from  w ww . j  a v  a 2s  .c om*/
public static void main(String[] args) {
    String table = "syslog";
    HBase hb = new HBase(new GenericObjectPool<>(new ConexionFactory()), "syslog");
    try {
        hb.getFilterRows();
    } catch (Exception ex) {
        Logger.getLogger(Consultor.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ReaderUtilClient.java

public static void main(String[] args) {
    ReaderUtil readerUtil = new ReaderUtil(new GenericObjectPool<StringBuffer>(new StringBufferFactory()));
    Reader reader = new StringReader("foo");
    try {/*from   w w  w .  j  a  va2  s .  co m*/
        System.out.println(readerUtil.readToString(reader));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.linuxrouter.netcool.test.DbPoolTest.java

public static void main(String[] args) {
    String host = "192.168.0.201";
    String port = "4100";
    String dbName = "alerts";
    String url = "jdbc:sybase:Tds:" + host + ":" + port + "/" + dbName;
    Driver drv = new com.sybase.jdbc3.jdbc.SybDriver();
    try {//ww  w.  j  a  v  a  2 s  . c o m
        DriverManager.registerDriver(drv);
    } catch (SQLException ex) {
        Logger.getLogger(DbPoolTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, "root", "omni12@#");
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            null);
    ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory);
    poolableConnectionFactory.setPool(connectionPool);
    PoolingDataSource<PoolableConnection> poolingDataSource = new PoolingDataSource<>(connectionPool);
    try {
        Connection con = poolingDataSource.getConnection();
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("select * from alerts.status");
        int x = 0;
        while (rs.next()) {
            //System.out.println(":::" + rs.getString(1));
            x++;
        }
        System.out.println("::::::" + x);
    } catch (SQLException ex) {
        Logger.getLogger(DbPoolTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:co.edu.unbosque.swii.PoolTest.java

@Test(expectedExceptions = org.postgresql.util.PSQLException.class, expectedExceptionsMessageRegExp = ".*too many connections.*")
public void soloDebeCrear5Conexiones() throws Exception {
    FabricaConexiones fc = new FabricaConexiones("aretico.com", 5432, "software_2", "grupo7_5", pwd);
    ObjectPool<Connection> pool = new GenericObjectPool<Connection>(fc);
    for (int i = 0; i < 6; i++) {
        pool.borrowObject();//from w w w. j a v  a 2 s  .c om
    }
}

From source file:com.newlandframework.rpc.serialize.hessian.HessianSerializePool.java

private HessianSerializePool() {
    hessianPool = new GenericObjectPool<HessianSerialize>(new HessianSerializeFactory());
}

From source file:com.newlandframework.rpc.serialize.protostuff.ProtostuffSerializePool.java

private ProtostuffSerializePool() {
    ProtostuffPool = new GenericObjectPool<ProtostuffSerialize>(new ProtostuffSerializeFactory());
}

From source file:com.mirth.connect.donkey.server.data.jdbc.DBCPConnectionPool.java

public DBCPConnectionPool(String url, String username, String password, int maxConnections) {
    this.maxConnections = maxConnections;

    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, username, password);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            null);//from ww w. j  a v  a2  s .  c  om
    poolableConnectionFactory.setDefaultAutoCommit(false);

    GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<PoolableConnection>(
            poolableConnectionFactory);
    connectionPool.setMaxTotal(maxConnections);
    connectionPool.setMaxIdle(maxConnections);

    poolableConnectionFactory.setPool(connectionPool);

    PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<PoolableConnection>(
            connectionPool);
    dataSource.setAccessToUnderlyingConnectionAllowed(true);

    this.dataSource = dataSource;
}

From source file:co.edu.unbosque.swii.PoolTest.java

@Test
public void aprendiendoAControlarLasConexiones() throws Exception {
    FabricaConexiones fc = new FabricaConexiones("aretico.com", 5432, "software_2", "grupo7_5", pwd);
    ObjectPool<Connection> pool = new GenericObjectPool<Connection>(fc);
    for (int i = 0; i < 6; i++) {
        Connection c = pool.borrowObject();
        pool.returnObject(c);//from w  ww.  j  a va2 s  .c  o m
    }
}

From source file:com.newlandframework.rpc.serialize.hessian.HessianSerializePool.java

public HessianSerializePool(final int maxTotal, final int minIdle, final long maxWaitMillis,
        final long minEvictableIdleTimeMillis) {
    hessianPool = new GenericObjectPool<HessianSerialize>(new HessianSerializeFactory());

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();

    config.setMaxTotal(maxTotal);//from   w w  w  .  ja v a 2 s.c  o m
    config.setMinIdle(minIdle);
    config.setMaxWaitMillis(maxWaitMillis);
    config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

    hessianPool.setConfig(config);
}

From source file:hu.neuron.java.jdbc.PoolingDataSourceExample.java

private static PoolingDataSource<PoolableConnection> setupDataSource() {
    ////  w  ww.ja  v a  2  s  .  c o  m
    // First, we'll create a ConnectionFactory that the
    // pool will use to create Connections.
    // We'll use the DriverManagerConnectionFactory,
    // using the connect string passed in the command line
    // arguments.
    //
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(URL, USER, PASS);

    //
    // Next we'll create the PoolableConnectionFactory, which wraps
    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    //
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            null);
    connectionPool = new GenericObjectPool<>(poolableConnectionFactory);

    connectionPool.setMaxTotal(10);
    connectionPool.setMinIdle(20);
    // Set the factory's pool property to the owning pool
    poolableConnectionFactory.setPool(connectionPool);

    //
    // Finally, we create the PoolingDriver itself,
    // passing in the object pool we created.
    //
    PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(connectionPool);

    return dataSource;
}