本文整理匯總了Java中com.mchange.v2.c3p0.ComboPooledDataSource.setCheckoutTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java ComboPooledDataSource.setCheckoutTimeout方法的具體用法?Java ComboPooledDataSource.setCheckoutTimeout怎麽用?Java ComboPooledDataSource.setCheckoutTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mchange.v2.c3p0.ComboPooledDataSource
的用法示例。
在下文中一共展示了ComboPooledDataSource.setCheckoutTimeout方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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();
}
示例4: 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);
}
示例5: 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);
}
示例6: testPooling
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public void testPooling(CloudSpannerConnection original)
throws SQLException, PropertyVetoException, InterruptedException
{
log.info("Starting connection pooling tests");
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass("nl.topicus.jdbc.CloudSpannerDriver");
cpds.setJdbcUrl(original.getUrl());
cpds.setProperties(original.getSuppliedProperties());
cpds.setInitialPoolSize(5);
cpds.setMinPoolSize(5);
cpds.setAcquireIncrement(5);
cpds.setMaxPoolSize(20);
cpds.setCheckoutTimeout(1000);
log.info("Connection pool created and configured. Acquiring connection from pool");
Assert.assertEquals(0, cpds.getNumBusyConnectionsDefaultUser());
Connection connection = cpds.getConnection();
Assert.assertNotNull(connection);
Assert.assertEquals(1, cpds.getNumBusyConnectionsDefaultUser());
connection.close();
while (cpds.getNumBusyConnections() == 1)
{
Thread.sleep(100l);
}
Assert.assertEquals(0, cpds.getNumBusyConnectionsDefaultUser());
log.info("About to acquire 10 connections");
Connection[] connections = new Connection[10];
for (int i = 0; i < connections.length; i++)
{
connections[i] = cpds.getConnection();
Assert.assertEquals(i + 1, cpds.getNumBusyConnectionsDefaultUser());
}
log.info("10 connections acquired, closing connections...");
for (int i = 0; i < connections.length; i++)
{
connections[i].close();
}
log.info("10 connections closed");
log.info("Acquiring 20 connections");
// Check that we can get 20 connections
connections = new Connection[20];
for (int i = 0; i < connections.length; i++)
{
connections[i] = cpds.getConnection();
connections[i].prepareStatement("SELECT 1").executeQuery();
}
log.info("20 connections acquired, trying to get one more");
// Verify that we can't get a connection now
connection = null;
try
{
connection = cpds.getConnection();
}
catch (SQLException e)
{
// timeout exception
log.info("Exception when trying to get one more connection (this is expected)");
}
log.info("Closing 20 connections");
Assert.assertNull(connection);
for (int i = 0; i < connections.length; i++)
{
connections[i].close();
}
log.info("Closing connection pool");
cpds.close();
log.info("Finished tests");
}
示例7: L2DatabaseFactory
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public L2DatabaseFactory() throws SQLException
{
try
{
if (Config.DATABASE_MAX_CONNECTIONS < 2)
{
Config.DATABASE_MAX_CONNECTIONS = 2;
_log.warning("at least " + Config.DATABASE_MAX_CONNECTIONS + " db connections are required.");
}
_source = new ComboPooledDataSource();
_source.setAutoCommitOnClose(true);
_source.setInitialPoolSize(10);
_source.setMinPoolSize(10);
_source.setMaxPoolSize(Config.DATABASE_MAX_CONNECTIONS);
_source.setAcquireRetryAttempts(0); // try to obtain connections indefinitely (0 = never quit)
_source.setAcquireRetryDelay(500); // 500 miliseconds wait before try to acquire connection again
_source.setCheckoutTimeout(0); // 0 = wait indefinitely for new connection
// if pool is exhausted
_source.setAcquireIncrement(5); // if pool is exhausted, get 5 more connections at a time
// cause there is a "long" delay on acquire connection
// so taking more than one connection at once will make connection pooling
// more effective.
// this "connection_test_table" is automatically created if not already there
_source.setAutomaticTestTable("connection_test_table");
_source.setTestConnectionOnCheckin(false);
// testing OnCheckin used with IdleConnectionTestPeriod is faster than testing on checkout
_source.setIdleConnectionTestPeriod(3600); // test idle connection every 60 sec
_source.setMaxIdleTime(0); // 0 = idle connections never expire
// *THANKS* to connection testing configured above
// but I prefer to disconnect all connections not used
// for more than 1 hour
// enables statement caching, there is a "semi-bug" in c3p0 0.9.0 but in 0.9.0.2 and later it's fixed
_source.setMaxStatementsPerConnection(100);
_source.setBreakAfterAcquireFailure(false); // never fail if any way possible
// setting this to true will make
// c3p0 "crash" and refuse to work
// till restart thus making acquire
// errors "FATAL" ... we don't want that
// it should be possible to recover
_source.setDriverClass(Config.DATABASE_DRIVER);
_source.setJdbcUrl(Config.DATABASE_URL);
_source.setUser(Config.DATABASE_LOGIN);
_source.setPassword(Config.DATABASE_PASSWORD);
/* Test the connection */
_source.getConnection().close();
if (Config.DEBUG) _log.fine("Database Connection Working");
if (Config.DATABASE_DRIVER.toLowerCase().contains("microsoft"))
_providerType = ProviderType.MsSql;
else
_providerType = ProviderType.MySql;
}
catch (SQLException x)
{
if (Config.DEBUG) _log.fine("Database Connection FAILED");
// rethrow the exception
throw x;
}
catch (Exception e)
{
if (Config.DEBUG) _log.fine("Database Connection FAILED");
throw new SQLException("could not init DB connection:"+e);
}
}
示例8: createFromConfig
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
private TransactionAwareDataSource createFromConfig(String instanceName, rapture.common.ConnectionInfo info) throws PropertyVetoException {
String url = PostgresConnectionInfoConfigurer.getUrl(info);
String user = info.getUsername();
validateConfig(url, user);
log.info("Host is " + url);
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDataSourceName(createDataSourceName(instanceName));
dataSource.setDriverClass(DRIVER_CLASS); // loads the jdbc driver
dataSource.setJdbcUrl(url);
dataSource.setUser(user);
dataSource.setCheckoutTimeout(DEFAULT_CHECKOUT_TIMEOUT);
String password = info.getPassword();
if (!StringUtils.isBlank(password)) {
dataSource.setPassword(password);
} else {
throw RaptureExceptionFactory.create("Password cannot be null!");
}
// pool size configuration
dataSource.setInitialPoolSize(getOptionAsInt(info, "initialPoolSize"));
dataSource.setMinPoolSize(getOptionAsInt(info, "minPoolSize"));
dataSource.setMaxPoolSize(getOptionAsInt(info, "maxPoolSize"));
dataSource.setMaxIdleTimeExcessConnections(getOptionAsInt(info, "maxIdleTimeExcessConnections"));
// statement size configuration
dataSource.setMaxStatements(getOptionAsInt(info, "maxStatements"));
dataSource.setStatementCacheNumDeferredCloseThreads(getOptionAsInt(info, "statementCacheNumDeferredCloseThreads"));
// connection testing
dataSource.setIdleConnectionTestPeriod(getOptionAsInt(info, "idleConnectionTestPeriod"));
boolean testConnectionOnCheckin = true;
if(info.getOption("testConnectionOnCheckin") != null) {
testConnectionOnCheckin = (boolean) info.getOption("testConnectionOnCheckin");
}
dataSource.setTestConnectionOnCheckin(testConnectionOnCheckin);
monitor.monitor(dataSource);
try {
Connection connection = DriverManager.getConnection(url, user, password);
connection.close();
} catch (SQLException e) {
throw RaptureExceptionFactory.create(ExceptionToString.format(e));
}
return new TransactionAwareDataSource(dataSource);
}
示例9: constructDbIdService
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
private IdService constructDbIdService(String dbUrl, String dbName,
String dbUser, String dbPassword) {
log.info(
"Construct Db IdService dbUrl {} dbName {} dbUser {} dbPassword {}",
dbUrl, dbName, dbUser, dbPassword);
ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
String jdbcDriver = "com.mysql.jdbc.Driver";
try {
comboPooledDataSource.setDriverClass(jdbcDriver);
} catch (PropertyVetoException e) {
log.error("Wrong JDBC driver {}", jdbcDriver);
log.error("Wrong JDBC driver error: ", e);
throw new IllegalStateException("Wrong JDBC driver ", e);
}
comboPooledDataSource.setMinPoolSize(5);
comboPooledDataSource.setMaxPoolSize(30);
comboPooledDataSource.setIdleConnectionTestPeriod(20);
comboPooledDataSource.setMaxIdleTime(25);
comboPooledDataSource.setBreakAfterAcquireFailure(false);
comboPooledDataSource.setCheckoutTimeout(3000);
comboPooledDataSource.setAcquireRetryAttempts(50);
comboPooledDataSource.setAcquireRetryDelay(1000);
String url = String
.format("jdbc:mysql://%s/%s?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true",
dbUrl, dbName);
comboPooledDataSource.setJdbcUrl(url);
comboPooledDataSource.setUser(dbUser);
comboPooledDataSource.setPassword(dbPassword);
JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setLazyInit(false);
jdbcTemplate.setDataSource(comboPooledDataSource);
DbMachineIdProvider dbMachineIdProvider = new DbMachineIdProvider();
dbMachineIdProvider.setJdbcTemplate(jdbcTemplate);
dbMachineIdProvider.init();
IdServiceImpl idServiceImpl = new IdServiceImpl();
idServiceImpl.setMachineIdProvider(dbMachineIdProvider);
if (genMethod != -1)
idServiceImpl.setGenMethod(genMethod);
if (type != -1)
idServiceImpl.setType(type);
if (version != -1)
idServiceImpl.setVersion(version);
idServiceImpl.init();
return idServiceImpl;
}
示例10: createDataPool
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
protected DataSource createDataPool(PoolConfig conf) {
if (!conf.isValid()) {
throw new RuntimeException("數據庫驅動為空或者數據庫用戶名或者密碼或者連接字符串為空");
}
log.info("db config:{}", conf.toString());
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setJdbcUrl(conf.jdbcUrl);
cpds.setUser(conf.userName);
cpds.setPassword(conf.password);
try {
cpds.setDriverClass(conf.driverClass);
} catch (PropertyVetoException e) {
throw new RuntimeException("數據庫驅動設置失敗");
}
cpds.setPreferredTestQuery("select 1");
cpds.setIdleConnectionTestPeriod(60);
if (conf.initialPoolSize != null && !conf.initialPoolSize.isEmpty()) {
cpds.setInitialPoolSize(Integer.parseInt(conf.initialPoolSize));
}
if (conf.acquireIncrement != null && !conf.acquireIncrement.isEmpty()) {
cpds.setAcquireIncrement(Integer.parseInt(conf.acquireIncrement));
}
if (conf.maxPoolSize != null && !conf.maxPoolSize.isEmpty()) {
cpds.setMaxPoolSize(Integer.parseInt(conf.maxPoolSize));
}
if (conf.minPoolSize != null && !conf.minPoolSize.isEmpty()) {
cpds.setMinPoolSize(Integer.parseInt(conf.minPoolSize));
}
if (conf.checkoutTimeout != null && !conf.checkoutTimeout.isEmpty()) {
cpds.setCheckoutTimeout(Integer.parseInt(conf.checkoutTimeout));
}
if (conf.maxStatements != null && !conf.maxStatements.isEmpty()) {
cpds.setMaxStatements(Integer.parseInt(conf.maxStatements));
}
if (conf.maxStatementsPerConnection != null && !conf.maxStatementsPerConnection.isEmpty()) {
cpds.setMaxStatementsPerConnection(Integer.parseInt(conf.maxStatementsPerConnection));
}
if (conf.maxIdleTime != null && !conf.maxIdleTime.isEmpty()) {
cpds.setMaxIdleTime(Integer.parseInt(conf.maxIdleTime));
}
if (conf.unreturnedConnectionTimeout != null && !conf.unreturnedConnectionTimeout.isEmpty()) {
cpds.setDebugUnreturnedConnectionStackTraces(true);
cpds.setUnreturnedConnectionTimeout(Integer.parseInt(conf.unreturnedConnectionTimeout));
} else {
cpds.setDebugUnreturnedConnectionStackTraces(false);
}
return cpds;
}
示例11: config
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public void config(ComboPooledDataSource ds) {
ds.setJdbcUrl("jdbc:h2:~/test");
ds.setPassword("");// change to your PWD
ds.setCheckoutTimeout(2000);
}
示例12: createDatasource
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
public DataSource createDatasource(DatasourceConfig datasourcecfg)
throws SQLException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
try {
dataSource.setDriverClass(datasourcecfg.getDriverClass());
} catch (PropertyVetoException e) {
throw new SQLException(e);
}
dataSource.setJdbcUrl(datasourcecfg.getJdbcUrl());
dataSource.setUser(datasourcecfg.getUsername());
dataSource.setPassword(datasourcecfg.getPassword());
Map props = datasourcecfg.getPoolPerperties();
int checkoutTimeout = Utils.strToInt((String) props
.get("checkoutTimeout"));
if (checkoutTimeout <= 0) {
checkoutTimeout = 5000;
}
dataSource.setCheckoutTimeout(checkoutTimeout);
int initPoolSize = Utils
.strToInt((String) props.get("initialPoolSize"));
if (initPoolSize > 0) {
dataSource.setInitialPoolSize(initPoolSize);
}
int minpoolsize = Utils.strToInt((String) props.get("minPoolSize"));
if (minpoolsize <= 0) {
minpoolsize = 5;
}
dataSource.setMinPoolSize(minpoolsize);
int maxpoolsize = Utils.strToInt((String) props.get("maxPoolSize"));
if (maxpoolsize <= 0) {
maxpoolsize = 100;
}
dataSource.setMaxPoolSize(maxpoolsize);
int acqInc = Utils.strToInt((String) props.get("acquireIncrement"));
if (acqInc <= 0) {
acqInc = 5;
}
dataSource.setAcquireIncrement(acqInc);
int maxIdleTime = Utils.strToInt((String) props.get("maxIdleTime"));
if (maxIdleTime > 0) {
dataSource.setMaxIdleTime(maxIdleTime);
}
int idleConTestPeriod = Utils.strToInt((String) props
.get("idleConnectionTestPeriod"));
if (idleConTestPeriod > 0) {
dataSource.setIdleConnectionTestPeriod(idleConTestPeriod);
}
int acqRetryAttempts = Utils.strToInt((String) props
.get("acquireRetryAttempts"));
if (acqRetryAttempts <= 0) {
acqRetryAttempts = 10;
}
dataSource.setAcquireRetryAttempts(acqRetryAttempts);
int acqRetryDelay = Utils.strToInt((String) props
.get("acquireRetryDelay"));
if (acqRetryDelay <= 0) {
acqRetryDelay = 500;
}
dataSource.setAcquireRetryDelay(acqRetryDelay);
return dataSource;
}
示例13: createC3p0DataSource
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
private static javax.sql.DataSource createC3p0DataSource(
DatasourceConfig datasourcecfg) throws SQLException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
try {
dataSource.setDriverClass(datasourcecfg.getDriverClass());
} catch (PropertyVetoException e) {
throw new SQLException(e);
}
dataSource.setJdbcUrl(datasourcecfg.getJdbcUrl());
dataSource.setUser(datasourcecfg.getUsername());
dataSource.setPassword(datasourcecfg.getPassword());
Map props = datasourcecfg.getPoolPerperties();
int checkoutTimeout = Utils.strToInt((String) props
.get("checkoutTimeout"));
if (checkoutTimeout <= 0) {
checkoutTimeout = 5000;
}
dataSource.setCheckoutTimeout(checkoutTimeout);
int initPoolSize = Utils
.strToInt((String) props.get("initialPoolSize"));
if (initPoolSize > 0) {
dataSource.setInitialPoolSize(initPoolSize);
}
int minpoolsize = Utils.strToInt((String) props.get("minPoolSize"));
if (minpoolsize <= 0) {
minpoolsize = 5;
}
dataSource.setMinPoolSize(minpoolsize);
int maxpoolsize = Utils.strToInt((String) props.get("maxPoolSize"));
if (maxpoolsize <= 0) {
maxpoolsize = 100;
}
dataSource.setMaxPoolSize(maxpoolsize);
int acqInc = Utils.strToInt((String) props.get("acquireIncrement"));
if (acqInc <= 0) {
acqInc = 5;
}
dataSource.setAcquireIncrement(acqInc);
int maxIdleTime = Utils.strToInt((String) props.get("maxIdleTime"));
if (maxIdleTime > 0) {
dataSource.setMaxIdleTime(maxIdleTime);
}
int idleConTestPeriod = Utils.strToInt((String) props
.get("idleConnectionTestPeriod"));
if (idleConTestPeriod > 0) {
dataSource.setIdleConnectionTestPeriod(idleConTestPeriod);
}
int acqRetryAttempts = Utils.strToInt((String) props
.get("acquireRetryAttempts"));
if (acqRetryAttempts <= 0) {
acqRetryAttempts = 10;
}
dataSource.setAcquireRetryAttempts(acqRetryAttempts);
int acqRetryDelay = Utils.strToInt((String) props
.get("acquireRetryDelay"));
if (acqRetryDelay <= 0) {
acqRetryDelay = 500;
}
dataSource.setAcquireRetryDelay(acqRetryDelay);
return dataSource;
}
示例14: createDataSource
import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
* Creates {@link DataSource} based on {@link CConnection} properties.
*
* NOTE: this method never throws exception but just logs it.
*
* @param connection
* @return {@link DataSource} or <code>null</code> if it cannot be created
*/
private ComboPooledDataSource createDataSource(final CConnection connection)
{
try
{
System.setProperty("com.mchange.v2.log.MLog", com.mchange.v2.log.slf4j.Slf4jMLog.class.getName());
// System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "ALL");
final ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDataSourceName("AdempiereDS");
cpds.setDriverClass(DRIVER);
// loads the jdbc driver
cpds.setJdbcUrl(getConnectionURL(connection));
cpds.setUser(connection.getDbUid());
cpds.setPassword(connection.getDbPwd());
cpds.setPreferredTestQuery(DEFAULT_CONN_TEST_SQL);
cpds.setIdleConnectionTestPeriod(1200);
// cpds.setTestConnectionOnCheckin(true);
// cpds.setTestConnectionOnCheckout(true);
cpds.setAcquireRetryAttempts(2);
// Set checkout timeout to avoid forever locking when trying to connect to a not existing host.
cpds.setCheckoutTimeout(SystemUtils.getSystemProperty(CONFIG_CheckoutTimeout, 20 * 1000));
if (Ini.isClient())
{
cpds.setInitialPoolSize(1);
cpds.setMinPoolSize(1);
cpds.setMaxPoolSize(20);
cpds.setMaxIdleTimeExcessConnections(1200);
cpds.setMaxIdleTime(900);
m_maxbusyconnectionsThreshold = 15;
}
else
{
cpds.setInitialPoolSize(10);
cpds.setMinPoolSize(5);
cpds.setMaxPoolSize(150);
cpds.setMaxIdleTimeExcessConnections(1200);
cpds.setMaxIdleTime(1200);
m_maxbusyconnectionsThreshold = 120;
}
// the following sometimes kill active connection!
// cpds.setUnreturnedConnectionTimeout(1200);
// cpds.setDebugUnreturnedConnectionStackTraces(true);
// 04006: add a customizer to set the log level for message that are send to the client
// background: if there are too many messages sent (e.g. from a verbose and long-running DB function)
// then the whole JVM might suffer an OutOfMemoryError
cpds.setConnectionCustomizerClassName(DB_PostgreSQL_ConnectionCustomizer.class.getName());
return cpds;
}
catch (Exception ex)
{
throw new DBNoConnectionException("Could not initialise C3P0 Datasource", ex);
}
}