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


Java ComboPooledDataSource.setIdleConnectionTestPeriod方法代碼示例

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


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

示例1: pooled

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
private static PooledDataSource pooled(String hostname, int port, String username, String password, String database, String driver, int maxPoolsize) {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    dataSource.setJdbcUrl(format("jdbc:mysql://%s:%d/%s?rewriteBatchedStatements=true",
            hostname,
            port,
            database));
    dataSource.setUser(username);
    dataSource.setPassword(password);
    dataSource.setIdleConnectionTestPeriod(60 * 5);
    dataSource.setMinPoolSize(3);
    dataSource.setInitialPoolSize(3);
    dataSource.setAcquireIncrement(1);
    dataSource.setMaxPoolSize(maxPoolsize);

    try {
        Class.forName(driver);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    return dataSource;
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:22,代碼來源:StacksConfiguredDataSource.java

示例2: createC3P0DataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
private DataSource createC3P0DataSource() throws PropertyVetoException {
    ComboPooledDataSource ds = new ComboPooledDataSource();
    ds.setDriverClass(configuration.getDriverClassName());
    ds.setJdbcUrl(configuration.getJdbcUrl());
    ds.setUser(configuration.getJdbcUsername());
    ds.setPassword(configuration.getJdbcPassword());

    ds.setAcquireIncrement(3);
    ds.setMinPoolSize(configuration.getMinPoolSize());
    ds.setMaxPoolSize(configuration.getMaxPoolSize());
    ds.setIdleConnectionTestPeriod(1800);
    ds.setConnectionTesterClassName(MidPointConnectionTester.class.getName());
    ds.setConnectionCustomizerClassName(MidPointConnectionCustomizer.class.getName());

    return ds;
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:17,代碼來源:DataSourceFactory.java

示例3: getSpecificDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@ConfigurationProperties(prefix="system.datasource")
private DataSource getSpecificDataSource(String dbname) {
	try {
		System.out.println("CONNECTING TO DB ---------------> " + dbname.replaceAll("discoursedb_ext", ""));

		ComboPooledDataSource ds = new ComboPooledDataSource();
		ds.setDriverClass(environment.getRequiredProperty("jdbc.driverClassName"));
		String host = environment.getRequiredProperty("jdbc.host");
		String port = environment.getRequiredProperty("jdbc.port");
		String database = "discoursedb_ext_" + dbname.replaceAll("discoursedb_ext_", "");
		ds.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + database+ "?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&useSSL=false");
		ds.setUser(environment.getRequiredProperty("jdbc.username"));
		ds.setPassword(environment.getRequiredProperty("jdbc.password"));
		ds.setAcquireIncrement(Integer.parseInt(environment.getRequiredProperty("c3p0.acquireIncrement").trim()));
		ds.setIdleConnectionTestPeriod(
				Integer.parseInt(environment.getRequiredProperty("c3p0.idleConnectionTestPeriod").trim()));
		ds.setMaxStatements(Integer.parseInt(environment.getRequiredProperty("c3p0.maxStatements").trim()));
		ds.setMinPoolSize(Integer.parseInt(environment.getRequiredProperty("c3p0.minPoolSize").trim()));
		ds.setMaxPoolSize(Integer.parseInt(environment.getRequiredProperty("c3p0.maxPoolSize").trim()));
		return ds;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:DiscourseDB,項目名稱:discoursedb-core,代碼行數:25,代碼來源:DatabaseSelector.java

示例4: systemDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Bean(name = "systemDataSource")
   @ConfigurationProperties(prefix="system.datasource")
  public DataSource systemDataSource() {
	try {
		ComboPooledDataSource ds = new ComboPooledDataSource();
		ds.setDriverClass(environment.getRequiredProperty("jdbc.driverClassName"));
		String host = environment.getRequiredProperty("jdbc.host");
		String port = environment.getRequiredProperty("jdbc.port");
		String database = environment.getRequiredProperty("jdbc.system_database").replaceAll("discoursedb_ext_", "");
		ds.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/discoursedb_ext_" + database+ "?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&useSSL=false");
		ds.setUser(environment.getRequiredProperty("jdbc.username"));
		ds.setPassword(environment.getRequiredProperty("jdbc.password"));
		ds.setAcquireIncrement(Integer.parseInt(environment.getRequiredProperty("c3p0.acquireIncrement").trim()));
		ds.setIdleConnectionTestPeriod(
				Integer.parseInt(environment.getRequiredProperty("c3p0.idleConnectionTestPeriod").trim()));
		ds.setMaxStatements(Integer.parseInt(environment.getRequiredProperty("c3p0.maxStatements").trim()));
		ds.setMinPoolSize(Integer.parseInt(environment.getRequiredProperty("c3p0.minPoolSize").trim()));
		ds.setMaxPoolSize(Integer.parseInt(environment.getRequiredProperty("c3p0.maxPoolSize").trim()));
		return ds;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:DiscourseDB,項目名稱:discoursedb-core,代碼行數:24,代碼來源:SystemDbConfiguration.java

示例5: h2DataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
 * @return the h2 database data source
 */
@Bean
public DataSource h2DataSource() {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();

    try {
        dataSource.setDriverClass("org.h2.Driver");
    } catch (PropertyVetoException e) {
        e.printStackTrace();
    }
    dataSource.setJdbcUrl("jdbc:h2:mem:bootstrap;mode=mysql;INIT=runscript from 'classpath:sql/bootstrap.h2.sql'\\;" +
            "runscript from 'classpath:sql/bootstrap.insert.sql'");
    dataSource.setUser("sa");
    dataSource.setPassword("");
    dataSource.setAcquireIncrement(10);
    dataSource.setIdleConnectionTestPeriod(60);
    dataSource.setMaxPoolSize(30);
    dataSource.setMinPoolSize(3);
    dataSource.setInitialPoolSize(5);
    dataSource.setMaxStatements(10);

    return dataSource;
}
 
開發者ID:nobodyiam,項目名稱:java-web-bootstrap,代碼行數:26,代碼來源:DataConfig.java

示例6: mysqlDataSource

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
/**
 * @return the mysql data source
 */
@Bean
public DataSource mysqlDataSource() {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    try {
        dataSource.setDriverClass("com.mysql.jdbc.Driver");
    } catch (PropertyVetoException e) {
        return null;
    }
    dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/bootstrap");
    dataSource.setUser("bootstrap");
    dataSource.setPassword("bootstrap");
    dataSource.setAcquireIncrement(50);
    dataSource.setIdleConnectionTestPeriod(60);
    dataSource.setMaxPoolSize(50);
    dataSource.setMinPoolSize(10);
    dataSource.setInitialPoolSize(20);
    dataSource.setMaxStatements(50);

    return dataSource;
}
 
開發者ID:nobodyiam,項目名稱:java-web-bootstrap,代碼行數:24,代碼來源:DataConfig.java

示例7: 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;
}
 
開發者ID:hekailiang,項目名稱:cloud-config,代碼行數:19,代碼來源:C3P0DataSourceFactoryBean.java

示例8: createConnection

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
private ComboPooledDataSource createConnection() {
	try {
		ComboPooledDataSource cpds = new ComboPooledDataSource();
		cpds.setDriverClass("com.mysql.jdbc.Driver");
		cpds.setJdbcUrl("jdbc:mysql://" + MYSQL_DATA.HOST + ":" + MYSQL_DATA.PORT + "/" + MYSQL_DATA.DATABASE);
		cpds.setProperties(connectionProperties);
		cpds.setInitialPoolSize(POOL_DATA.INITIAL_POOL_SIZE);
		cpds.setMinPoolSize(POOL_DATA.MIN_POOL_SIZE);
		cpds.setMaxPoolSize(POOL_DATA.MAX_POOL_SIZE);
		cpds.setTestConnectionOnCheckin(POOL_DATA.TEST_CONNECTION_ON_CHECKIN);
		cpds.setIdleConnectionTestPeriod(POOL_DATA.IDLE_CONNECTION_TEST_PERIOD);
		return cpds;
	} catch (PropertyVetoException e) {
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:Simonsator,項目名稱:BungeecordPartyAndFriends,代碼行數:18,代碼來源:PoolSQLCommunication.java

示例9: 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;
}
 
開發者ID:leopardoooo,項目名稱:cambodia,代碼行數:27,代碼來源:ConnContainer.java

示例10: 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);
    }
}
 
開發者ID:xianrendzw,項目名稱:EasyReport,代碼行數:27,代碼來源:C3p0DataSourcePool.java

示例11: 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);

}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:36,代碼來源:DAOFactory.java

示例12: 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);
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:40,代碼來源:DAOFactory.java

示例13: 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);
}
 
開發者ID:AnywhereSoftware,項目名稱:B4J_Server,代碼行數:20,代碼來源:ConnectionPool.java

示例14: init

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public void init(String configurationName, Map<String, String> properties) {
    this.configurationName = configurationName;
    this.properties = new HashMap<>(properties);

    String connectionKey = getConnectionKey();

    try {
        String driver = property("driver");

        String userName = property("user");
        String password = property("pass");

        cpds = new ComboPooledDataSource();
        cpds.setDriverClass(driver);
        cpds.setJdbcUrl(getJdbcUrl());
        cpds.setUser(userName);
        cpds.setPassword(password);

        int minPoolSize = Integer.parseInt(property("pool_min_size"));
        int aquireIncrement = Integer.parseInt(property("pool_increment_by"));
        int maxPoolSize = Integer.parseInt(property("pool_max_size"));

        cpds.setMinPoolSize(minPoolSize);
        cpds.setAcquireIncrement(aquireIncrement);
        cpds.setMaxPoolSize(maxPoolSize);
        cpds.setIdleConnectionTestPeriod(300);
        cpds.setPreferredTestQuery("SELECT 1");
        cpds.setTestConnectionOnCheckin(false);
        cpds.setTestConnectionOnCheckout(false);
    } catch (Throwable t) {
        throw new RuntimeException("Unable to establich SQL connection for JDBC-key: " + connectionKey, t);
    }
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:35,代碼來源:MySqlDatabaseConnection.java

示例15: start

import com.mchange.v2.c3p0.ComboPooledDataSource; //導入方法依賴的package包/類
@Override
public void start() {
    cpds = new ComboPooledDataSource();
    cpds.setJdbcUrl(getServerURL());
    cpds.setUser(getUsername());
    cpds.setPassword(getPassword());
    cpds.setMinPoolSize(getMinConnections());
    cpds.setMaxPoolSize(getMaxConnections());
    cpds.setIdleConnectionTestPeriod(getIdleTestInterval());
    cpds.setTestConnectionOnCheckout(getTestBeforeUse());
    cpds.setTestConnectionOnCheckin(getTestAfterUse());
    cpds.setPreferredTestQuery(getTestSQL());
    cpds.setMaxConnectionAge(getConnectionTimeout());
}
 
開發者ID:MoneyBeets,項目名稱:Narvaro,代碼行數:15,代碼來源:AbstractConnectionProvider.java


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