Example usage for org.apache.commons.pool.impl GenericKeyedObjectPool setTimeBetweenEvictionRunsMillis

List of usage examples for org.apache.commons.pool.impl GenericKeyedObjectPool setTimeBetweenEvictionRunsMillis

Introduction

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

Prototype

public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) 

Source Link

Document

Sets the number of milliseconds to sleep between runs of the idle object evictor thread.

Usage

From source file:com.googlecode.jmxtrans.guice.JmxTransModule.java

private <K, V> GenericKeyedObjectPool getObjectPool(KeyedPoolableObjectFactory<K, V> factory, String poolName) {
    GenericKeyedObjectPool<K, V> pool = new GenericKeyedObjectPool<K, V>(factory);
    pool.setTestOnBorrow(true);//w  w  w .  j a va 2 s. c o m
    pool.setMaxActive(-1);
    pool.setMaxIdle(-1);
    pool.setTimeBetweenEvictionRunsMillis(MILLISECONDS.convert(5, MINUTES));
    pool.setMinEvictableIdleTimeMillis(MILLISECONDS.convert(5, MINUTES));

    try {
        ManagedGenericKeyedObjectPool mbean = new ManagedGenericKeyedObjectPool(pool, poolName);
        ManagementFactory.getPlatformMBeanServer().registerMBean(mbean, mbean.getObjectName());
    } catch (Exception e) {
        log.error("Could not register mbean for pool [{}]", poolName, e);
    }

    return pool;
}

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

public void testSettersAndGetters() throws Exception {
    GenericKeyedObjectPool pool = new GenericKeyedObjectPool();
    {// w w w.java2  s.c  o m
        pool.setFactory(new SimpleFactory());
    }
    {
        pool.setMaxActive(123);
        assertEquals(123, pool.getMaxActive());
    }
    {
        pool.setMaxIdle(12);
        assertEquals(12, pool.getMaxIdle());
    }
    {
        pool.setMaxWait(1234L);
        assertEquals(1234L, pool.getMaxWait());
    }
    {
        pool.setMinEvictableIdleTimeMillis(12345L);
        assertEquals(12345L, pool.getMinEvictableIdleTimeMillis());
    }
    {
        pool.setNumTestsPerEvictionRun(11);
        assertEquals(11, pool.getNumTestsPerEvictionRun());
    }
    {
        pool.setTestOnBorrow(true);
        assertTrue(pool.getTestOnBorrow());
        pool.setTestOnBorrow(false);
        assertTrue(!pool.getTestOnBorrow());
    }
    {
        pool.setTestOnReturn(true);
        assertTrue(pool.getTestOnReturn());
        pool.setTestOnReturn(false);
        assertTrue(!pool.getTestOnReturn());
    }
    {
        pool.setTestWhileIdle(true);
        assertTrue(pool.getTestWhileIdle());
        pool.setTestWhileIdle(false);
        assertTrue(!pool.getTestWhileIdle());
    }
    {
        pool.setTimeBetweenEvictionRunsMillis(11235L);
        assertEquals(11235L, pool.getTimeBetweenEvictionRunsMillis());
    }
    {
        pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_BLOCK, pool.getWhenExhaustedAction());
        pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_FAIL, pool.getWhenExhaustedAction());
        pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
    }
}