本文整理匯總了Java中com.mchange.v2.c3p0.ComboPooledDataSource.setMaxIdleTime方法的典型用法代碼示例。如果您正苦於以下問題:Java ComboPooledDataSource.setMaxIdleTime方法的具體用法?Java ComboPooledDataSource.setMaxIdleTime怎麽用?Java ComboPooledDataSource.setMaxIdleTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mchange.v2.c3p0.ComboPooledDataSource
的用法示例。
在下文中一共展示了ComboPooledDataSource.setMaxIdleTime方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: start
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public boolean start() {
if (isStarted)
return true;
dataSource = new ComboPooledDataSource();
dataSource.setJdbcUrl(jdbcUrl);
dataSource.setUser(user);
dataSource.setPassword(password);
try {
dataSource.setDriverClass(driverClass);
} catch (PropertyVetoException e) {
dataSource = null;
logger.error("C3p0Plugin start error");
throw new RuntimeException(e);
}
dataSource.setMaxPoolSize(maxPoolSize);
dataSource.setMinPoolSize(minPoolSize);
dataSource.setInitialPoolSize(initialPoolSize);
dataSource.setMaxIdleTime(maxIdleTime);
dataSource.setAcquireIncrement(acquireIncrement);
isStarted = true;
return true;
}
示例2: createNewDataSource
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
private ComboPooledDataSource createNewDataSource() throws Exception {
ComboPooledDataSource c3p0DataSource = new ComboPooledDataSource();
c3p0DataSource.setDriverClass(config.getDriverClassName()); //loads the jdbc driver
c3p0DataSource.setJdbcUrl(config.getJdbcUrl());
c3p0DataSource.setUser(config.getUserName());
c3p0DataSource.setPassword(config.getPassword());
// the settings below are optional -- c3p0 can work with defaults
c3p0DataSource.setMinPoolSize(config.getMinPoolSize());
c3p0DataSource.setMaxPoolSize(config.getMaxPoolSize());
c3p0DataSource.setAcquireIncrement(config.getAcquireIncrement());
c3p0DataSource.setMaxStatements(config.getMaxStatements());
c3p0DataSource.setIdleConnectionTestPeriod(config.getIdleTestPeriod());
c3p0DataSource.setMaxIdleTime(config.getMaxIdleTime());
return c3p0DataSource;
}
示例3: datasource
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Bean(name = "NextRTCDataSource", destroyMethod = "close")
public ComboPooledDataSource datasource() throws PropertyVetoException {
ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setMinPoolSize(1);
ds.setMaxPoolSize(10);
ds.setCheckoutTimeout(30 * 60 * 100);
ds.setMaxIdleTime(30 * 60); // 30 minutes
ds.setMaxStatements(10);
ds.setMaxStatementsPerConnection(10);
ds.setAutoCommitOnClose(true);
ds.setDriverClass(environment.getRequiredProperty("nextrtc.db.driverClassName"));
ds.setJdbcUrl(environment.getRequiredProperty("nextrtc.db.url"));
ds.setUser(environment.getRequiredProperty("nextrtc.db.username"));
ds.setPassword(environment.getRequiredProperty("nextrtc.db.password"));
return ds;
}
示例4: configDataSource
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public static DataSource configDataSource(RepDatabase cfg)
throws PropertyVetoException {
ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setDriverClass(cfg.getDriverclass().trim());
// loads the jdbc driver
ds.setJdbcUrl(cfg.getUrl().trim());
ds.setUser(cfg.getUsername().trim());
ds.setPassword(cfg.getPassword().trim());
ds.setMaxStatements(20);//
ds.setMaxIdleTime(cfg.getMaxidletime());// 最大空閑時間,60秒內未使用則連接被丟棄。若為0則永不丟棄
ds.setMaxPoolSize(cfg.getMaxpoolsize());// 池最大連接數
ds.setMinPoolSize(cfg.getMinpoolsize());// 池最小連接數
// 檢查有效性
if(StringHelper.isNotEmpty(cfg.getTestquerysql())&&cfg.getTestoeriod()!=null){
ds.setPreferredTestQuery(cfg.getTestquerysql());
ds.setIdleConnectionTestPeriod(cfg.getTestoeriod());// 每隔10分鍾檢查一次空閑連接的有效性
}
//獲取連接超時
ds.setCheckoutTimeout(10000);
return ds;
}
示例5: setup
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public SqlgDataSource setup(String driver, Configuration configuration) throws Exception {
Preconditions.checkState(configuration.containsKey(SqlgGraph.JDBC_URL));
Preconditions.checkState(configuration.containsKey("jdbc.username"));
Preconditions.checkState(configuration.containsKey("jdbc.password"));
String connectURI = configuration.getString(SqlgGraph.JDBC_URL);
String username = configuration.getString("jdbc.username");
String password = configuration.getString("jdbc.password");
ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
comboPooledDataSource.setDriverClass(driver);
comboPooledDataSource.setJdbcUrl(connectURI);
comboPooledDataSource.setMaxPoolSize(configuration.getInt("maxPoolSize", 100));
// comboPooledDataSource.setInitialPoolSize(1);
// comboPooledDataSource.setMinPoolSize(1);
// comboPooledDataSource.setMaxPoolSize(1);
comboPooledDataSource.setMaxIdleTime(configuration.getInt("maxIdleTime", 3600));
comboPooledDataSource.setForceUseNamedDriverClass(true);
if (!StringUtils.isEmpty(username)) {
comboPooledDataSource.setUser(username);
}
if (!StringUtils.isEmpty(password)) {
comboPooledDataSource.setPassword(password);
}
return new C3P0DataSource(connectURI, comboPooledDataSource);
}
示例6: wrap
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public DataSource wrap(ReportDataSource rptDs) {
try {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDriverClass(rptDs.getDriverClass());
dataSource.setJdbcUrl(rptDs.getJdbcUrl());
dataSource.setUser(rptDs.getUser());
dataSource.setPassword(rptDs.getPassword());
dataSource.setInitialPoolSize(MapUtils.getInteger(rptDs.getOptions(), "initialPoolSize", 3));
dataSource.setMinPoolSize(MapUtils.getInteger(rptDs.getOptions(), "minPoolSize", 1));
dataSource.setMaxPoolSize(MapUtils.getInteger(rptDs.getOptions(), "maxPoolSize", 20));
dataSource.setMaxStatements(MapUtils.getInteger(rptDs.getOptions(), "maxStatements", 50));
dataSource.setMaxIdleTime(MapUtils.getInteger(rptDs.getOptions(), "maxIdleTime", 1800));
dataSource.setAcquireIncrement(MapUtils.getInteger(rptDs.getOptions(), "acquireIncrement", 3));
dataSource.setAcquireRetryAttempts(MapUtils.getInteger(rptDs.getOptions(), "acquireRetryAttempts", 30));
dataSource.setIdleConnectionTestPeriod(
MapUtils.getInteger(rptDs.getOptions(), "idleConnectionTestPeriod", 60));
dataSource.setBreakAfterAcquireFailure(
MapUtils.getBoolean(rptDs.getOptions(), "breakAfterAcquireFailure", false));
dataSource.setTestConnectionOnCheckout(
MapUtils.getBoolean(rptDs.getOptions(), "testConnectionOnCheckout", false));
return dataSource;
} catch (Exception ex) {
throw new RuntimeException("C3p0DataSourcePool Create Error", ex);
}
}
示例7: getConnection
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public synchronized Connection getConnection(Configuration conf) throws SQLException {
DriverConfig config = getDriverConfigfromConf(conf);
if (!dataSourceMap.containsKey(config)) {
ComboPooledDataSource cpds = new ComboPooledDataSource();
try {
cpds.setDriverClass(config.driverClass);
} catch (PropertyVetoException e) {
throw new IllegalArgumentException("Unable to set driver class:" + config.driverClass, e);
}
cpds.setJdbcUrl(config.jdbcURI);
cpds.setProperties(config.properties);
cpds.setMaxPoolSize(Integer.parseInt(config.getProperty(JDBC_POOL_MAX_SIZE.getPoolProperty())));
cpds.setMaxIdleTime(Integer.parseInt(config.getProperty(JDBC_POOL_IDLE_TIME.getPoolProperty())));
cpds.setMaxIdleTimeExcessConnections(Integer.parseInt(config.getProperty(JDBC_MAX_IDLE_TIME_EXCESS_CONNECTIONS
.getPoolProperty())));
cpds.setMaxStatementsPerConnection(Integer.parseInt(config.getProperty(JDBC_MAX_STATEMENTS_PER_CONNECTION
.getPoolProperty())));
cpds.setCheckoutTimeout(Integer.parseInt(config.getProperty(JDBC_GET_CONNECTION_TIMEOUT.getPoolProperty())));
dataSourceMap.put(config, cpds);
log.info("Created new datasource for config: {}", config);
}
return dataSourceMap.get(config).getConnection();
}
示例8: getDataSource
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
private DataSource getDataSource(C3P0 c3p0) throws Exception {
ComboPooledDataSource ds = new ComboPooledDataSource(true);
ds.setDataSourceName("C3PO");
ds.setJdbcUrl(c3p0.jdbcUrl);
ds.setDriverClass(c3p0.driverClass);
ds.setUser(c3p0.user);
ds.setPassword(c3p0.password);
ds.setMaxIdleTime(c3p0.maxIdleTime);
ds.setMaxPoolSize((c3p0.maxPoolSize));
ds.setMinPoolSize(c3p0.minPoolSize);
return ds;
}
示例9: DAOFactory
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
protected DAOFactory(String driverClassName, String jdbcURL, String userName, String userPassword, int initPoolSize,
int MinPoolSize, int MaxPoolSize, int maxIdleTime, int idleConnectionTestPeriod, String testQuerySQL) {
ds = new ComboPooledDataSource();
// 設置JDBC的Driver類
try {
ds.setDriverClass(driverClassName);
}
catch (PropertyVetoException e) {
throw new RuntimeException(e);
}
// 設置JDBC的URL
ds.setJdbcUrl(jdbcURL);
// 設置數據庫的登錄用戶名
ds.setUser(userName);
// 設置數據庫的登錄用戶密碼
ds.setPassword(userPassword);
// 設置連接池的最大連接數
ds.setMaxPoolSize(MaxPoolSize);
// 設置連接池的最小連接數
ds.setMinPoolSize(MinPoolSize);
// 設置初始化連接數
ds.setInitialPoolSize(initPoolSize);
// 設置最大閑置時間
ds.setMaxIdleTime(maxIdleTime);
// 設置測試SQL
ds.setPreferredTestQuery(testQuerySQL);
// 設置閑置測試周期
ds.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
// 增加單個連接的Statements數量
ds.setMaxStatements(0);
ds.setMaxStatementsPerConnection(200);
}
示例10: DAOFactory
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
protected DAOFactory(String facName, String driverClassName, String jdbcURL, String userName, String userPassword,
int initPoolSize, int MinPoolSize, int MaxPoolSize, int maxIdleTime, int idleConnectionTestPeriod,
String testQuerySQL) {
this.facName = facName;
ds = new ComboPooledDataSource();
// 設置JDBC的Driver類
try {
ds.setDriverClass(driverClassName);
}
catch (PropertyVetoException e) {
throw new RuntimeException(e);
}
// 設置JDBC的URL
ds.setJdbcUrl(jdbcURL);
// 設置數據庫的登錄用戶名
ds.setUser(userName);
// 設置數據庫的登錄用戶密碼
ds.setPassword(userPassword);
// 設置連接池的最大連接數
ds.setMaxPoolSize(MaxPoolSize);
// 設置連接池的最小連接數
ds.setMinPoolSize(MinPoolSize);
// 設置初始化連接數
ds.setInitialPoolSize(initPoolSize);
// 設置最大閑置時間
ds.setMaxIdleTime(maxIdleTime);
// 設置測試SQL
ds.setPreferredTestQuery(testQuerySQL);
// 設置閑置測試周期
ds.setIdleConnectionTestPeriod(idleConnectionTestPeriod);
// 增加單個連接的Statements數量
ds.setMaxStatements(0);
// 連接池內單個連接所擁有的最大緩存statements數
ds.setMaxStatementsPerConnection(200);
// 獲取空閑連接超時時間
ds.setCheckoutTimeout(10 * 1000);
}
示例11: Initialize
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
* Initializes the pool.
*DriverClass - The JDBC driver class.
*JdbcUrl - JDBC connection url.
*User / Password - Connection credentials.
*/
public void Initialize(String DriverClass, String JdbcUrl, String User, String Password) throws PropertyVetoException {
final ComboPooledDataSource pool = new ComboPooledDataSource();
setObject(pool);
pool.setDriverClass(DriverClass);
pool.setJdbcUrl(JdbcUrl);
pool.setUser(User);
pool.setPassword(Password);
pool.setMaxStatements(150);
pool.setMaxIdleTime(1800);
pool.setIdleConnectionTestPeriod(600);
pool.setCheckoutTimeout(20000);
pool.setTestConnectionOnCheckout(true);
}
示例12: createDataSource
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public static ProxyDataSource createDataSource(String driverClass, String jdbcUrl, String user, String password, int maxPoolSize) {
if (StringUtils.isEmpty(driverClass)) {
// System.err.println("驅動程序沒有設置.");
driverClass = "oracle.jdbc.driver.OracleDriver";
}
logger.info("createDataSource jdbcUrl:" + jdbcUrl);
// ComboPooledDataSource dataSource = new ComboPooledDataSource();
ComboPooledDataSource dataSource = new ComboPooledDataSource();
try {
// dataSource.setDriverClass("org.mariadb.jdbc.Driver");
// dataSource.setDriverClass("org.gjt.mm.mysql.Driver");
dataSource.setDriverClass(driverClass);
}
catch (PropertyVetoException e) {
throw new RuntimeException(e.getMessage(), e);
}
dataSource.setJdbcUrl(jdbcUrl);
dataSource.setUser(user);
dataSource.setPassword(password);
dataSource.setTestConnectionOnCheckout(false);
dataSource.setInitialPoolSize(1);
dataSource.setMinPoolSize(1);
dataSource.setMaxPoolSize(maxPoolSize);
dataSource.setAcquireIncrement(1);
dataSource.setAcquireRetryAttempts(1);
dataSource.setMaxIdleTime(7200);
dataSource.setMaxStatements(0);
return new OracleProxyDataSource(dataSource);
}
示例13: start
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
* 使用指定配置文件初始化 C3P0。
*
* @param file
* 配置文件路徑
*/
public void start(String file) {
if (isStarted) {
return;
}
if (file.equals("")) {
file = "dbconfig.properties";
}
init(file);
dataSource = new ComboPooledDataSource();
dataSource.setJdbcUrl(jdbcUrl);
dataSource.setUser(user);
dataSource.setPassword(password);
try {
dataSource.setDriverClass(driverClass);
} catch (PropertyVetoException e) {
dataSource = null;
throw new RuntimeException(e);
}
dataSource.setMaxPoolSize(maxPoolSize);
dataSource.setMinPoolSize(minPoolSize);
dataSource.setInitialPoolSize(initialPoolSize);
dataSource.setMaxIdleTime(maxIdleTime);
dataSource.setAcquireIncrement(acquireIncrement);
isStarted = true;
}
示例14: createDelegate
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
protected DataSource createDelegate() {
final ComboPooledDataSource ds = new ComboPooledDataSource();
try {
ds.setDriverClass(context.getConnectionDriver());
} catch (final PropertyVetoException e1) {
throw Err.process(e1);
}
ds.setJdbcUrl(context.getConnectionUrl());
ds.setUser(context.getConnectionUser());
ds.setPassword(context.getConnectionPassword());
ds.setMaxStatements(5000);
ds.setMaxStatementsPerConnection(50);
ds.setStatementCacheNumDeferredCloseThreads(1); //fix apparent deadlocks
ds.setMaxPoolSize(100);
ds.setMinPoolSize(1);
ds.setMaxIdleTime(new Duration(1, FTimeUnit.MINUTES).intValue(FTimeUnit.SECONDS));
ds.setTestConnectionOnCheckout(true);
ds.setAutoCommitOnClose(true);
Assertions.assertThat(this.closeableDs).isNull();
this.closeableDs = ds;
if (logging) {
try {
final ConnectionPoolDataSourceProxy proxy = new ConnectionPoolDataSourceProxy();
proxy.setTargetDSDirect(ds);
return proxy;
} catch (final JdbcDsLogRuntimeException e) {
throw new RuntimeException(e);
}
} else {
return ds;
}
}
示例15: configure
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public void configure(ComboPooledDataSource ds) {
ds.setMinPoolSize(poolSize);
ds.setInitialPoolSize(poolSize);
ds.setMaxPoolSize(poolSize * 3);
ds.setAcquireIncrement(aquireInc);
ds.setMaxIdleTime(maxIdle);
ds.setMaxConnectionAge(maxAge);
ds.setMaxStatementsPerConnection(maxStmts);
ds.setAcquireRetryAttempts(retry);
ds.setAcquireRetryDelay(retryDelay);
}