Java Code Examples for com.zaxxer.hikari.HikariConfig#setLeakDetectionThreshold()

The following examples show how to use com.zaxxer.hikari.HikariConfig#setLeakDetectionThreshold() . 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: HelperSql.java    From helper with MIT License 6 votes vote down vote up
public HelperSql(@Nonnull DatabaseCredentials credentials) {
    final HikariConfig hikari = new HikariConfig();

    hikari.setPoolName("helper-sql-" + POOL_COUNTER.getAndIncrement());

    hikari.setDataSourceClassName(DATA_SOURCE_CLASS);
    hikari.addDataSourceProperty("serverName", credentials.getAddress());
    hikari.addDataSourceProperty("port", credentials.getPort());
    hikari.addDataSourceProperty("databaseName", credentials.getDatabase());

    hikari.setUsername(credentials.getUsername());
    hikari.setPassword(credentials.getPassword());

    hikari.setMaximumPoolSize(MAXIMUM_POOL_SIZE);
    hikari.setMinimumIdle(MINIMUM_IDLE);

    hikari.setMaxLifetime(MAX_LIFETIME);
    hikari.setConnectionTimeout(CONNECTION_TIMEOUT);
    hikari.setLeakDetectionThreshold(LEAK_DETECTION_THRESHOLD);

    // ensure we use unicode (this calls #setProperties, a hack for the mariadb driver)
    hikari.addDataSourceProperty("properties", "useUnicode=true;characterEncoding=utf8");

    this.source = new HikariDataSource(hikari);
    this.stream = SqlStream.connect(this.source);
}
 
Example 2
Source File: JooqJobActivityConnectorComponent.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Bean
@Primary
public JooqContext getJooqContext(JooqConfiguration jooqConfiguration, EmbeddedPostgresService embeddedPostgresService) {
    HikariConfig hikariConfig = new HikariConfig();

    hikariConfig.setAutoCommit(true);

    // Connection management
    hikariConfig.setConnectionTimeout(10000);
    hikariConfig.setMaximumPoolSize(10);
    hikariConfig.setLeakDetectionThreshold(3000);

    if (jooqConfiguration.isInMemoryDb()) {
        hikariConfig.setDataSource(embeddedPostgresService.getDataSource());
    } else {
        hikariConfig.addDataSourceProperty(PGProperty.SSL.getName(), "true");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_MODE.getName(), "verify-ca");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_FACTORY.getName(), RDSSSLSocketFactory.class.getName());
        hikariConfig.setJdbcUrl(jooqConfiguration.getDatabaseUrl());
    }

    return new JooqContext(jooqConfiguration, new HikariDataSource(hikariConfig), embeddedPostgresService);
}
 
Example 3
Source File: JooqJobActivityConnectorComponent.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Bean
public JooqContext getJooqProducerContext(JooqConfiguration jooqConfiguration, EmbeddedPostgresService embeddedPostgresService) {
    HikariConfig hikariConfig = new HikariConfig();

    hikariConfig.setAutoCommit(true);

    // Connection management
    hikariConfig.setConnectionTimeout(10000);
    hikariConfig.setMaximumPoolSize(10);
    hikariConfig.setLeakDetectionThreshold(3000);

    if (jooqConfiguration.isInMemoryDb()) {
        hikariConfig.setDataSource(embeddedPostgresService.getDataSource());
    } else {
        hikariConfig.addDataSourceProperty(PGProperty.SSL.getName(), "true");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_MODE.getName(), "verify-ca");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_FACTORY.getName(), RDSSSLSocketFactory.class.getName());
        hikariConfig.setJdbcUrl(jooqConfiguration.getProducerDatatabaseUrl());
    }

    return new JooqContext(jooqConfiguration, new HikariDataSource(hikariConfig), embeddedPostgresService);
}
 
Example 4
Source File: MySQLDB.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Setups the {@link HikariDataSource}
 */
@Override
public void setupDataSource() {
    try {
        loadMySQLDriver();

        HikariConfig hikariConfig = new HikariConfig();

        String host = config.get(DatabaseSettings.MYSQL_HOST);
        String port = config.get(DatabaseSettings.MYSQL_PORT);
        String database = config.get(DatabaseSettings.MYSQL_DATABASE);
        String launchOptions = config.get(DatabaseSettings.MYSQL_LAUNCH_OPTIONS);
        // REGEX: match "?", match "word=word&" *-times, match "word=word"
        if (launchOptions.isEmpty() || !launchOptions.matches("\\?((\\w*=\\w*)&)*(\\w*=\\w*)")) {
            launchOptions = "?rewriteBatchedStatements=true&useSSL=false";
            logger.error(locale.getString(PluginLang.DB_MYSQL_LAUNCH_OPTIONS_FAIL, launchOptions));
        }
        hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
        hikariConfig.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + database + launchOptions);

        String username = config.get(DatabaseSettings.MYSQL_USER);
        String password = config.get(DatabaseSettings.MYSQL_PASS);

        hikariConfig.setUsername(username);
        hikariConfig.setPassword(password);
        hikariConfig.addDataSourceProperty("connectionInitSql", "set time_zone = '+00:00'");

        hikariConfig.setPoolName("Plan Connection Pool-" + increment);
        increment();

        hikariConfig.setAutoCommit(true);
        hikariConfig.setMaximumPoolSize(8);
        hikariConfig.setMaxLifetime(TimeUnit.MINUTES.toMillis(25L));
        hikariConfig.setLeakDetectionThreshold(TimeUnit.MINUTES.toMillis(10L));

        this.dataSource = new HikariDataSource(hikariConfig);
    } catch (HikariPool.PoolInitializationException e) {
        throw new DBInitException("Failed to set-up HikariCP Datasource: " + e.getMessage(), e);
    }
}
 
Example 5
Source File: DataSourceProvider.java    From digdag with Apache License 2.0 5 votes vote down vote up
private void createPooledDataSource()
{
    String url = DatabaseConfig.buildJdbcUrl(config);

    HikariConfig hikari = new HikariConfig();
    hikari.setJdbcUrl(url);
    hikari.setDriverClassName(DatabaseMigrator.getDriverClassName(config.getType()));
    hikari.setDataSourceProperties(DatabaseConfig.buildJdbcProperties(config));

    hikari.setConnectionTimeout(config.getConnectionTimeout() * 1000);
    hikari.setIdleTimeout(config.getIdleTimeout() * 1000);
    hikari.setValidationTimeout(config.getValidationTimeout() * 1000);
    hikari.setMaximumPoolSize(config.getMaximumPoolSize());
    hikari.setMinimumIdle(config.getMinimumPoolSize());
    hikari.setRegisterMbeans(config.getEnableJMX());
    hikari.setLeakDetectionThreshold(config.getLeakDetectionThreshold());

    // Here should not set connectionTestQuery (that overrides isValid) because
    // ThreadLocalTransactionManager.commit assumes that Connection.isValid returns
    // false when an error happened during a transaction.

    logger.debug("Using database URL {}", hikari.getJdbcUrl());

    HikariDataSource ds = new HikariDataSource(hikari);
    this.ds = ds;
    this.closer = ds;
}
 
Example 6
Source File: HikariCPDataSourceProvider.java    From vertx-jdbc-client with Apache License 2.0 4 votes vote down vote up
@Override
public DataSource getDataSource(JsonObject json) throws SQLException {

  final HikariConfig config = new HikariConfig();

  for (Map.Entry<String, Object> entry : json) {
    switch (entry.getKey()) {
      case "dataSourceClassName":
        config.setDataSourceClassName((String) entry.getValue());
        break;
      case "jdbcUrl":
        config.setJdbcUrl((String) entry.getValue());
        break;
      case "username":
        config.setUsername((String) entry.getValue());
        break;
      case "password":
        config.setPassword((String) entry.getValue());
        break;
      case "autoCommit":
        config.setAutoCommit((Boolean) entry.getValue());
        break;
      case "connectionTimeout":
        config.setConnectionTimeout(getLong(entry.getValue()));
        break;
      case "idleTimeout":
        config.setIdleTimeout(getLong(entry.getValue()));
        break;
      case "maxLifetime":
        config.setMaxLifetime(getLong(entry.getValue()));
        break;
      case "connectionTestQuery":
        config.setConnectionTestQuery((String) entry.getValue());
        break;
      case "minimumIdle":
        config.setMinimumIdle((Integer) entry.getValue());
        break;
      case "maximumPoolSize":
        config.setMaximumPoolSize((Integer) entry.getValue());
        break;
      case "metricRegistry":
        throw new UnsupportedOperationException(entry.getKey());
      case "healthCheckRegistry":
        throw new UnsupportedOperationException(entry.getKey());
      case "poolName":
        config.setPoolName((String) entry.getValue());
        break;
      case "isolationInternalQueries":
        config.setIsolateInternalQueries((Boolean) entry.getValue());
        break;
      case "allowPoolSuspension":
        config.setAllowPoolSuspension((Boolean) entry.getValue());
        break;
      case "readOnly":
        config.setReadOnly((Boolean) entry.getValue());
        break;
      case "registerMBeans":
        config.setRegisterMbeans((Boolean) entry.getValue());
        break;
      case "catalog":
        config.setCatalog((String) entry.getValue());
        break;
      case "connectionInitSql":
        config.setConnectionInitSql((String) entry.getValue());
        break;
      case "driverClassName":
        config.setDriverClassName((String) entry.getValue());
        break;
      case "transactionIsolation":
        config.setTransactionIsolation((String) entry.getValue());
        break;
      case "validationTimeout":
        config.setValidationTimeout(getLong(entry.getValue()));
        break;
      case "leakDetectionThreshold":
        config.setLeakDetectionThreshold(getLong(entry.getValue()));
        break;
      case "dataSource":
        throw new UnsupportedOperationException(entry.getKey());
      case "threadFactory":
        throw new UnsupportedOperationException(entry.getKey());
      case "datasource":
        // extension to support configuring datasource.* properties
        for (Map.Entry<String, Object> key : ((JsonObject) entry.getValue())) {
          config.addDataSourceProperty(key.getKey(), key.getValue());
        }
        break;
    }
  }

  return new HikariDataSource(config);
}