Hikari 连接没有超时

Hikari connection is not getting timed out

我的 spring 启动应用程序中有以下 Hikari 配置。查询花费的时间超过 connection-timeout 设置的时间。但是,超时从未发生。我保持尽可能低的水平来模拟连接超时。

    HikariConfig dataSourceConfig = new HikariConfig();
    dataSourceConfig.setDriverClassName(config.driver);
    dataSourceConfig.setJdbcUrl(config.url);
    dataSourceConfig.setUsername(config.user);
    dataSourceConfig.setPassword(config.password);
    dataSourceConfig.setConnectionTestQuery(config.validationQuery);
    dataSourceConfig.setMaximumPoolSize(config.poolMax);
    dataSourceConfig.setConnectionTimeout(300);
    dataSourceConfig.setIdleTimeout(10000);
    dataSourceConfig.setMaxLifetime(60000);
    JdbcTemplate jdbcTemplate = new JdbcTemplate(new HikariDataSource(dataSourceConfig));

这是一些显示查询 运行 超过 300 毫秒的日志。

Time elapsed to run query......2913

使用 Hikari 3.2 和 mariadb

谢谢。

发件人:https://github.com/brettwooldridge/HikariCP

connectionTimeout This property controls the maximum number of milliseconds that a client (that's you) will wait for a connection from the pool. If this time is exceeded without a connection becoming available, a SQLException will be thrown. Lowest acceptable connection timeout is 250 ms. Default: 30000 (30 seconds)

所以这个 属性 更多的是关于您的应用程序等待连接的时间,而不是允许执行查询的时间。

我想你想要的是"max_statement_time":https://mariadb.com/kb/en/library/server-system-variables/#max_statement_time

Maximum time in seconds that a query can execute before being aborted. This includes all queries, not just SELECT statements, but excludes statements in stored procedures. If set to 0, no limit is applied.