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:org.springframework.boot.jta.narayana.DbcpXADataSourceWrapper.java

@Override
public DataSource wrapDataSource(XADataSource xaDataSource) throws Exception {
    DataSourceXAResourceRecoveryHelper helper = new DataSourceXAResourceRecoveryHelper(xaDataSource);
    recoveryManager.registerXAResourceRecoveryHelper(helper);
    System.out.println("register xa recovery helper " + helper);

    DataSourceXAConnectionFactory dataSourceXAConnectionFactory = new DataSourceXAConnectionFactory(tm,
            xaDataSource);//w  ww  . jav  a 2  s .co  m
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
            dataSourceXAConnectionFactory, null);
    GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory);
    poolableConnectionFactory.setPool(connectionPool);
    return new ManagedDataSource<>(connectionPool, dataSourceXAConnectionFactory.getTransactionRegistry());

}

From source file:org.wso2.andes.thrift.MBThriftClient.java

/**
 * Initialize a new thrift client connection pool.
 *//*w w  w  . java  2 s .  c  o  m*/
private void initializeThriftConnectionPool() {

    int thriftClientPoolSize = AndesConfigurationManager
            .readValue(AndesConfiguration.PERFORMANCE_TUNING_THRIFT_CLIENT_POOL_SIZE);

    GenericObjectPool<SlotManagementService.Client> thriftConnectionPool = new GenericObjectPool<>(
            thriftClientFactory);
    thriftConnectionPool.setMaxTotal(thriftClientPoolSize);
    thriftConnectionPool.setTestOnBorrow(true);
    if (socketTimeout > 0) {
        thriftConnectionPool.setTimeBetweenEvictionRunsMillis(socketTimeout / 2);
        thriftConnectionPool.setMinEvictableIdleTimeMillis(socketTimeout);
    }
    thriftClientPool = thriftConnectionPool;
}

From source file:science.freeabyss.hulk.jdbc.dbcp.PoolingDriverExample.java

public static void initDataSource() {
    try {//from  w  w  w .  ja  va2 s .c  om
        //
        // 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.
        //
        PropertiesUtil.init("dbcp.properties");
        Class.forName(PropertiesUtil.getString("dbcp.driver"));

        ConnectionFactory connFactory = new DriverManagerConnectionFactory(PropertiesUtil.getString("dbcp.url"),
                PropertiesUtil.getString("dbcp.username"), PropertiesUtil.getString("dbcp.password"));

        //
        // Next, we'll create the PoolableConnectionFactory, which wraps
        // the "real" Connections created by the ConnectionFactory with
        // the classes that implement the pooling functionality.
        //
        PoolableConnectionFactory poolFactory = new PoolableConnectionFactory(connFactory, null);

        //
        // Now we'll need a ObjectPool that serves as the
        // actual pool of connections.
        //
        // We'll use a GenericObjectPool instance, although
        // any ObjectPool implementation will suffice.
        //
        ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolFactory);

        // Set the factory's pool property to the owning pool
        poolFactory.setPool(connectionPool);

        //
        // Finally, we create the PoolingDriver itself...
        //
        Class.forName("org.apache.commons.dbcp2.PoolingDriver");
        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");

        //
        // ...and register our pool with it.
        //
        driver.registerPool("example", connectionPool);

        //
        // Now we can just use the connect string "jdbc:apache:commons:dbcp:example"
        // to access our pool of Connections.
        //
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }

}

From source file:share.StringBuilderPoolFactory.java

public static GenericObjectPool<StringBuilder> makePool() {
    return new GenericObjectPool<StringBuilder>(PooledStringBuilderFactory.inst());
}

From source file:uk.ac.ed.ph.asciimath.parser.AsciiMathParser.java

public AsciiMathParser(final String classPathLocation) {
    sharedScope = new GenericObjectPool<>(new AsciiMathEngineFactory());
    sharedScope.setTestOnBorrow(true);/*from  w  w w  .  j  a va2 s  . com*/
    sharedScope.setTestOnReturn(true);
    sharedScope.setMaxTotal(10);
}