当前位置: 首页>>代码示例>>Java>>正文


Java HikariConfig.setIdleTimeout方法代码示例

本文整理汇总了Java中com.zaxxer.hikari.HikariConfig.setIdleTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java HikariConfig.setIdleTimeout方法的具体用法?Java HikariConfig.setIdleTimeout怎么用?Java HikariConfig.setIdleTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.zaxxer.hikari.HikariConfig的用法示例。


在下文中一共展示了HikariConfig.setIdleTimeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hikariConfig

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
public HikariConfig hikariConfig() {
    log.info("Creating HikariConfig with:\n* username: {}\n* jdbcUrl: {}", databaseProperties.getUsername(), databaseProperties.getUrl());

    HikariConfig config = new HikariConfig();
    config.setDriverClassName(databaseProperties.getDriverClassName());
    config.setJdbcUrl(databaseProperties.getUrl());
    config.setUsername(databaseProperties.getUsername());
    config.setPassword(databaseProperties.getPassword());
    config.setMaximumPoolSize(databaseProperties.getMaximumPoolSize());
    config.setIdleTimeout(databaseProperties.getIdleTimeout());
    config.setConnectionTestQuery(databaseProperties.getConnectionTestQuery());
    config.setPoolName(databaseProperties.getPoolName());
    config.setMetricsTrackerFactory(prometheusMetricsTrackerFactory());

    config.setDataSourceProperties(dataSourceProperties());

    return config;
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:20,代码来源:DatabaseConfig.java

示例2: enableDatabaseSQLiteTest

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Test
public void enableDatabaseSQLiteTest() {
    try {
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("org.sqlite.JDBC");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:sqlite:PetBlocks.db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assert.fail();
    }
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:18,代码来源:DatabaseIT.java

示例3: enableDatabaseMySQLTest

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Test
public void enableDatabaseMySQLTest() {
    try {
        final DB database = DB.newEmbeddedDB(3306);
        database.start();
        try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
            try (Statement statement = conn.createStatement()) {
                statement.executeUpdate("CREATE DATABASE db");
            }
        }
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("com.mysql.jdbc.Driver");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
        database.stop();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assert.fail();
    }
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:26,代码来源:DatabaseIT.java

示例4: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
public DataSource dataSource() {
    logger.debug("Configuring Datasource");
    String databaseUrl = String.format("jdbc:mysql://%s:%s/%s?%s",
            databaseHostname, databasePort, databaseSchema, databaseOptions);
    logger.info("database.url:" + databaseUrl);
    logger.info("database.user:" + databaseUser);
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
    config.addDataSourceProperty("url", databaseUrl);
    config.addDataSourceProperty("user", databaseUser);
    config.setInitializationFailFast(false);
    config.setIdleTimeout(60000);
    String forcePassword = System.getenv("MYSQL_ROOT_PASSWORD");
    // coming from environnment host
    if (forcePassword != null) {
        logger.info("Force the mysql password from host env");
        databasePassword = forcePassword;
    }
    logger.info("URL : " + databaseUrl + " password : " + databasePassword);
    config.addDataSourceProperty("password", databasePassword);
    return new HikariDataSource(config);
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:24,代码来源:DatabaseConfiguration.java

示例5: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
public DataSource dataSource() {
    HikariConfig dataSourceConfig = new HikariConfig();
    dataSourceConfig.setDriverClassName(environment.getRequiredProperty("spring.datasource.driver-class-name"));
    dataSourceConfig.setJdbcUrl(environment.getRequiredProperty("spring.datasource.url"));
    dataSourceConfig.setUsername(environment.getRequiredProperty("spring.datasource.username"));
    dataSourceConfig.setPassword(environment.getRequiredProperty("spring.datasource.password"));
    dataSourceConfig.setMaximumPoolSize(Integer.parseInt(environment.getRequiredProperty("spring.datasource.maximumPoolSize")));
    dataSourceConfig.setMinimumIdle(Integer.parseInt(environment.getRequiredProperty("spring.datasource.minimumIdle")));
    dataSourceConfig.setMaxLifetime(Integer.parseInt(environment.getRequiredProperty("spring.datasource.maxLifetime")));
    dataSourceConfig.setConnectionTimeout(Long.parseLong(environment.getRequiredProperty("spring.datasource.connectionTimeout")));
    dataSourceConfig.setIdleTimeout(Long.parseLong(environment.getRequiredProperty("spring.datasource.idleTimeout")));
    dataSourceConfig.addDataSourceProperty("poolName", environment.getRequiredProperty("spring.datasource.poolName"));
    dataSourceConfig.addDataSourceProperty("cachePrepStmts", "true");
    dataSourceConfig.addDataSourceProperty("prepStmtCacheSize", "250");
    dataSourceConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    return new HikariDataSource(dataSourceConfig);
}
 
开发者ID:RizkiMufrizal,项目名称:Spring-OAuth2-Custom,代码行数:19,代码来源:DataSourceConfiguration.java

示例6: enableDatabaseSQLiteTest

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Test
public void enableDatabaseSQLiteTest() {
    try {
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("org.sqlite.JDBC");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:sqlite:PetBlocks.db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assertions.fail(ex);
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:18,代码来源:DatabaseTest.java

示例7: enableDatabaseMySQLTest

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Test
public void enableDatabaseMySQLTest() {
    try {
        final DB database = DB.newEmbeddedDB(3306);
        database.start();
        try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
            try (Statement statement = conn.createStatement()) {
                statement.executeUpdate("CREATE DATABASE db");
            }
        }

        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("com.mysql.jdbc.Driver");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
        database.stop();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assertions.fail(ex);
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:27,代码来源:DatabaseTest.java

示例8: setup

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
protected void setup(Jecon jecon, HikariConfig hikariConfig) {
	this.jecon = jecon;
	if (config == null) {
		config = jecon.getConfigStruct();
	}
	this.prefix = config.getDbConfig().prefix;

	hikariConfig.setJdbcUrl(config.getDbConfig().url);
	hikariConfig.setInitializationFailFast(true);
	hikariConfig.setAutoCommit(true);
	hikariConfig.setConnectionInitSql("/* Jecon */SELECT 1");

	if (config.getDbConfig().poolSize > 0) {
		hikariConfig.setMaximumPoolSize(config.getDbConfig().poolSize);
	}
	if (config.getDbConfig().timeout > 0) {
		hikariConfig.setIdleTimeout(config.getDbConfig().timeout);
	}

	hikariConfig.setDataSourceProperties(config.getDbConfig().propaties);

	// HikariDataSourceをインスタンス化
	this.hikariDc = new HikariDataSource(hikariConfig);

	this.createTable();
}
 
开发者ID:HimaJyun,项目名称:Jecon,代码行数:27,代码来源:Database.java

示例9: initConnection

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private void initConnection() throws Exception {
	HikariConfig config = new HikariConfig();
	config.setPoolName("Parties");
	config.setJdbcUrl(Variables.storage_settings_mysql_url);
	config.setUsername(Variables.storage_settings_mysql_username);
	config.setPassword(Variables.storage_settings_mysql_password);
	config.setMaximumPoolSize(Variables.storage_settings_mysql_poolsize);
	config.setMinimumIdle(Variables.storage_settings_mysql_poolsize);
	config.setMaxLifetime(Variables.storage_settings_mysql_connlifetime);
	config.setIdleTimeout(Variables.storage_settings_mysql_conntimeout);
	
	// Properties: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html
	config.addDataSourceProperty("cachePreStmts", "true"); // Enable Prepared Statement caching
	config.addDataSourceProperty("prepStmtCacheSize", "25"); // How many PS cache, default: 25
	config.addDataSourceProperty("useServerPrepStmts", "true"); // If supported use PS server-side
	config.addDataSourceProperty("useLocalSessionState", "true"); // Enable setAutoCommit
	config.addDataSourceProperty("useLocalTransactionState", "true"); // Enable commit/rollbacks
	
	hikariDataSource = new HikariDataSource(config);
}
 
开发者ID:AlessioDP,项目名称:Parties,代码行数:21,代码来源:MySQLData.java

示例10: HikariCpImpl

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public HikariCpImpl() {
    Properties properties = new Properties();
    properties.setProperty("dataSourceClassName", "com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
    properties.setProperty("dataSource.serverName", "127.0.0.1");
    properties.setProperty("dataSource.portNumber", "3306");
    properties.setProperty("dataSource.databaseName", "study");
    properties.setProperty("dataSource.user", "root");
    properties.setProperty("dataSource.password", "zhilaiadmin");
    properties.setProperty("dataSource.encoding", "UTF-8");
    properties.setProperty("maximumPoolSize", "100");
    HikariConfig config = new HikariConfig(properties);
    config.setConnectionTimeout(30 * 1000);
    config.setIdleTimeout(60 * 1000);
    config.setMaxLifetime(60 * 1000);
    config.setMinimumIdle(50);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "1000");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    ds = new HikariDataSource(config);
}
 
开发者ID:amao12580,项目名称:JOOQ,代码行数:21,代码来源:HikariCpImpl.java

示例11: start

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public void start() {
	HikariConfig config = new HikariConfig();
	config.setJdbcUrl(this.conURL);
	config.setUsername(this.username);
	config.setPassword(this.password);
	config.setDriverClassName(this.driverName);
	config.setMaximumPoolSize(max);
	config.setMinimumIdle(min);
	if (this.testSql != null && this.testSql.trim().length() > 0) {
		config.setConnectionTestQuery(testSql);
	}
	config.setPoolName("HikariCPPool[" + username + "]");
	config.addDataSourceProperty("cachePrepStmts", AppProperties.get("HikariCPPool_cachePrepStmts", "true"));
	config.addDataSourceProperty("prepStmtCacheSize", AppProperties.get("HikariCPPool_prepStmtCacheSize", "250"));
	config.addDataSourceProperty("prepStmtCacheSqlLimit",
			AppProperties.get("HikariCPPool_prepStmtCacheSqlLimit", "2048"));
	config.setConnectionTimeout(AppProperties.getAsInt("HikariCPPool_connectionTimeout", 30000));
	config.setIdleTimeout(AppProperties.getAsInt("HikariCPPool_idleTimeout", 600000));
	config.setMaxLifetime(AppProperties.getAsInt("HikariCPPool_maxLifetime", 1800000));
	// HikariDataSource ds = new HikariDataSource(config);
	// this.datasource=ds.getDataSource();
	this.datasource = new HikariDataSource(config);
}
 
开发者ID:jbeetle,项目名称:BJAF3.x,代码行数:25,代码来源:HikariCPPool.java

示例12: Database

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public Database(Logger log, String user, String pass, String host, int port, String db,
		int poolSize, long connectionTimeout, long idleTimeout, long maxLife) {
	if(user != null && host != null && port > 0 && db != null) {
		HikariConfig config = new HikariConfig();
		config.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + db);
		config.setConnectionTimeout(connectionTimeout);
		config.setIdleTimeout(idleTimeout);
		config.setMaxLifetime(maxLife);
		config.setMaximumPoolSize(poolSize);
		config.setUsername(user);
		if(pass != null) {
			config.setPassword(pass);
		}
		datasource = new HikariDataSource(config);
		
		try {
			Connection conn = getConnection();
			PreparedStatement statement = conn.prepareStatement(INIT_DATABASE);
			statement.execute();
			statement.close();
			conn.close();
		} catch (SQLException e) {
			log.log(Level.SEVERE, "Unable to initialize database", e);
			datasource = null;
		}
	} else {
		datasource = null;
		log.log(Level.SEVERE, "Database not configured and is unavailable");
	}
}
 
开发者ID:CivClassic,项目名称:BetterAlts,代码行数:31,代码来源:Database.java

示例13: hikariConfig

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private HikariConfig hikariConfig() {
    HikariConfig config = new HikariConfig();
    config.setDriverClassName(driverClassName);
    config.setJdbcUrl(url);
    config.setUsername(username);
    config.setPassword(password);
    config.setPoolName(poolName);
    config.setMaximumPoolSize(20);
    config.setMinimumIdle(2);
    config.setIdleTimeout(TimeUnit.SECONDS.toMillis(30));
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    return config;
}
 
开发者ID:JUGIstanbul,项目名称:second-opinion-api,代码行数:16,代码来源:DataSourceConfiguration.java

示例14: get

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public DataSource get() throws SQLException {
    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(baseConfig.getJdbcUrl());
    config.setUsername(baseConfig.getUsername());
    config.setPassword(baseConfig.getPassword());
    config.setMinimumIdle(baseConfig.getMinimumIdle());
    config.setMaximumPoolSize(baseConfig.getMaximumPoolSize());
    config.setConnectionTestQuery(baseConfig.getConnectionTestQuery());
    config.setIdleTimeout(baseConfig.getIdleTimeout());
    config.setConnectionTimeout(baseConfig.getConnectionTimeout());

    return new HikariDataSource(config);
}
 
开发者ID:Twister915,项目名称:pl,代码行数:15,代码来源:ConfiguredDataSourceProvider.java

示例15: getHikariConfig

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private HikariConfig getHikariConfig(AgroalDataSourceConfiguration dataSourceConfiguration) {
    if ( dataSourceConfiguration.isXA() ) {
        throw new UnsupportedOperationException( "Unsupported. Hikari does not support XA" );
    }

    HikariConfig hikariConfig = new HikariConfig();

    hikariConfig.setDataSourceJNDI( dataSourceConfiguration.jndiName() );
    hikariConfig.setLeakDetectionThreshold( poolConfiguration.leakTimeout().toMillis() );
    hikariConfig.setIdleTimeout( poolConfiguration.reapTimeout().toMillis() );
    hikariConfig.setValidationTimeout( poolConfiguration.validationTimeout().toMillis() );

    if ( factoryConfiguration.jdbcTransactionIsolation().isDefined() ) {
        hikariConfig.setTransactionIsolation( "TRANSACTION_" + factoryConfiguration.jdbcTransactionIsolation().name() );
    }

    hikariConfig.setJdbcUrl( factoryConfiguration.jdbcUrl() );
    hikariConfig.setAutoCommit( factoryConfiguration.autoCommit() );
    hikariConfig.setConnectionInitSql( factoryConfiguration.initialSql() );

    Principal principal = factoryConfiguration.principal();
    if ( principal != null ) {
        hikariConfig.setUsername( factoryConfiguration.principal().getName() );
    }
    for ( Object credential : factoryConfiguration.credentials() ) {
        if ( credential instanceof SimplePassword ) {
            hikariConfig.setPassword( ( (SimplePassword) credential ).getWord() );
        }
    }

    hikariConfig.setMaximumPoolSize( poolConfiguration.maxSize() );
    hikariConfig.setConnectionTimeout( poolConfiguration.acquisitionTimeout().toMillis() );
    hikariConfig.setDriverClassName( factoryConfiguration.driverClassName() );

    return hikariConfig;
}
 
开发者ID:agroal,项目名称:agroal,代码行数:37,代码来源:HikariUnderTheCovers.java


注:本文中的com.zaxxer.hikari.HikariConfig.setIdleTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。