use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project demo by changlongmao.
the class RedisTemplateConfig method genericObjectPoolConfig.
/**
* GenericObjectPoolConfig 连接池配置
*/
@Bean
public GenericObjectPoolConfig genericObjectPoolConfig() {
GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig();
genericObjectPoolConfig.setMaxIdle(maxIdle);
genericObjectPoolConfig.setMinIdle(minIdle);
genericObjectPoolConfig.setMaxTotal(maxActive);
genericObjectPoolConfig.setMaxWaitMillis(maxWait);
return genericObjectPoolConfig;
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig 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);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project spring-framework-debug by Joker-5.
the class CommonsPool2TargetSource method createObjectPool.
/**
* Subclasses can override this if they want to return a specific Commons pool.
* They should apply any configuration properties to the pool here.
* <p>Default is a GenericObjectPool instance with the given pool size.
* @return an empty Commons {@code ObjectPool}.
* @see GenericObjectPool
* @see #setMaxSize
*/
protected ObjectPool createObjectPool() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(getMaxSize());
config.setMaxIdle(getMaxIdle());
config.setMinIdle(getMinIdle());
config.setMaxWaitMillis(getMaxWait());
config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
config.setBlockWhenExhausted(isBlockWhenExhausted());
return new GenericObjectPool(this, config);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class CommonsPool2TargetSource method createObjectPool.
/**
* Subclasses can override this if they want to return a specific Commons pool.
* They should apply any configuration properties to the pool here.
* <p>Default is a GenericObjectPool instance with the given pool size.
* @return an empty Commons {@code ObjectPool}.
* @see GenericObjectPool
* @see #setMaxSize
*/
protected ObjectPool createObjectPool() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(getMaxSize());
config.setMaxIdle(getMaxIdle());
config.setMinIdle(getMinIdle());
config.setMaxWaitMillis(getMaxWait());
config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
config.setBlockWhenExhausted(isBlockWhenExhausted());
return new GenericObjectPool(this, config);
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project ksan by infinistor.
the class MariaDB method initConnectionPool.
private void initConnectionPool(String dbUrl, String dbPort, String dbName, String userName, String passwd) throws Exception {
try {
Class.forName("org.mariadb.jdbc.Driver");
String jdbcUrl = "jdbc:mariadb://" + dbUrl + ":" + dbPort + "/" + dbName + "?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8";
logger.debug(jdbcUrl);
ConnectionFactory connFactory = new DriverManagerConnectionFactory(jdbcUrl, userName, passwd);
PoolableConnectionFactory poolableConnFactory = new PoolableConnectionFactory(connFactory, null);
poolableConnFactory.setValidationQuery("select 1");
GenericObjectPoolConfig<PoolableConnection> poolConfig = new GenericObjectPoolConfig<PoolableConnection>();
Duration timeBetweenEvictionRuns = Duration.ofSeconds(60);
poolConfig.setTimeBetweenEvictionRuns(timeBetweenEvictionRuns);
poolConfig.setTestWhileIdle(true);
poolConfig.setMinIdle(4);
poolConfig.setMaxTotal(16);
poolConfig.setTestOnBorrow(true);
poolConfig.setTestWhileIdle(true);
GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnFactory, poolConfig);
poolableConnFactory.setPool(connectionPool);
Class.forName("org.apache.commons.dbcp2.PoolingDriver");
PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
driver.registerPool("cpMetering", connectionPool);
jrpool = new JedisPool(dbUrl, 6379);
} catch (ClassNotFoundException e) {
throw new RuntimeException("fail to load JDBC Driver", e);
} catch (SQLException e) {
throw new RuntimeException("fail to load JDBC Driver", e);
}
initDBTable();
loadbuckets();
}
Aggregations