本文整理汇总了Java中org.apache.commons.dbcp.BasicDataSource.setMinIdle方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDataSource.setMinIdle方法的具体用法?Java BasicDataSource.setMinIdle怎么用?Java BasicDataSource.setMinIdle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.dbcp.BasicDataSource
的用法示例。
在下文中一共展示了BasicDataSource.setMinIdle方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: register
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public boolean register(JdbcVo conf) {
boolean isOk = true;
try {
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName(conf.getDriverClass());
bds.setUrl(conf.getUrl());
bds.setUsername(conf.getUserName());
bds.setPassword(conf.getPassword());
bds.setInitialSize(conf.getInitialSize());
bds.setMaxActive(conf.getMaxActive());
bds.setMaxIdle(conf.getMaxIdle());
bds.setMinIdle(conf.getMinIdle());
cmap.put(conf.getKey(), bds);
} catch (Exception e) {
logger.error("[db container init key " + conf.getKey() + " datasource error!]", e);
isOk = false;
}
return isOk;
}
示例2: register
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public boolean register(JdbcVo conf) {
boolean isOk = true;
try {
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName(conf.getDriverClass());
bds.setUrl(conf.getUrl());
bds.setUsername(conf.getUserName());
bds.setPassword(conf.getPassword());
bds.setInitialSize(conf.getInitialSize());
bds.setMaxActive(conf.getMaxActive());
bds.setMaxIdle(conf.getMaxIdle());
bds.setMinIdle(conf.getMinIdle());
cmap.put(conf.getKey(), bds);
} catch (Exception e) {
LoggerFactory.getLogger().error("[db container initThreadPool key " + conf.getKey() + " datasource error!]", e);
isOk = false;
}
return isOk;
}
示例3: createFromJdbcUrl
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private static DataSource createFromJdbcUrl(Class<? extends Driver> driverClass, String url,
Credential credential, int numThreads, ImmutableList<String> initSqls, Properties extraConnectionProperties) {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(driverClass.getName());
dataSource.setUrl(url);
dataSource.setUsername(credential.getUsername());
dataSource.setPassword(credential.getPassword());
// connection pool settings
dataSource.setInitialSize(numThreads);
dataSource.setMaxActive(numThreads);
// keep the connections open if possible; only close them via the removeAbandonedTimeout feature
dataSource.setMaxIdle(numThreads);
dataSource.setMinIdle(0);
dataSource.setRemoveAbandonedTimeout(300);
dataSource.setConnectionInitSqls(initSqls.castToList());
if (extraConnectionProperties != null) {
for (String key : extraConnectionProperties.stringPropertyNames()) {
dataSource.addConnectionProperty(key, extraConnectionProperties.getProperty(key));
}
}
return dataSource;
}
示例4: DataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private DataSource() throws IOException, SQLException {
ds = new BasicDataSource();
ds.setDriverClassName("org.postgresql.Driver");
ds.setUsername("alex");
ds.setPassword("");
ds.setUrl("jdbc:postgresql://localhost/infotranspub");
// the settings below are optional -- dbcp can work with defaults
ds.setMinIdle(1);// 5
ds.setMaxActive(1); // 10
ds.setMaxIdle(1); // 20
ds.setMaxOpenPreparedStatements(1); // 180
}
示例5: createDataSourceMetadata
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private CommonsDbcpDataSourcePoolMetadata createDataSourceMetadata(int minSize,
int maxSize) {
BasicDataSource dataSource = createDataSource();
dataSource.setMinIdle(minSize);
dataSource.setMaxActive(maxSize);
return new CommonsDbcpDataSourcePoolMetadata(dataSource);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:CommonsDbcpDataSourcePoolMetadataTests.java
示例6: createDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private DataSource createDataSource(String url, String userName, String password, String driverClassName,
DataMediaType dataMediaType, String encoding) {
BasicDataSource dbcpDs = new BasicDataSource();
dbcpDs.setInitialSize(initialSize);// 初始化连接池时创建的连接数
dbcpDs.setMaxActive(maxActive);// 连接池允许的最大并发连接数,值为非正数时表示不限制
dbcpDs.setMaxIdle(maxIdle);// 连接池中的最大空闲连接数,超过时,多余的空闲连接将会被释放,值为负数时表示不限制
dbcpDs.setMinIdle(minIdle);// 连接池中的最小空闲连接数,低于此数值时将会创建所欠缺的连接,值为0时表示不创建
dbcpDs.setMaxWait(maxWait);// 以毫秒表示的当连接池中没有可用连接时等待可用连接返回的时间,超时则抛出异常,值为-1时表示无限等待
dbcpDs.setRemoveAbandoned(true);// 是否清除已经超过removeAbandonedTimeout设置的无效连接
dbcpDs.setLogAbandoned(true);// 当清除无效链接时是否在日志中记录清除信息的标志
dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // 以秒表示清除无效链接的时限
dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// 确保连接池中没有已破损的连接
dbcpDs.setTestOnBorrow(false);// 指定连接被调用时是否经过校验
dbcpDs.setTestOnReturn(false);// 指定连接返回到池中时是否经过校验
dbcpDs.setTestWhileIdle(true);// 指定连接进入空闲状态时是否经过空闲对象驱逐进程的校验
dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // 以毫秒表示空闲对象驱逐进程由运行状态进入休眠状态的时长,值为非正数时表示不运行任何空闲对象驱逐进程
dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // 以毫秒表示连接被空闲对象驱逐进程驱逐前在池中保持空闲状态的最小时间
// 动态的参数
dbcpDs.setDriverClassName(driverClassName);
dbcpDs.setUrl(url);
dbcpDs.setUsername(userName);
dbcpDs.setPassword(password);
if (dataMediaType.isOracle()) {
dbcpDs.addConnectionProperty("restrictGetTables", "true");
// dbcpDs.setValidationQuery("select 1 from dual");
} else if (dataMediaType.isMysql()) {
// open the batch mode for mysql since 5.1.8
dbcpDs.addConnectionProperty("useServerPrepStmts", "false");
dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true");
dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 将0000-00-00的时间类型返回null
dbcpDs.addConnectionProperty("yearIsDateType", "false");// 直接返回字符串,不做year转换date处理
dbcpDs.addConnectionProperty("noDatetimeStringSync", "true");// 返回时间类型的字符串,不做时区处理
if (StringUtils.isNotEmpty(encoding)) {
if (StringUtils.equalsIgnoreCase(encoding, "utf8mb4")) {
dbcpDs.addConnectionProperty("characterEncoding", "utf8");
dbcpDs.setConnectionInitSqls(Arrays.asList("set names utf8mb4"));
} else {
dbcpDs.addConnectionProperty("characterEncoding", encoding);
}
}
// dbcpDs.setValidationQuery("select 1");
} else {
logger.error("ERROR ## Unknow database type");
}
return dbcpDs;
}
示例7: doCreateDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
protected DataSource doCreateDataSource(String url) {
BasicDataSource dbcpDs = new BasicDataSource();
dbcpDs.setInitialSize(initialSize);// 初始化连接池时创建的连接数
dbcpDs.setMaxActive(maxActive);// 连接池允许的最大并发连接数,值为非正数时表示不限制
dbcpDs.setMaxIdle(maxIdle);// 连接池中的最大空闲连接数,超过时,多余的空闲连接将会被释放,值为负数时表示不限制
dbcpDs.setMinIdle(minIdle);// 连接池中的最小空闲连接数,低于此数值时将会创建所欠缺的连接,值为0时表示不创建
dbcpDs.setMaxWait(maxWait);// 以毫秒表示的当连接池中没有可用连接时等待可用连接返回的时间,超时则抛出异常,值为-1时表示无限等待
dbcpDs.setRemoveAbandoned(true);// 是否清除已经超过removeAbandonedTimeout设置的无效连接
dbcpDs.setLogAbandoned(true);// 当清除无效链接时是否在日志中记录清除信息的标志
dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // 以秒表示清除无效链接的时限
dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// 确保连接池中没有已破损的连接
dbcpDs.setTestOnBorrow(false);// 指定连接被调用时是否经过校验
dbcpDs.setTestOnReturn(false);// 指定连接返回到池中时是否经过校验
dbcpDs.setTestWhileIdle(true);// 指定连接进入空闲状态时是否经过空闲对象驱逐进程的校验
dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // 以毫秒表示空闲对象驱逐进程由运行状态进入休眠状态的时长,值为非正数时表示不运行任何空闲对象驱逐进程
dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // 以毫秒表示连接被空闲对象驱逐进程驱逐前在池中保持空闲状态的最小时间
// 动态的参数
dbcpDs.setDriverClassName(driverClassName);
dbcpDs.setUrl(url);
dbcpDs.setUsername(userName);
dbcpDs.setPassword(password);
if (dataMediaType.isOracle()) {
dbcpDs.addConnectionProperty("restrictGetTables", "true");
dbcpDs.setValidationQuery("select 1 from dual");
} else if (dataMediaType.isMysql()) {
// open the batch mode for mysql since 5.1.8
dbcpDs.addConnectionProperty("useServerPrepStmts", "false");
dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true");
dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 将0000-00-00的时间类型返回null
dbcpDs.addConnectionProperty("yearIsDateType", "false");// 直接返回字符串,不做year转换date处理
if (StringUtils.isNotEmpty(encoding)) {
dbcpDs.addConnectionProperty("characterEncoding", encoding);
}
dbcpDs.setValidationQuery("select 1");
} else {
logger.error("ERROR ## Unknow database type");
}
return dbcpDs;
}
示例8: createDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private DataSource createDataSource(String url, String userName, String password, String driverClassName,
DataMediaType dataMediaType, String encoding) {
BasicDataSource dbcpDs = new BasicDataSource();
dbcpDs.setInitialSize(initialSize);// 初始化连接池时创建的连接数
dbcpDs.setMaxActive(maxActive);// 连接池允许的最大并发连接数,值为非正数时表示不限制
dbcpDs.setMaxIdle(maxIdle);// 连接池中的最大空闲连接数,超过时,多余的空闲连接将会被释放,值为负数时表示不限制
dbcpDs.setMinIdle(minIdle);// 连接池中的最小空闲连接数,低于此数值时将会创建所欠缺的连接,值为0时表示不创建
dbcpDs.setMaxWait(maxWait);// 以毫秒表示的当连接池中没有可用连接时等待可用连接返回的时间,超时则抛出异常,值为-1时表示无限等待
dbcpDs.setRemoveAbandoned(true);// 是否清除已经超过removeAbandonedTimeout设置的无效连接
dbcpDs.setLogAbandoned(true);// 当清除无效链接时是否在日志中记录清除信息的标志
dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // 以秒表示清除无效链接的时限
dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// 确保连接池中没有已破损的连接
dbcpDs.setTestOnBorrow(false);// 指定连接被调用时是否经过校验
dbcpDs.setTestOnReturn(false);// 指定连接返回到池中时是否经过校验
dbcpDs.setTestWhileIdle(true);// 指定连接进入空闲状态时是否经过空闲对象驱逐进程的校验
dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // 以毫秒表示空闲对象驱逐进程由运行状态进入休眠状态的时长,值为非正数时表示不运行任何空闲对象驱逐进程
dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // 以毫秒表示连接被空闲对象驱逐进程驱逐前在池中保持空闲状态的最小时间
// 动态的参数
dbcpDs.setDriverClassName(driverClassName);
dbcpDs.setUrl(url);
dbcpDs.setUsername(userName);
dbcpDs.setPassword(password);
if (dataMediaType.isOracle()) {
dbcpDs.addConnectionProperty("restrictGetTables", "true");
dbcpDs.setValidationQuery("select 1 from dual");
} else if (dataMediaType.isMysql()) {
// open the batch mode for mysql since 5.1.8
dbcpDs.addConnectionProperty("useServerPrepStmts", "false");
dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true");
dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 将0000-00-00的时间类型返回null
dbcpDs.addConnectionProperty("yearIsDateType", "false");// 直接返回字符串,不做year转换date处理
dbcpDs.addConnectionProperty("noDatetimeStringSync", "true");// 返回时间类型的字符串,不做时区处理
if (StringUtils.isNotEmpty(encoding)) {
if (StringUtils.equalsIgnoreCase(encoding, "utf8mb4")) {
dbcpDs.addConnectionProperty("characterEncoding", "utf8");
dbcpDs.setConnectionInitSqls(Arrays.asList("set names utf8mb4"));
} else {
dbcpDs.addConnectionProperty("characterEncoding", encoding);
}
}
dbcpDs.setValidationQuery("select 1");
} else {
logger.error("ERROR ## Unknow database type");
}
return dbcpDs;
}
示例9: createDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private BasicDataSource createDataSource(Map<String, String> properties, String urlPattern) {
BasicDataSource dsPool = new BasicDataSource();
dsPool.setDriverClassName(DSPropertyUtil.getPropertyStringValue("driver", properties, null, null, true));
dsPool.setUsername(DSPropertyUtil.getPropertyStringValue("username", properties, null, null, true));
dsPool.setPassword(DSPropertyUtil.getPropertyStringValue("password", properties, null, null, true));
String url = DSPropertyUtil.getPropertyStringValue("url", properties, null, null, true);
if (null != urlPattern) {
url = DSPropertyUtil.replace(url, "{}", urlPattern);
}
dsPool.setUrl(url);
dsPool.setPoolPreparedStatements(DSPropertyUtil.getPropertyBooleanValue("poolingStatements", properties, null, true, true)); // 开启池的prepared
// 池功能
dsPool.setRemoveAbandoned(DSPropertyUtil.getPropertyBooleanValue("removeAbandoned", properties, null, true, true));
dsPool.setRemoveAbandonedTimeout(DSPropertyUtil.getPropertyIntegerValue("removeAbandonedTimeout", properties, null, 1000, true));
dsPool.setLogAbandoned(DSPropertyUtil.getPropertyBooleanValue("logAbandoned", properties, null, true, true));
dsPool.setInitialSize(DSPropertyUtil.getPropertyIntegerValue("initialSize", properties, null, 2, true));
dsPool.setMaxActive(DSPropertyUtil.getPropertyIntegerValue("maxActive", properties, null, 8, true));
dsPool.setMaxIdle(DSPropertyUtil.getPropertyIntegerValue("maxIdle", properties, null, 8, true));
dsPool.setMinIdle(DSPropertyUtil.getPropertyIntegerValue("minIdle", properties, null, 0, true));
dsPool.setMaxWait(DSPropertyUtil.getPropertyIntegerValue("maxWait", properties, null, 10000, true));
dsPool.setTimeBetweenEvictionRunsMillis(DSPropertyUtil.getPropertyIntegerValue("timeBetweenEvictionRunsMillis", properties, null, -1, true));
dsPool.setTestOnBorrow(DSPropertyUtil.getPropertyBooleanValue("testOnBorrow", properties, null, false, true));
dsPool.setTestOnReturn(DSPropertyUtil.getPropertyBooleanValue("testOnReturn", properties, null, false, true));
dsPool.setTestWhileIdle(DSPropertyUtil.getPropertyBooleanValue("testWhileIdle", properties, null, false, true));
String validationQuery = DSPropertyUtil.getPropertyStringValue("validationQuery", properties, null, null, false);
if (null != validationQuery) {
dsPool.setValidationQuery(validationQuery);
}
int timeout = DSPropertyUtil.getPropertyIntegerValue("", properties, null, -1, false);
if (timeout > -1) {
dsPool.setValidationQueryTimeout(timeout);
}
dsPool.setNumTestsPerEvictionRun(DSPropertyUtil.getPropertyIntegerValue("numTestsPerEvictionRun", properties, null, 10, true));
dsPool.setMinEvictableIdleTimeMillis(DSPropertyUtil.getPropertyIntegerValue("minEvictableIdleTimeMillis", properties, null, 60000, true));
// mysql:select 1
// oracle:select 1 from dual
// sqlserver:select 1
// jtds:select 1
boolean openTest = DSPropertyUtil.getPropertyBooleanValue("openTest", properties, null, false, false);
if (openTest) {
try {
Connection conn = dsPool.getConnection();
conn.close();
log.info("test open database success.");
} catch (Exception e) {
throw new DataSourceException("test open database error: " + e.getMessage(), e);
}
}
return dsPool;
}
示例10: createDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private BasicDataSource createDataSource(Map<String, String> properties, Map<String, String> decryptProperties, String urlPattern) {
BasicDataSource dsPool = new BasicDataSource();
dsPool.setDriverClassName(getPropertyStringValue("driver", properties, null, null, true));
dsPool.setUsername(getPropertyStringValue("username", properties, null, null, true));
dsPool.setPassword(getPropertyStringValue("password", properties, null, null, true));
String url = getPropertyStringValue("url", properties, null, null, true);
if (null != urlPattern) {
url = StringUtils.replace(url, "{}", urlPattern);
}
dsPool.setUrl(url);
dsPool.setPoolPreparedStatements(getPropertyBooleanValue("poolingStatements", properties, null, true, true)); // 开启池的prepared statement 池功能
dsPool.setRemoveAbandoned(getPropertyBooleanValue("removeAbandoned", properties, null, true, true));
dsPool.setRemoveAbandonedTimeout(getPropertyIntegerValue("removeAbandonedTimeout", properties, null, 1000, true));
dsPool.setLogAbandoned(getPropertyBooleanValue("logAbandoned", properties, null, true, true));
dsPool.setInitialSize(getPropertyIntegerValue("initialSize", properties, null, 2, true));
dsPool.setMaxActive(getPropertyIntegerValue("maxActive", properties, null, 8, true));
dsPool.setMaxIdle(getPropertyIntegerValue("maxIdle", properties, null, 8, true));
dsPool.setMinIdle(getPropertyIntegerValue("minIdle", properties, null, 0, true));
dsPool.setMaxWait(getPropertyIntegerValue("maxWait", properties, null, 10000, true));
dsPool.setTimeBetweenEvictionRunsMillis(getPropertyIntegerValue("timeBetweenEvictionRunsMillis", properties, null, -1, true));
dsPool.setTestOnBorrow(getPropertyBooleanValue("testOnBorrow", properties, null, false, true));
dsPool.setTestOnReturn(getPropertyBooleanValue("testOnReturn", properties, null, false, true));
dsPool.setTestWhileIdle(getPropertyBooleanValue("testWhileIdle", properties, null, false, true));
String validationQuery = getPropertyStringValue("validationQuery", properties, null, null, false);
if (null != validationQuery) {
dsPool.setValidationQuery(validationQuery);
}
// dsPool.setValidationQueryTimeout(timeout);
dsPool.setNumTestsPerEvictionRun(getPropertyIntegerValue("numTestsPerEvictionRun", properties, null, 10, true));
dsPool.setMinEvictableIdleTimeMillis(getPropertyIntegerValue("minEvictableIdleTimeMillis", properties, null, 60000, true));
// mysql:select 1
// oracle:select 1 from dual
// sqlserver:select 1
// jtds:select 1
boolean openTest = getPropertyBooleanValue("openTest", properties, null, false, false);
if (openTest) {
try {
Connection conn = dsPool.getConnection();
conn.close();
log.info("test open database success.");
} catch (Exception e) {
throw new DataSourceException("test open database error: " + e.getMessage(), e);
}
}
return dsPool;
}