Java Code Examples for com.zaxxer.hikari.HikariDataSource#setIdleTimeout()
The following examples show how to use
com.zaxxer.hikari.HikariDataSource#setIdleTimeout() .
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: LocDataSourceAutoConfiguration.java From loc-framework with MIT License | 6 votes |
private HikariDataSource createHikariDataSource(JdbcProperties jdbcProperties) { HikariDataSource hikariDataSource = new HikariDataSource(); hikariDataSource.setJdbcUrl(jdbcProperties.getJdbcUrl()); hikariDataSource.setUsername(jdbcProperties.getUsername()); hikariDataSource.setPassword(jdbcProperties.getPassword()); JdbcPoolProperties jdbcPoolProperties = jdbcProperties.getJdbcPool(); hikariDataSource.setAutoCommit(jdbcPoolProperties.isAutoCommit()); hikariDataSource.setConnectionTimeout(jdbcPoolProperties.getConnectionTimeout()); hikariDataSource.setIdleTimeout(jdbcPoolProperties.getIdleTimeout()); hikariDataSource.setMaxLifetime(jdbcPoolProperties.getMaxLifetime()); hikariDataSource.setMaximumPoolSize(jdbcPoolProperties.getMaximumPoolSize()); hikariDataSource.setMinimumIdle(jdbcPoolProperties.getMinimumIdle()); hikariDataSource .setInitializationFailTimeout(jdbcPoolProperties.getInitializationFailTimeout()); hikariDataSource.setIsolateInternalQueries(jdbcPoolProperties.isIsolateInternalQueries()); hikariDataSource.setReadOnly(jdbcPoolProperties.isReadOnly()); hikariDataSource.setRegisterMbeans(jdbcPoolProperties.isRegisterMbeans()); Optional.ofNullable(jdbcPoolProperties.getDriverClassName()) .ifPresent(hikariDataSource::setDriverClassName); hikariDataSource.setValidationTimeout(jdbcPoolProperties.getValidationTimeout()); hikariDataSource.setLeakDetectionThreshold(jdbcPoolProperties.getLeakDetectionThreshold()); return hikariDataSource; }
Example 2
Source File: JobConfiguration.java From CogStack-Pipeline with Apache License 2.0 | 6 votes |
@Bean(destroyMethod = "close") @Primary @Qualifier("sourceDataSource") public DataSource sourceDataSource() { HikariDataSource mainDatasource = new HikariDataSource(); executeSessionScripts(mainDatasource,sourceDriver); mainDatasource.setDriverClassName(sourceDriver); mainDatasource.setJdbcUrl(sourceJdbcPath); mainDatasource.setUsername(sourceUserName); mainDatasource.setPassword(sourcePassword); mainDatasource.setIdleTimeout(sourceIdleTimeout); mainDatasource.setMaxLifetime(sourceMaxLifeTime); // show tables query does not work with post gres if (Arrays.asList(this.env.getActiveProfiles()).contains("docman") && ! Arrays.asList(this.env.getActiveProfiles()).contains("postgres")){ mainDatasource.setConnectionTestQuery("show tables"); } if (sourcePoolSize > 0){ mainDatasource.setMaximumPoolSize(sourcePoolSize); } // set the db connection leak detection time mainDatasource.setLeakDetectionThreshold(sourceLeakDetection); return mainDatasource; }
Example 3
Source File: JobConfiguration.java From CogStack-Pipeline with Apache License 2.0 | 6 votes |
@Profile({"jdbc_out", "jdbc_out_map"}) @Bean(destroyMethod = "close") @Qualifier("targetDataSource") public DataSource targetDataSource() { HikariDataSource mainDatasource = new HikariDataSource(); // read and set the mandatory DB connector properties executeSessionScripts(mainDatasource, env.getRequiredProperty("target.Driver")); mainDatasource.setDriverClassName(env.getRequiredProperty("target.Driver")); mainDatasource.setJdbcUrl(env.getRequiredProperty("target.JdbcPath")); mainDatasource.setUsername(env.getRequiredProperty("target.username")); mainDatasource.setPassword(env.getRequiredProperty("target.password")); // set optional properties mainDatasource.setIdleTimeout(targetIdleTimeout); mainDatasource.setMaxLifetime(targetMaxLifeTime); if (targetPoolSize > 0){ mainDatasource.setMaximumPoolSize(targetPoolSize); } return mainDatasource; }
Example 4
Source File: BatchConfigurer.java From CogStack-Pipeline with Apache License 2.0 | 6 votes |
@Bean(destroyMethod = "close") @Qualifier("jobRepositoryDataSource") public DataSource jobRepositoryDataSource() { HikariDataSource mainDatasource = new HikariDataSource(); mainDatasource.setDriverClassName(repoDriver); mainDatasource.setJdbcUrl(repoJdbcPath); mainDatasource.setUsername(repoUserName); mainDatasource.setPassword(repoPassword); mainDatasource.setIdleTimeout(repoIdleTimeoutMs); mainDatasource.setMaxLifetime(repoMaxLifeTimeMs); if (repoPoolSize > 0) { mainDatasource.setMaximumPoolSize(repoPoolSize); } //mainDatasource.setAutoCommit(false); return mainDatasource; }
Example 5
Source File: PostgreSQLSourceConfig.java From Launcher with GNU General Public License v3.0 | 5 votes |
public synchronized Connection getConnection() throws SQLException { if (source == null) { // New data source PGSimpleDataSource postgresqlSource = new PGSimpleDataSource(); // Set credentials postgresqlSource.setServerNames(addresses); postgresqlSource.setPortNumbers(ports); postgresqlSource.setUser(username); postgresqlSource.setPassword(password); postgresqlSource.setDatabaseName(database); // Try using HikariCP source = postgresqlSource; //noinspection Duplicates try { Class.forName("com.zaxxer.hikari.HikariDataSource"); hikari = true; // Used for shutdown. Not instanceof because of possible classpath error // Set HikariCP pool HikariDataSource hikariSource = new HikariDataSource(); hikariSource.setDataSource(source); // Set pool settings hikariSource.setPoolName(poolName); hikariSource.setMinimumIdle(0); hikariSource.setMaximumPoolSize(MAX_POOL_SIZE); hikariSource.setIdleTimeout(TIMEOUT * 1000L); // Replace source with hds source = hikariSource; LogHelper.info("HikariCP pooling enabled for '%s'", poolName); } catch (ClassNotFoundException ignored) { LogHelper.warning("HikariCP isn't in classpath for '%s'", poolName); } } return source.getConnection(); }
Example 6
Source File: JdbcCoordinatorRepository.java From hmily with Apache License 2.0 | 5 votes |
@Override public void init(final String modelName, final HmilyConfig txConfig) { try { final HmilyDbConfig hmilyDbConfig = txConfig.getHmilyDbConfig(); if (hmilyDbConfig.getDataSource() != null && StringUtils.isBlank(hmilyDbConfig.getUrl())) { dataSource = hmilyDbConfig.getDataSource(); } else { HikariDataSource hikariDataSource = new HikariDataSource(); hikariDataSource.setJdbcUrl(hmilyDbConfig.getUrl()); hikariDataSource.setDriverClassName(hmilyDbConfig.getDriverClassName()); hikariDataSource.setUsername(hmilyDbConfig.getUsername()); hikariDataSource.setPassword(hmilyDbConfig.getPassword()); hikariDataSource.setMaximumPoolSize(hmilyDbConfig.getMaxActive()); hikariDataSource.setMinimumIdle(hmilyDbConfig.getMinIdle()); hikariDataSource.setConnectionTimeout(hmilyDbConfig.getConnectionTimeout()); hikariDataSource.setIdleTimeout(hmilyDbConfig.getIdleTimeout()); hikariDataSource.setMaxLifetime(hmilyDbConfig.getMaxLifetime()); hikariDataSource.setConnectionTestQuery(hmilyDbConfig.getConnectionTestQuery()); if (hmilyDbConfig.getDataSourcePropertyMap() != null && !hmilyDbConfig.getDataSourcePropertyMap().isEmpty()) { hmilyDbConfig.getDataSourcePropertyMap().forEach(hikariDataSource::addDataSourceProperty); } dataSource = hikariDataSource; } this.tableName = RepositoryPathUtils.buildDbTableName(modelName); //save current database type this.currentDBType = DbTypeUtils.buildByDriverClassName(hmilyDbConfig.getDriverClassName()); executeUpdate(SqlHelper.buildCreateTableSql(hmilyDbConfig.getDriverClassName(), tableName)); } catch (Exception e) { LogUtil.error(LOGGER, "hmily jdbc log init exception please check config:{}", e::getMessage); throw new HmilyRuntimeException(e); } }
Example 7
Source File: DataSourceUtils.java From shardingsphere with Apache License 2.0 | 5 votes |
private static HikariDataSource createHikariDataSource(final DatabaseType databaseType, final String databaseName) { HikariDataSource result = new HikariDataSource(); result.setJdbcUrl(getURL(databaseType, databaseName)); result.setUsername("root"); result.setPassword("root"); result.setMaximumPoolSize(10); result.setMinimumIdle(2); result.setConnectionTimeout(15 * 1000); result.setIdleTimeout(40 * 1000); return result; }
Example 8
Source File: HikariCPDataSourceBuilder.java From micro-server with Apache License 2.0 | 5 votes |
private DataSource getDataSource() { HikariDataSource ds = new HikariDataSource(); ds.setDriverClassName(mainEnv.getDriverClassName()); ds.setJdbcUrl(mainEnv.getUrl()); ds.setUsername(mainEnv.getUsername()); ds.setPassword(mainEnv.getPassword()); ds.setMaximumPoolSize(hikariCPEnv.getMaxPoolSize()); ds.setMinimumIdle(hikariCPEnv.getMinimumIdle()); ds.setIdleTimeout(hikariCPEnv.getIdleTimeout()); return ds; }
Example 9
Source File: HikariCPProvider.java From tastjava with MIT License | 4 votes |
@Override public boolean register() { if (IsRegistered) { return HAS_REGISTERED; } HikariDataSource ds = new HikariDataSource(); //basic config ds.setJdbcUrl(jdbcURL); ds.setDriverClassName(jdbcDriver); ds.setUsername(jdbcUsername); ds.setPassword(jdbcPassword); //custom config ds.setAutoCommit(autoCommit); ds.setConnectionTimeout(connectionTimeout); ds.setIdleTimeout(idleTimeout); ds.setMaxLifetime(maxLifetime); ds.setMaximumPoolSize(maximumPoolSize); ds.setValidationTimeout(validationTimeout); ds.setLeakDetectionThreshold(leakDetectionThreshold); if (!StrUtil.isBlank(poolName)) { ds.setPoolName(poolName); } if (!StrUtil.isBlank(catalog)) { ds.setCatalog(catalog); } if (!StrUtil.isBlank(connectionInitSql)) { ds.setConnectionInitSql(connectionInitSql); } if (!StrUtil.isBlank(transactionIsolation)) { ds.setTransactionIsolation(transactionIsolation); } if (jdbcURL.contains(":mysql:")) { ds.addDataSourceProperty("cachePrepStmts", "true"); ds.addDataSourceProperty("prepStmtCacheSize", "250"); ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); ds.addDataSourceProperty("useServerPrepStmts", "true"); } setDataSource(ds); setIsRegistered(HAS_REGISTERED); return HAS_REGISTERED; }