Example usage for org.apache.commons.pool.impl GenericObjectPool DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS

List of usage examples for org.apache.commons.pool.impl GenericObjectPool DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS

Introduction

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

Prototype

long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS

To view the source code for org.apache.commons.pool.impl GenericObjectPool DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS.

Click Source Link

Document

The default value for #getMinEvictableIdleTimeMillis .

Usage

From source file:com.alibaba.cobar.manager.test.ConnectionTest.java

/**
 * @param args/* ww  w. j a v a  2  s  .  c  o  m*/
 */
public static void main(String[] args) {
    try {
        BasicDataSource ds = new BasicDataSource();
        ds.setUsername("test");
        ds.setPassword("");
        ds.setUrl("jdbc:mysql://10.20.153.178:9066/");
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setMaxActive(-1);
        ds.setMinIdle(0);
        ds.setTimeBetweenEvictionRunsMillis(600000);
        ds.setNumTestsPerEvictionRun(Integer.MAX_VALUE);
        ds.setMinEvictableIdleTimeMillis(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
        Connection conn = ds.getConnection();

        Statement stm = conn.createStatement();
        stm.execute("show @@version");

        ResultSet rst = stm.getResultSet();
        rst.next();
        String version = rst.getString("VERSION");

        System.out.println(version);

    } catch (Exception exception) {
        System.out.println("10.20.153.178:9066   " + exception.getMessage() + exception);
    }
}

From source file:com.alibaba.cobar.manager.qa.modle.CobarFactory.java

public static CobarAdapter getCobarAdapter(String cobarNodeName) throws IOException {
    CobarAdapter cAdapter = new CobarAdapter();
    Properties prop = new Properties();
    prop.load(CobarFactory.class.getClassLoader().getResourceAsStream("cobarNode.properties"));
    BasicDataSource ds = new BasicDataSource();
    String user = prop.getProperty(cobarNodeName + ".user").trim();
    String password = prop.getProperty(cobarNodeName + ".password").trim();
    String ip = prop.getProperty(cobarNodeName + ".ip").trim();
    int managerPort = Integer.parseInt(prop.getProperty(cobarNodeName + ".manager.port").trim());
    int maxActive = -1;
    int minIdle = 0;
    long timeBetweenEvictionRunsMillis = 10 * 60 * 1000;
    int numTestsPerEvictionRun = Integer.MAX_VALUE;
    long minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
    ds.setUsername(user);//from www .j  a va2 s  . c  o  m
    ds.setPassword(password);
    ds.setUrl(new StringBuilder().append("jdbc:mysql://").append(ip).append(":").append(managerPort).append("/")
            .toString());
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setMaxActive(maxActive);
    ds.setMinIdle(minIdle);
    ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    ds.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

    cAdapter.setDataSource(ds);
    return cAdapter;
}

From source file:com.fjn.helper.frameworkex.apache.commons.pool.connectionPool.ConnectionManager.java

/**
 *
 * @param maxNum// w  w  w  .  j  a  v a 2  s  .  c o  m
 * @param maxIdleCount
 * @param minIdleCount
 * @param maxWaitTime
 *
 */
public void initConnectionPool(int maxNum, int maxIdleCount, int minIdleCount, long maxWaitTime) {
    int maxActive = maxNum;
    byte whenExhaustedAction = GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
    long maxWait = maxWaitTime;
    int maxIdle = maxIdleCount;
    int minIdle = minIdleCount;
    boolean testOnBorrow = GenericObjectPool.DEFAULT_TEST_ON_BORROW;
    boolean testOnReturn = GenericObjectPool.DEFAULT_TEST_ON_RETURN;
    long timeBetweenEvictionRunsMillis = GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
    int numTestsPerEvictionRun = GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
    long minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
    boolean testWhileIdle = GenericObjectPool.DEFAULT_TEST_WHILE_IDLE;
    long softMinEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
    boolean lifo = GenericObjectPool.DEFAULT_LIFO;
    connPoolFactory = new ConnectionPoolFactory(connFactory, maxActive, whenExhaustedAction, maxWait, maxIdle,
            minIdle, testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
            minEvictableIdleTimeMillis, testWhileIdle, softMinEvictableIdleTimeMillis, lifo);

}

From source file:com.toolsverse.etl.sql.connection.PooledAliasConnectionProvider.java

/**
 * Instantiates a new pooled alias connection provider.
 *///from w w  w  .  j  a v  a 2 s .  c o  m
public PooledAliasConnectionProvider() {
    _config = new GenericObjectPool.Config();

    _config.maxActive = Utils.str2Int(SystemConfig.instance().getSystemProperty(MAX_ACTIVE),
            GenericObjectPool.DEFAULT_MAX_ACTIVE);

    _config.whenExhaustedAction = Utils.str2Byte(
            SystemConfig.instance().getSystemProperty(WHEN_EXHAUSTED_ACTION),
            GenericObjectPool.WHEN_EXHAUSTED_GROW);

    _config.maxWait = Utils.str2Long(SystemConfig.instance().getSystemProperty(MAX_WAIT), 1000 * 30);

    _config.maxIdle = Utils.str2Int(SystemConfig.instance().getSystemProperty(MAX_IDLE),
            GenericObjectPool.DEFAULT_MAX_IDLE);

    _config.minIdle = Utils.str2Int(SystemConfig.instance().getSystemProperty(MIN_IDLE),
            GenericObjectPool.DEFAULT_MIN_IDLE);

    _config.testOnBorrow = Utils.str2Boolean(SystemConfig.instance().getSystemProperty(TEST_ON_BORROW),
            GenericObjectPool.DEFAULT_TEST_ON_BORROW);

    _config.testOnReturn = Utils.str2Boolean(SystemConfig.instance().getSystemProperty(TEST_ON_RETURN),
            GenericObjectPool.DEFAULT_TEST_ON_RETURN);

    _config.timeBetweenEvictionRunsMillis = Utils.str2Long(
            SystemConfig.instance().getSystemProperty(TIME_BETWEEN_EVICTION_RUNS_MILLIS),
            GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);

    _config.numTestsPerEvictionRun = Utils.str2Int(
            SystemConfig.instance().getSystemProperty(NUM_TESTS_PER_EVICTION_RUN),
            GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN);

    _config.minEvictableIdleTimeMillis = Utils.str2Long(
            SystemConfig.instance().getSystemProperty(MIN_EVICTABLE_IDLE_TIME_MILLIS),
            GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);

    _config.testWhileIdle = Utils.str2Boolean(SystemConfig.instance().getSystemProperty(TEST_WHILE_IDLE),
            GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
}

From source file:com.flipkart.phantom.thrift.impl.ThriftProxy.java

/**
 * Initialize this ThriftProxy//w  w w.j  a va  2 s .com
 */
public void init(TaskContext context) throws Exception {
    if (this.thriftServiceClass == null) {
        throw new AssertionError("The 'thriftServiceClass' may not be null");
    }
    if (this.processMap == null || this.processMap.isEmpty()) {
        throw new AssertionError(
                "ProcessFunctions not populated. Maybe The 'thriftServiceClass' is not a valid class?");
    }
    if (this.thriftTimeoutMillis == -1) { // implying none set
        throw new Exception("'thriftTimeoutMillis' must be set to a non-negative value!");
    }

    //Create pool
    this.socketPool = new GenericObjectPool<Socket>(new SocketObjectFactory(this), this.poolSize,
            GenericObjectPool.WHEN_EXHAUSTED_GROW, this.maxWait, this.maxIdle, this.minIdle, false, false,
            this.timeBetweenEvictionRunsMillis, GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
            GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, true);
}

From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java

public void testInvalidWhenExhaustedAction() throws Exception {
    try {//from   www. j a v  a2s  . c  o m
        pool.setWhenExhaustedAction(Byte.MAX_VALUE);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // expected
    }

    try {
        ObjectPool pool = new GenericObjectPool(new SimpleFactory(), GenericObjectPool.DEFAULT_MAX_ACTIVE,
                Byte.MAX_VALUE, GenericObjectPool.DEFAULT_MAX_WAIT, GenericObjectPool.DEFAULT_MAX_IDLE, false,
                false, GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, false);
        assertNotNull(pool);
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // expected
    }
}

From source file:org.apache.avalon.dbcp.DbcpConnectionManager.java

/**
 * Returns an object pool configuration object populated with data
 * retrieved from the component's configuration.  Defaults correspond
 * to the <code>GenericObjectPool</code> default values.
 *   //from  w  ww  . j a  v a2 s . co m
 * @return <code>GenericObjectPool.Config</code> instance containing
 * the pool's configuration parameters
 */
private GenericObjectPool.Config getPoolConfig() {
    GenericObjectPool.Config config = new GenericObjectPool.Config();
    if (m_pool != null) {
        config.maxActive = m_pool.getAttributeAsInteger("max-active", GenericObjectPool.DEFAULT_MAX_ACTIVE);
        config.maxIdle = m_pool.getAttributeAsInteger("max-idle", GenericObjectPool.DEFAULT_MAX_IDLE);
        config.maxWait = m_pool.getAttributeAsLong("max-wait", GenericObjectPool.DEFAULT_MAX_WAIT);
        config.minEvictableIdleTimeMillis = m_pool.getAttributeAsLong("min-evict-idle-time",
                GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
        config.minIdle = m_pool.getAttributeAsInteger("min-idle", GenericObjectPool.DEFAULT_MIN_IDLE);
        config.numTestsPerEvictionRun = m_pool.getAttributeAsInteger("num-evict-tests",
                GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN);
        config.testOnBorrow = m_pool.getAttributeAsBoolean("test-on-borrow",
                GenericObjectPool.DEFAULT_TEST_ON_BORROW);
        config.testOnReturn = m_pool.getAttributeAsBoolean("test-on-return",
                GenericObjectPool.DEFAULT_TEST_ON_RETURN);
        config.testWhileIdle = m_pool.getAttributeAsBoolean("test-while-idle",
                GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
        config.timeBetweenEvictionRunsMillis = m_pool.getAttributeAsLong("time-between-evict-runs",
                GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
        config.whenExhaustedAction = GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
    }
    return config;
}

From source file:org.apache.cayenne.conf.CustomDBCPDataSourceBuilder.java

private KeyedObjectPoolFactory createPreparedStatementPool() {

    if (!config.getBoolean("poolPreparedStatements", false)) {
        return null;
    }/*w w w .j a  v a2  s. c  o  m*/

    // the GenericKeyedObjectPool.Config object isn't used because
    // although it has provision for the maxTotal parameter when
    // passed to the GenericKeyedObjectPoolFactory constructor
    // this parameter is not being properly set as a default for
    // creating prepared statement pools

    int maxActive = config.getInt(PS_MAX_ACTIVE, GenericObjectPool.DEFAULT_MAX_ACTIVE);
    byte whenExhaustedAction = config.getWhenExhaustedAction(PS_EXHAUSTED_ACTION,
            GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION);
    long maxWait = config.getLong(PS_MAX_WAIT, GenericObjectPool.DEFAULT_MAX_WAIT);
    int maxIdle = config.getInt(PS_MAX_IDLE, GenericObjectPool.DEFAULT_MAX_IDLE);
    int maxTotal = config.getInt(PS_MAX_TOTAL, 1);

    boolean testOnBorrow = config.getBoolean(PS_TEST_ON_BORROW, GenericObjectPool.DEFAULT_TEST_ON_BORROW);
    boolean testOnReturn = config.getBoolean(PS_TEST_ON_RETURN, GenericObjectPool.DEFAULT_TEST_ON_RETURN);

    long timeBetweenEvictionRunsMillis = config.getLong(PS_TIME_BETWEEN_EVICTIONS,
            GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
    int numTestsPerEvictionRun = config.getInt(PS_NUM_TEST_PER_EVICTION,
            GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN);

    long minEvictableIdleTimeMillis = config.getLong(PS_MIN_EVICTABLE_TIME,
            GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);

    boolean testWhileIdle = config.getBoolean(PS_TEST_IDLE, GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);

    return new GenericKeyedObjectPoolFactory(null, maxActive, whenExhaustedAction, maxWait, maxIdle, maxTotal,
            testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
            minEvictableIdleTimeMillis, testWhileIdle);
}

From source file:org.apache.cayenne.conf.CustomDBCPDataSourceBuilder.java

private GenericObjectPool.Config createConnectionPoolConfig() {
    GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();

    poolConfig.maxIdle = config.getInt(MAX_IDLE, GenericObjectPool.DEFAULT_MAX_IDLE);
    poolConfig.minIdle = config.getInt(MIN_IDLE, GenericObjectPool.DEFAULT_MIN_IDLE);
    poolConfig.maxActive = config.getInt(MAX_ACTIVE, GenericObjectPool.DEFAULT_MAX_ACTIVE);
    poolConfig.maxWait = config.getLong(MAX_WAIT, GenericObjectPool.DEFAULT_MAX_WAIT);

    poolConfig.testOnBorrow = config.getBoolean(TEST_ON_BORROW, GenericObjectPool.DEFAULT_TEST_ON_BORROW);
    poolConfig.testOnReturn = config.getBoolean(TEST_ON_RETURN, GenericObjectPool.DEFAULT_TEST_ON_RETURN);
    poolConfig.testWhileIdle = config.getBoolean(TEST_IDLE, GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);

    poolConfig.timeBetweenEvictionRunsMillis = config.getLong(TIME_BETWEEN_EVICTIONS,
            GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
    poolConfig.numTestsPerEvictionRun = config.getInt(NUM_TEST_PER_EVICTION,
            GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN);
    poolConfig.minEvictableIdleTimeMillis = config.getLong(MIN_EVICTABLE_TIME,
            GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);

    poolConfig.whenExhaustedAction = config.getWhenExhaustedAction(EXHAUSTED_ACTION,
            GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION);

    return poolConfig;
}

From source file:org.apache.hadoop.hive.metastore.datasource.DbCPDataSourceProvider.java

@Override
public DataSource create(Configuration hdpConfig) throws SQLException {

    LOG.debug("Creating dbcp connection pool for the MetaStore");

    String driverUrl = DataSourceProvider.getMetastoreJdbcDriverUrl(hdpConfig);
    String user = DataSourceProvider.getMetastoreJdbcUser(hdpConfig);
    String passwd = DataSourceProvider.getMetastoreJdbcPasswd(hdpConfig);
    int maxPoolSize = hdpConfig.getInt(MetastoreConf.ConfVars.CONNECTION_POOLING_MAX_CONNECTIONS.getVarname(),
            ((Long) MetastoreConf.ConfVars.CONNECTION_POOLING_MAX_CONNECTIONS.getDefaultVal()).intValue());
    long connectionTimeout = hdpConfig.getLong(CONNECTION_TIMEOUT_PROPERTY, 30000L);
    int connectionMaxIlde = hdpConfig.getInt(CONNECTION_MAX_IDLE_PROPERTY, GenericObjectPool.DEFAULT_MAX_IDLE);
    int connectionMinIlde = hdpConfig.getInt(CONNECTION_MIN_IDLE_PROPERTY, GenericObjectPool.DEFAULT_MIN_IDLE);
    boolean testOnBorrow = hdpConfig.getBoolean(CONNECTION_TEST_BORROW_PROPERTY,
            GenericObjectPool.DEFAULT_TEST_ON_BORROW);
    long evictionTimeMillis = hdpConfig.getLong(CONNECTION_MIN_EVICT_MILLIS_PROPERTY,
            GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    boolean testWhileIdle = hdpConfig.getBoolean(CONNECTION_TEST_IDLEPROPERTY,
            GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
    long timeBetweenEvictionRuns = hdpConfig.getLong(CONNECTION_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
    int numTestsPerEvictionRun = hdpConfig.getInt(CONNECTION_NUM_TESTS_PER_EVICTION_RUN,
            GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN);
    boolean testOnReturn = hdpConfig.getBoolean(CONNECTION_TEST_ON_RETURN,
            GenericObjectPool.DEFAULT_TEST_ON_RETURN);
    long softMinEvictableIdleTimeMillis = hdpConfig.getLong(CONNECTION_SOFT_MIN_EVICTABLE_IDLE_TIME,
            GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    boolean lifo = hdpConfig.getBoolean(CONNECTION_LIFO, GenericObjectPool.DEFAULT_LIFO);

    GenericObjectPool objectPool = new GenericObjectPool();
    objectPool.setMaxActive(maxPoolSize);
    objectPool.setMaxWait(connectionTimeout);
    objectPool.setMaxIdle(connectionMaxIlde);
    objectPool.setMinIdle(connectionMinIlde);
    objectPool.setTestOnBorrow(testOnBorrow);
    objectPool.setTestWhileIdle(testWhileIdle);
    objectPool.setMinEvictableIdleTimeMillis(evictionTimeMillis);
    objectPool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns);
    objectPool.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    objectPool.setTestOnReturn(testOnReturn);
    objectPool.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
    objectPool.setLifo(lifo);//from   w ww  .  j  ava 2  s. c  om

    ConnectionFactory connFactory = new DriverManagerConnectionFactory(driverUrl, user, passwd);
    // This doesn't get used, but it's still necessary, see
    // https://git1-us-west.apache.org/repos/asf?p=commons-dbcp.git;a=blob;f=doc/ManualPoolingDataSourceExample.java;
    // h=f45af2b8481f030b27364e505984c0eef4f35cdb;hb=refs/heads/DBCP_1_5_x_BRANCH
    new PoolableConnectionFactory(connFactory, objectPool, null, null, false, true);

    return new PoolingDataSource(objectPool);
}