Search in sources :

Example 1 with User

use of com.emily.cloud.test.api.po.User in project spring-parent by mingyang66.

the class PoolMain method main.

public static void main(String[] args) throws Exception {
    ObjectFactory orderFactory = new ObjectFactory();
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(5000);
    // 设置获取连接超时时间
    config.setMaxWaitMillis(1000);
    GenericObjectPool<User> connectionPool = new GenericObjectPool<User>(orderFactory, config);
    long start = System.currentTimeMillis();
    for (int i = 0; i < 100000; i++) {
        User o = connectionPool.borrowObject();
        // User o = new User();
        // System.out.println("brrow a connection: " + o +" active connection:"+connectionPool.getNumActive());
        connectionPool.returnObject(o);
    }
    System.out.println(System.currentTimeMillis() - start);
}
Also used : User(com.emily.cloud.test.api.po.User) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool)

Aggregations

User (com.emily.cloud.test.api.po.User)1 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)1 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)1