當前位置: 首頁>>代碼示例>>Java>>正文


Java ComboPooledDataSource.setMaxIdleTimeExcessConnections方法代碼示例

本文整理匯總了Java中com.mchange.v2.c3p0.ComboPooledDataSource.setMaxIdleTimeExcessConnections方法的典型用法代碼示例。如果您正苦於以下問題:Java ComboPooledDataSource.setMaxIdleTimeExcessConnections方法的具體用法?Java ComboPooledDataSource.setMaxIdleTimeExcessConnections怎麽用?Java ComboPooledDataSource.setMaxIdleTimeExcessConnections使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mchange.v2.c3p0.ComboPooledDataSource的用法示例。


在下文中一共展示了ComboPooledDataSource.setMaxIdleTimeExcessConnections方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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();
}
 
開發者ID:apache,項目名稱:lens,代碼行數:26,代碼來源:DataSourceConnectionProvider.java

示例2: createAdminDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
 *
 *
 */
public boolean createAdminDataSource() throws Exception {
  String dbHost = "", dbUser = "", dbPass = "", dbPort = "", url = "";
  try {
    dbHost = this.config.getProp(MAIN_CONFIG, MASTER_DBHOST);
    dbUser = this.config.getProp(MAIN_CONFIG, MASTER_DBUSER);
    dbPass = this.config.getProp(MAIN_CONFIG, MASTER_DBPASS);
    dbPort = this.config.getProp(MAIN_CONFIG, MASTER_DBPORT);
    url = url + URL_PREFIX + dbHost + ":" + dbPort + "?" + DRIVER_PARAMETERS;

    newAdminDataSource = new ComboPooledDataSource();
    newAdminDataSource.setDriverClass(DRIVER); // loads the mariadb-jdbc driver
    newAdminDataSource.setJdbcUrl(url);
    newAdminDataSource.setUser(dbUser);

    if (dbPass != null && !dbPass.isEmpty()) {
      newAdminDataSource.setPassword(dbPass);
    }

    // the settings below are optional -- c3p0 can work with defaults
    newAdminDataSource.setMinPoolSize(0);
    newAdminDataSource.setInitialPoolSize(0);
    newAdminDataSource.setAcquireIncrement(5);
    newAdminDataSource.setMaxPoolSize(20);

    newAdminDataSource.setMaxIdleTimeExcessConnections(80);
    newAdminDataSource.setMaxIdleTime(120);
    newAdminDataSource.setUnreturnedConnectionTimeout(160);

  } catch (Exception e) {
    LOGGER.error("CAN NOT CREATE ADMIN DATA SOURCE", e);
  }
  return true;
}
 
開發者ID:UniversityOfWuerzburg-ChairCompSciVI,項目名稱:ueps,代碼行數:38,代碼來源:ConnectionManager.java

示例3: 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);
    }
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:50,代碼來源:ConnectionCacheLoader.java

示例4: 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);
	}
}
 
開發者ID:metasfresh,項目名稱:metasfresh,代碼行數:66,代碼來源:DB_PostgreSQL.java


注:本文中的com.mchange.v2.c3p0.ComboPooledDataSource.setMaxIdleTimeExcessConnections方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。