2

Running this test with an invalid hostname, or user/password, it waits about 2 minutes before failing. I would ideally like to have it fail immediately if user/password is incorrect, or if the hostname/port are not correct.

    HikariConfig config = new HikariConfig();
    config.setMaximumPoolSize(1);
    config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
    config.addDataSourceProperty("serverName", "localhost");
    config.addDataSourceProperty("url", "jdbc:mysql://localhost:3306/project_one?useServerPrepStmts=true&autoReconnect=false");
    config.addDataSourceProperty("port", "3306");
    config.addDataSourceProperty("databaseName", "project_one");
    config.addDataSourceProperty("user", "root");
    config.addDataSourceProperty("password", "");
    config.addDataSourceProperty("autoReconnect", false);

    HikariDataSource ds = new HikariDataSource(config);
    Connection connection = ds.getConnection();

    Statement statement = connection.createStatement();
    statement.executeQuery("SELECT 1");
4

2 回答 2

2

是的,版本 1.2.9 引入了快速失败选项(当前版本是 1.3.3)。配置属性是initializationFailFast. 将其设置为 true,池应该很快就会失败。com.zaxxer.hikari在您的日志记录框架(log4j、slf4j 等)中启用调试日志记录可以提供有关连接失败发生原因的更多详细信息。

于 2014-03-26T03:31:16.387 回答
1

从 HikariCP v3.0.0 开始,您必须使用属性initializationFailTimeout.

该属性initializationFailFast在 v2.4.10 中已弃用,并在 v3.0.0 中删除。

相关问题#770和拉取请求#771

于 2019-05-17T12:23:37.413 回答