本文整理汇总了Java中org.apache.commons.pool2.impl.GenericObjectPoolConfig.setTestOnBorrow方法的典型用法代码示例。如果您正苦于以下问题:Java GenericObjectPoolConfig.setTestOnBorrow方法的具体用法?Java GenericObjectPoolConfig.setTestOnBorrow怎么用?Java GenericObjectPoolConfig.setTestOnBorrow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.pool2.impl.GenericObjectPoolConfig
的用法示例。
在下文中一共展示了GenericObjectPoolConfig.setTestOnBorrow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGenericPoolConfig
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入方法依赖的package包/类
public GenericObjectPoolConfig getGenericPoolConfig() {
GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig();
genericObjectPoolConfig.setLifo(this.lifo);
genericObjectPoolConfig.setMinIdle(this.minIdle);
genericObjectPoolConfig.setMaxIdle(this.maxIdle);
genericObjectPoolConfig.setMaxTotal(this.maxTotal);
genericObjectPoolConfig.setNumTestsPerEvictionRun(this.numtestsPerEviction);
genericObjectPoolConfig.setBlockWhenExhausted(this.blockedWhenExhausted);
genericObjectPoolConfig.setTimeBetweenEvictionRunsMillis(this.timeBetweenEvictionRun);
genericObjectPoolConfig.setTestOnBorrow(this.testOnBorrow);
genericObjectPoolConfig.setTestOnCreate(this.testOnCreate);
genericObjectPoolConfig.setTestOnReturn(this.testOnReturn);
return genericObjectPoolConfig;
}
示例2: JbootClusterRedisImpl
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入方法依赖的package包/类
public JbootClusterRedisImpl(JbootRedisConfig config) {
Integer timeout = config.getTimeout();
String password = config.getPassword();
Integer maxAttempts = config.getMaxAttempts();
if (timeout != null) {
this.timeout = timeout;
}
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
if (StringUtils.isNotBlank(config.getTestWhileIdle())) {
poolConfig.setTestWhileIdle(config.getTestWhileIdle());
}
if (StringUtils.isNotBlank(config.getTestOnBorrow())) {
poolConfig.setTestOnBorrow(config.getTestOnBorrow());
}
if (StringUtils.isNotBlank(config.getTestOnCreate())) {
poolConfig.setTestOnCreate(config.getTestOnCreate());
}
if (StringUtils.isNotBlank(config.getTestOnReturn())) {
poolConfig.setTestOnReturn(config.getTestOnReturn());
}
if (StringUtils.isNotBlank(config.getMinEvictableIdleTimeMillis())) {
poolConfig.setMinEvictableIdleTimeMillis(config.getMinEvictableIdleTimeMillis());
}
if (StringUtils.isNotBlank(config.getTimeBetweenEvictionRunsMillis())) {
poolConfig.setTimeBetweenEvictionRunsMillis(config.getTimeBetweenEvictionRunsMillis());
}
if (StringUtils.isNotBlank(config.getNumTestsPerEvictionRun())) {
poolConfig.setNumTestsPerEvictionRun(config.getNumTestsPerEvictionRun());
}
this.jedisCluster = newJedisCluster(config.getHostAndPorts(), timeout, maxAttempts, password, poolConfig);
}
示例3: RedisRegistry
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; //导入方法依赖的package包/类
public RedisRegistry(URL url) {
super(url);
if (url.isAnyHost()) {
throw new IllegalStateException("registry address == null");
}
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setTestOnBorrow(url.getParameter("test.on.borrow", true));
config.setTestOnReturn(url.getParameter("test.on.return", false));
config.setTestWhileIdle(url.getParameter("test.while.idle", false));
if (url.getParameter("max.idle", 0) > 0)
config.setMaxIdle(url.getParameter("max.idle", 0));
if (url.getParameter("min.idle", 0) > 0)
config.setMinIdle(url.getParameter("min.idle", 0));
if (url.getParameter("max.active", 0) > 0)
config.setMaxTotal(url.getParameter("max.active", 0));
if (url.getParameter("max.total", 0) > 0)
config.setMaxTotal(url.getParameter("max.total", 0));
if (url.getParameter("max.wait", url.getParameter("timeout", 0)) > 0)
config.setMaxWaitMillis(url.getParameter("max.wait", url.getParameter("timeout", 0)));
if (url.getParameter("num.tests.per.eviction.run", 0) > 0)
config.setNumTestsPerEvictionRun(url.getParameter("num.tests.per.eviction.run", 0));
if (url.getParameter("time.between.eviction.runs.millis", 0) > 0)
config.setTimeBetweenEvictionRunsMillis(url.getParameter("time.between.eviction.runs.millis", 0));
if (url.getParameter("min.evictable.idle.time.millis", 0) > 0)
config.setMinEvictableIdleTimeMillis(url.getParameter("min.evictable.idle.time.millis", 0));
String cluster = url.getParameter("cluster", "failover");
if (!"failover".equals(cluster) && !"replicate".equals(cluster)) {
throw new IllegalArgumentException("Unsupported redis cluster: " + cluster + ". The redis cluster only supported failover or replicate.");
}
replicate = "replicate".equals(cluster);
List<String> addresses = new ArrayList<String>();
addresses.add(url.getAddress());
String[] backups = url.getParameter(Constants.BACKUP_KEY, new String[0]);
if (backups != null && backups.length > 0) {
addresses.addAll(Arrays.asList(backups));
}
for (String address : addresses) {
int i = address.indexOf(':');
String host;
int port;
if (i > 0) {
host = address.substring(0, i);
port = Integer.parseInt(address.substring(i + 1));
} else {
host = address;
port = DEFAULT_REDIS_PORT;
}
this.jedisPools.put(address, new JedisPool(config, host, port,
url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)));
}
this.reconnectPeriod = url.getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD);
String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
if (!group.startsWith(Constants.PATH_SEPARATOR)) {
group = Constants.PATH_SEPARATOR + group;
}
if (!group.endsWith(Constants.PATH_SEPARATOR)) {
group = group + Constants.PATH_SEPARATOR;
}
this.root = group;
this.expirePeriod = url.getParameter(Constants.SESSION_TIMEOUT_KEY, Constants.DEFAULT_SESSION_TIMEOUT);
this.expireFuture = expireExecutor.scheduleWithFixedDelay(new Runnable() {
public void run() {
try {
deferExpired(); // 延长过期时间
} catch (Throwable t) { // 防御性容错
logger.error("Unexpected exception occur at defer expire time, cause: " + t.getMessage(), t);
}
}
}, expirePeriod / 2, expirePeriod / 2, TimeUnit.MILLISECONDS);
}