当前位置: 首页 > 知识库问答 >
问题:

HikariCP是否支持类似于C#的spring boot应用程序中的命令超时

麻超
2023-03-14

HikariCP是否支持类似于C#的spring boot应用程序中的命令超时

我正在我的spring boot应用程序中使用Hikari连接池。我使用以下配置启用了connectionTimeout

spring.datasource.hikari.connectionTimeout: 30000

如果增加并发用户数,日志中会出现以下异常

Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; 
nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.

除了上面的例外,我很满意。我可以增加连接的数量。但我担心的是,很少有endpoint需要2分钟以上的响应时间。这些endpoint从池获得了DB连接,但需要更多的时间来处理。是否有一个设置,我可以在其中提到一些超时,这样,如果DB需要超过一些时间(操作时间--比如40秒),那么它应该发送SQL异常。类似于C#中的命令超时

应用程序.属性

# A list of all Hikari parameters with a good explanation is available on https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby
# This property controls the minimum number of idle connections that HikariCP tries to maintain in the pool. Default: same as maximumPoolSize
spring.datasource.hikari.minimumIdle: 10
# This property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections. Basically this value will determine the maximum number of actual connections to the database backend.
# Default: 10
spring.datasource.hikari.maximumPoolSize: 20
#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)
spring.datasource.hikari.connectionTimeout: 30000
# This property controls the maximum amount of time that a connection is allowed to sit idle in the pool. This setting only applies when minimumIdle is defined to be less than maximumPoolSize
# Default: 600000 (10 minutes)
spring.datasource.hikari.idleTimeout: 600000
# This property controls the maximum lifetime of a connection in the pool. An in-use connection will never be retired, only when it is closed will it then be removed.
# Default: 1800000 (30 minutes)
spring.datasource.hikari.maxLifetime: 1800000
# This property sets a SQL statement that will be executed after every new connection creation before adding it to the pool. Default: none
spring.datasource.hikari.connectionInitSql: SELECT 1 FROM DUAL

共有1个答案

赵征
2023-03-14

正如本注释中所解释的,connectiontimeout值似乎用于获取连接超时。您可以尝试将其设置为高于30秒的值,看看是否有帮助。

 类似资料:
  • 我已经为Postgresql启用了复制,并且正在使用PGPool进行负载平衡。 我在使用HikariCP甚至Apache DBCP连接到Postgres时遇到了问题。 在SpringBoot应用程序中有没有使用PGPool的方法? 请查找堆栈跟踪: 2018-08-10 10:20:19.124信息37879----[main]com.zaxxer.hikari.hikaridatasource:

  • 嗨,我想通过JDBC在DB2、Sybase、MySQL等多个数据库上创建表,现在我需要使用文本文件data.txt创建这个表,它包含数据空间分隔值。对于例如。 现在这个data.txt包含数千个记录,以空格分隔的值。我需要使用java io逐行解析这个文件,并对每个记录执行sql insert查询。 我发现有一个加载数据的sql命令。是否有任何JDBC驱动程序支持此命令?如果不是,什么应该是解决这

  • 这是我使用SpringBoot的第一天,我试图理解体系结构,因此我开始构建一个hello world应用程序: 在我的pom.xml中,在maven-shade-plugin下,我将mainClass声明如下: 文件目标是src/main/java/com/demo/helloworld.java,该文件中的代码是: 我错过了什么?

  • 到目前为止,我一直认为容器技术(例如:docker)提供了所需的隔离和操作系统级虚拟化。在容器中运行的应用程序受到名称空间、cgroup、设备/selinux、功能的限制,他们无法弄清楚自己所处的主机环境。但是这种理解似乎不是100%正确的。 与wiki-OS级虚拟化一样 操作系统级虚拟化是一种操作系统范例,其中内核允许存在多个独立的用户空间实例。这些实例称为容器(LXC、Solaris容器、Do

  • 问题内容: 我想检查一个对象是否是类的实例或的子类。 例如,如果is是类,我想成为并且也要成为。 我希望它也适用于装箱的原始类型。例如,如果是那么应该是。 有这样的事吗?如果没有,如何实现这种方法? 问题答案: Class.isInstance可以满足您的需求。 当然,如果可以使用它,则不应该使用它,但是对于反射场景,它通常派上用场。

  • 是否可以将最大池大小设置为软限制? 我的意思是,我希望HikariCP最多使用5个连接。但是,当需要第6个连接时,我希望HikariCP创建第6个连接,该连接在我将其返回池后将被销毁。此外,如果HikariCP通知我,由于池中的所有连接都已在使用中,因此创建了一个额外的连接,那就太好了。