本文整理汇总了Java中org.apache.commons.dbcp.BasicDataSource.setMaxActive方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDataSource.setMaxActive方法的具体用法?Java BasicDataSource.setMaxActive怎么用?Java BasicDataSource.setMaxActive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.dbcp.BasicDataSource
的用法示例。
在下文中一共展示了BasicDataSource.setMaxActive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getJdbcTemplate
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
@Provides
@Singleton
public NamedParameterJdbcTemplate getJdbcTemplate(
@Named("jdbc.driver") String driver,
@Named("jdbc.username") String username,
@Named("jdbc.password") String password,
@Named("jdbc.url") String url,
@Named("jdbc.maxActive") Integer maxActive,
@Named("jdbc.maxIdle") Integer maxIdle,
@Named("jdbc.initialSize") Integer initialSize,
@Named("jdbc.validationQuery") String validationQuery) {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setUrl(url);
dataSource.setMaxActive(maxActive);
dataSource.setMaxIdle(maxIdle);
dataSource.setInitialSize(initialSize);
dataSource.setValidationQuery(validationQuery);
return new NamedParameterJdbcTemplate(dataSource);
}
示例4: 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;
}
示例5: getDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public static DataSource getDataSource() {
BasicDataSource ds = new BasicDataSource();
if (StringUtil.isNotEmpty(driver)) {
ds.setDriverClassName(driver);
}
if (StringUtil.isNotEmpty(url)) {
ds.setUrl(url);
}
if (StringUtil.isNotEmpty(username)) {
ds.setUsername(username);
}
if (StringUtil.isNotEmpty(password)) {
ds.setPassword(password);
}
if (maxActive != 0) {
ds.setMaxActive(maxActive);
}
if (maxIdle != 0) {
ds.setMaxIdle(maxIdle);
}
return ds;
}
示例6: _get
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private static BasicDataSource _get(String D, String username, String passwd, String url, int N) {
BasicDataSource external = new BasicDataSource();
external.setDriverClassName(D.trim());
if (!X.isEmpty(username)) {
external.setUsername(username.trim());
}
if (!X.isEmpty(passwd)) {
external.setPassword(passwd.trim());
}
external.setUrl(url.trim());
external.setMaxActive(N);
external.setDefaultAutoCommit(true);
external.setMaxIdle(N);
external.setMaxWait(MAX_WAIT_TIME);
external.setDefaultAutoCommit(true);
external.setDefaultReadOnly(false);
external.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
external.setValidationQuery(null);// VALIDATION_SQL);
external.setPoolPreparedStatements(true);
return external;
}
示例7: initDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
@PostConstruct
public void initDataSource() throws Exception {
// 读取jdbc.properties配置, 加载数据源
Properties props = ResourceUtils.getResourceAsProperties("jdbc.properties");
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(JDBC_DRIVER_NAME);
ds.setUrl(ensurePropValueNotNull(props.getProperty("db.url")));
ds.setUsername(ensurePropValueNotNull(props.getProperty("db.user")));
ds.setPassword(ensurePropValueNotNull(props.getProperty("db.password")));
ds.setInitialSize(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.initialSize"))));
ds.setMaxActive(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.maxActive"))));
ds.setMaxIdle(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.maxIdle"))));
ds.setMaxWait(Long.parseLong(ensurePropValueNotNull(props.getProperty("db.maxWait"))));
ds.setPoolPreparedStatements(Boolean.parseBoolean(ensurePropValueNotNull(props
.getProperty("db.poolPreparedStatements"))));
this.jt = new JdbcTemplate();
this.jt.setDataSource(ds);
// 设置最大记录数,防止内存膨胀
this.jt.setMaxRows(MAX_ROWS);
// 设置JDBC执行超时时间
this.jt.setQueryTimeout(QUERY_TIMEOUT);
}
示例8: initialize
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
/**
* Create the underlying DBCP BasicDataSource with the
* default supported properties.
*/
private void initialize(
String dbDriver,
String dbURL,
String dbUser,
String dbPassword,
int maxConnections,
String dbValidationQuery) throws SQLException {
if (dbURL == null) {
throw new SQLException(
"DBPool could not be created: DB URL cannot be null");
}
if (dbDriver == null) {
throw new SQLException(
"DBPool '" + dbURL + "' could not be created: " +
"DB driver class name cannot be null!");
}
if (maxConnections < 0) {
throw new SQLException(
"DBPool '" + dbURL + "' could not be created: " +
"Max connections must be greater than zero!");
}
datasource = new BasicDataSource();
datasource.setDriverClassName(dbDriver);
datasource.setUrl(dbURL);
datasource.setUsername(dbUser);
datasource.setPassword(dbPassword);
datasource.setMaxActive(maxConnections);
if (dbValidationQuery != null) {
datasource.setValidationQuery(dbValidationQuery);
}
}
示例9: basicDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
/**
* @return datasource
*/
private BasicDataSource basicDataSource() {
final BasicDataSource dataSource = new BasicDataSource();
// Driver
dataSource.setDriverClassName(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));
// Pool
dataSource.setInitialSize(Integer.parseInt(environment.getRequiredProperty(PROPERTY_NAME_POOL_INITIAL_SIZE)));
dataSource.setMaxActive(Integer.parseInt(environment.getRequiredProperty(PROPERTY_NAME_POOL_MAX_ACTIVE)));
return dataSource;
}
示例10: createDataSource
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
public DataSource createDataSource(String url, String driverClassName, String username, String password) {
BasicDataSource ds = new SerializableBasicDataSource();
ds.setUsername(username);
ds.setPassword(password);
ds.setUrl(url);
ds.setDriverClassName(driverClassName);
ds.setMaxActive(5);
ds.setMaxIdle(2);
return ds;
}
示例11: 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
}
示例12: 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
示例13: setNumConnections
import org.apache.commons.dbcp.BasicDataSource; //导入方法依赖的package包/类
private void setNumConnections(BasicDataSource ds, int initialSize, int maxActive, int maxIdle) {
ds.setInitialSize(initialSize);
ds.setMaxActive(maxActive);
ds.setMaxIdle(maxIdle);
}
示例14: 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;
}
示例15: 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;
}