Java Code Examples for com.mchange.v2.c3p0.ComboPooledDataSource#setAcquireRetryDelay()
The following examples show how to use
com.mchange.v2.c3p0.ComboPooledDataSource#setAcquireRetryDelay() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlConnectionPool.java From mxisd with GNU Affero General Public License v3.0 | 5 votes |
public SqlConnectionPool(SqlConfig cfg) { Drivers.load(cfg.getType()); ds = new ComboPooledDataSource(); ds.setJdbcUrl("jdbc:" + cfg.getType() + ":" + cfg.getConnection()); ds.setMinPoolSize(1); ds.setMaxPoolSize(10); ds.setAcquireIncrement(2); ds.setAcquireRetryAttempts(10); ds.setAcquireRetryDelay(1000); }
Example 2
Source File: DataSourceUtils.java From hasor with Apache License 2.0 | 5 votes |
public static DataSource loadDB(String dbID, Settings settings) throws Throwable { // 1.获取数据库连接配置信息 String driverString = settings.getString(dbID + ".driver"); String urlString = settings.getString(dbID + ".url"); String userString = settings.getString(dbID + ".user"); String pwdString = settings.getString(dbID + ".password"); // 2.创建数据库连接池 int poolMaxSize = 40; logger.info("C3p0 Pool Info maxSize is ‘%s’ driver is ‘%s’ jdbcUrl is‘%s’", poolMaxSize, driverString, urlString); ComboPooledDataSource dataSource = new ComboPooledDataSource(); dataSource.setDriverClass(driverString); dataSource.setJdbcUrl(urlString); dataSource.setUser(userString); dataSource.setPassword(pwdString); dataSource.setMaxPoolSize(poolMaxSize); dataSource.setInitialPoolSize(1); // dataSource.setAutomaticTestTable("DB_TEST_ATest001"); dataSource.setIdleConnectionTestPeriod(18000); dataSource.setCheckoutTimeout(3000); dataSource.setTestConnectionOnCheckin(true); dataSource.setAcquireRetryDelay(1000); dataSource.setAcquireRetryAttempts(30); dataSource.setAcquireIncrement(1); dataSource.setMaxIdleTime(25000); // 3.启用默认事务拦截器 return dataSource; }
Example 3
Source File: IdServiceFactoryBean.java From vesta-id-generator with Apache License 2.0 | 4 votes |
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; }
Example 4
Source File: L2DatabaseFactory.java From L2jBrasil with GNU General Public License v3.0 | 4 votes |
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); } }
Example 5
Source File: C3P0DataSourceProvider.java From vertx-jdbc-client with Apache License 2.0 | 4 votes |
@Override public DataSource getDataSource(JsonObject config) throws SQLException { String url = config.getString("url"); if (url == null) throw new NullPointerException("url cannot be null"); String driverClass = config.getString("driver_class"); String user = config.getString("user"); String password = config.getString("password"); Integer maxPoolSize = config.getInteger("max_pool_size"); Integer initialPoolSize = config.getInteger("initial_pool_size"); Integer minPoolSize = config.getInteger("min_pool_size"); Integer maxStatements = config.getInteger("max_statements"); Integer maxStatementsPerConnection = config.getInteger("max_statements_per_connection"); Integer maxIdleTime = config.getInteger("max_idle_time"); Integer acquireRetryAttempts = config.getInteger("acquire_retry_attempts"); Integer acquireRetryDelay = config.getInteger("acquire_retry_delay"); Boolean breakAfterAcquireFailure = config.getBoolean("break_after_acquire_failure"); // If you want to configure any other C3P0 properties you can add a file c3p0.properties to the classpath ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setJdbcUrl(url); if (driverClass != null) { try { cpds.setDriverClass(driverClass); } catch (PropertyVetoException e) { throw new IllegalArgumentException(e); } } if (user != null) { cpds.setUser(user); } if (password != null) { cpds.setPassword(password); } if (maxPoolSize != null) { cpds.setMaxPoolSize(maxPoolSize); } if (minPoolSize != null) { cpds.setMinPoolSize(minPoolSize); } if (initialPoolSize != null) { cpds.setInitialPoolSize(initialPoolSize); } if (maxStatements != null) { cpds.setMaxStatements(maxStatements); } if (maxStatementsPerConnection != null) { cpds.setMaxStatementsPerConnection(maxStatementsPerConnection); } if (maxIdleTime != null) { cpds.setMaxIdleTime(maxIdleTime); } if(acquireRetryAttempts != null){ cpds.setAcquireRetryAttempts(acquireRetryAttempts); } if(acquireRetryDelay != null){ cpds.setAcquireRetryDelay(acquireRetryDelay); } if(breakAfterAcquireFailure != null){ cpds.setBreakAfterAcquireFailure(breakAfterAcquireFailure); } return cpds; }