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


Java HikariConfig.setMaxLifetime方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: dataSource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean
public DataSource dataSource() {
    HikariConfig configuration = new HikariConfig();
    configuration.setJdbcUrl(url);
    configuration.setUsername(username);
    configuration.setPassword(password);
    configuration.setAutoCommit(false);
    configuration.setMaximumPoolSize(maxPoolSize);
    configuration.setConnectionTimeout(connectionTimeout);
    configuration.setMaxLifetime(maxLifetime);
    Properties properties = new Properties();
    properties.setProperty("cachePrepStmts", cachePrepStmts);
    properties.setProperty("prepStmtCacheSize", prepStmtCacheSize);
    properties.setProperty("prepStmtCacheSqlLimit", prepStmtCacheSqlLimit);
    properties.setProperty("useServerPrepStmts", useServerPrepStmts);
    configuration.setDataSourceProperties(properties);
    configuration.setConnectionInitSql("SET NAMES " + connectionCharacter);
    return new HikariDataSource(configuration);
}
 
开发者ID:superkoh,项目名称:k-framework,代码行数:21,代码来源:MybatisAutoConfiguration.java

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: HikariCPComponent

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public HikariCPComponent(OptionMap options) {
    config = new HikariConfig();
    if (options.containsKey("uri")) config.setJdbcUrl(options.getString("uri"));
    if (options.containsKey("username")) config.setUsername(options.getString("username"));
    if (options.containsKey("password")) config.setPassword(options.getString("password"));
    if (options.containsKey("autoCommit?")) config.setAutoCommit(options.getBoolean("autoCommit?"));
    if (options.containsKey("connTimeout")) config.setConnectionTimeout(options.getLong("connTimeout"));
    if (options.containsKey("idleTimeout")) config.setIdleTimeout(options.getLong("idleTimeout"));
    if (options.containsKey("maxLifetime")) config.setMaxLifetime(options.getLong("maxLifetime"));
    if (options.containsKey("maxPoolSize")) config.setMaximumPoolSize(options.getInt("maxPoolSize"));
    if (options.containsKey("minIdle")) config.setMinimumIdle(options.getInt("minIdle"));
    if (options.containsKey("poolName")) config.setPoolName(options.getString("uri"));
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:14,代码来源:HikariCPComponent.java

示例12: loadHikariConfig

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private HikariConfig loadHikariConfig() {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(getString("settings.database.jdbc-url", "jdbc:h2:./plugins/FactionsTop/database"));
    hikariConfig.setUsername(getString("settings.database.username", "root"));
    hikariConfig.setPassword(getString("settings.database.password", "pa$$w0rd"));
    hikariConfig.setMaximumPoolSize(getInt("settings.database.maximum-pool-size", 10));
    hikariConfig.setMaxLifetime(getLong("settings.database.max-lifetime", 5000));
    hikariConfig.setIdleTimeout(getLong("settings.database.idle-timeout", 5000));
    hikariConfig.setConnectionTimeout(getLong("settings.database.connection-timeout", 5000));
    hikariConfig.setThreadFactory(new ThreadFactoryBuilder().setDaemon(true)
            .setNameFormat("factions-top-sql-pool-%d").build());
    return hikariConfig;
}
 
开发者ID:novucs,项目名称:factions-top,代码行数:14,代码来源:Settings.java

示例13: init

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public void init() {
    HikariConfig config = new HikariConfig();
    config.setPoolName("luckperms");

    appendConfigurationInfo(config);
    appendProperties(config, this.configuration);

    config.setMaximumPoolSize(this.configuration.getMaxPoolSize());
    config.setMinimumIdle(this.configuration.getMinIdleConnections());
    config.setMaxLifetime(this.configuration.getMaxLifetime());
    config.setConnectionTimeout(this.configuration.getConnectionTimeout());

    // If a connection is not returned within 10 seconds, it's probably safe to assume it's been leaked.
    config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(10)); // 10000

    // The drivers are really old in some of the older Spigot binaries, so Connection#isValid doesn't work.
    config.setConnectionTestQuery("/* LuckPerms ping */ SELECT 1");

    try {
        // don't perform any initial connection validation - we subsequently call #getConnection
        // to setup the schema anyways
        config.setInitializationFailTimeout(-1);
    } catch (NoSuchMethodError e) {
        //noinspection deprecation
        config.setInitializationFailFast(false);
    }


    this.hikari = new HikariDataSource(config);
}
 
开发者ID:lucko,项目名称:LuckPerms,代码行数:32,代码来源:HikariConnectionFactory.java

示例14: datasource

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
    public DataSource datasource() throws SQLException{
        HikariConfig config = new HikariConfig();
        dataSourceConfigure(config);
        config.setMaximumPoolSize(maxPoolSize);
       // config.setConnectionTimeout(connectionTimeoutMs);
        config.setIdleTimeout(idleTimeoutMs);
        config.setMaxLifetime(maxLifetimeMs);
        config.setRegisterMbeans(registerMbeans);
        config.setPoolName("pool");

        HikariDataSource dataSource = new HikariDataSource(config);
        return dataSource;
}
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:15,代码来源:JpaConfig.java

示例15: build

import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public ManagedDataSource build(final MetricRegistry metricRegistry, final String name) {
    final Properties properties = new Properties();
    for (final Map.Entry<String, String> property : this.properties.entrySet()) {
        properties.setProperty(property.getKey(), property.getValue());
    }

    final HikariConfig config = new HikariConfig();
    config.setDataSourceProperties(properties);
    if (this.autoCommitByDefault.isPresent()) {
        config.setAutoCommit(this.autoCommitByDefault.get());
    }
    config.setCatalog(this.defaultCatalog);
    if (this.readOnlyByDefault.isPresent()) {
        config.setReadOnly(this.readOnlyByDefault.get());
    }
    config.setDriverClassName(this.driverClass);
    config.setConnectionInitSql(this.initializationQuery);
    config.setMaximumPoolSize(this.maxSize);
    config.setMinimumIdle(this.minSize);
    if (this.getMaxConnectionAge().isPresent()) {
        config.setMaxLifetime(this.maxConnectionAge.toMilliseconds());
    }
    config.setPoolName(name);
    config.setJdbcUrl(this.url);
    config.setUsername(this.user);
    config.setPassword(this.user != null && this.password == null ? "" : this.password);
    config.setConnectionTestQuery(this.validationQuery);
    if (this.getValidationQueryTimeout().isPresent()) {
        config.setValidationTimeout(this.validationQueryTimeout.toMilliseconds());
    }
    if (this.defaultTransactionIsolation.isPresent()) {
        config.setTransactionIsolation(this.defaultTransactionIsolation.get().toString());
    }
    return new ManagedPooledDataSource(config, metricRegistry);
}
 
开发者ID:mtakaki,项目名称:dropwizard-hikaricp,代码行数:37,代码来源:DataSourceFactory.java


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