Spring HikariCP空闲连接以活动状态保留在连接池中
我正在使用SpringBoot(1.5.6)、Hibernate、Postgres和Hikari(2.7.8)。我的配置是:Spring HikariCP空闲连接以活动状态保留在连接池中,spring,hibernate,spring-boot,hikaricp,connection-pool,Spring,Hibernate,Spring Boot,Hikaricp,Connection Pool,我正在使用SpringBoot(1.5.6)、Hibernate、Postgres和Hikari(2.7.8)。我的配置是: spring.datasource.hikari.minimumIdle=1 spring.datasource.hikari.maximumPoolSize=20 spring.datasource.hikari.idleTimeout=30000 spring.datasource.hikari.poolName=SpringBootJPAHikariCP sprin
spring.datasource.hikari.minimumIdle=1
spring.datasource.hikari.maximumPoolSize=20
spring.datasource.hikari.idleTimeout=30000
spring.datasource.hikari.poolName=SpringBootJPAHikariCP
spring.datasource.hikari.maxLifetime=50000
spring.datasource.hikari.connectionTimeout=30000
我所期望的是,空闲连接应在30000
ms/30秒空闲后释放。问题在于每次请求新连接时都会保留所有空闲连接。因此,在一些时间之后,我得到了20个空闲连接和一个新请求,Hikari尝试获得一个新连接并获得
SpringBootJPahikarip-连接不可用,请求在30001ms后超时。
那么,我做错了什么。?还是用户误解了配置
Hikari初始化日志:
SpringBootJPAHikariCP - configuration:
allowPoolSuspension.............false
autoCommit......................true
catalog.........................none
connectionInitSql...............none
connectionTestQuery.............none
connectionTimeout...............30000
dataSource......................none
dataSourceClassName.............none
dataSourceJNDI..................none
dataSourceProperties............{password=<masked>}
driverClassName................."org.postgresql.Driver"
healthCheckProperties...........{}
healthCheckRegistry.............none
idleTimeout.....................30000
initializationFailFast..........true
initializationFailTimeout.......1
isolateInternalQueries..........false
jdbc4ConnectionTest.............false
jdbcUrl.........................jdbc:postgresql://localhost:5432/dbname
leakDetectionThreshold..........0
maxLifetime.....................50000
maximumPoolSize.................20
metricRegistry..................none
metricsTrackerFactory...........none
minimumIdle.....................1
password........................<masked>
poolName........................"SpringBootJPAHikariCP"
readOnly........................false
registerMbeans..................false
scheduledExecutor...............none
scheduledExecutorService........internal
schema..........................none
threadFactory...................internal
transactionIsolation............default
username........................"postgres"
validationTimeout...............5000
idle
formpostgres
视图和active
form Hikari视图。所以,当有5个来自数据库的空闲连接时,Hikari日志中有toatal=5、active=4、idle=、waiting=0
@Transactional
这不是Hikari的问题,我的结局是个错误。仍在张贴这件事发生的细节,以防对某人有所帮助 我使用的是
spring boot 1.5.6
(这是我开始工作时的最新版本)。
此版本包括spring orm 4.3.1
。此版本的springorm
包括对三个版本的hibernate的支持,Hibernate5
,Hibernate4
和Hibernate3
因此,我为当前会话上下文类配置了spring boot的以下配置
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
在Hikari的连接管理之前,一切都很正常。所发生的是1.5.6版的springbootstarterjpa
,包括Hibernate5
(我指的是hibernate核心)
因此,在执行任何DB操作后,spring将失去对该连接的控制(这种版本不匹配的可能性最大)。因此问题就来了
更换后
org.springframework.orm.hibernate4.SpringSessionContext
到
问题马上就解决了
我当前的配置是
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL95Dialect
仅供参考,解决问题后切换至弹簧护套2 您的代码没有返回到池的连接。这与idleTimeout配置设置无关。那么我如何解决这个问题呢。有什么建议或资源可以阅读吗。?顺便说一句,我在连接池方面是个新手。启用
leakDetectionThreshold
并查看日志中的泄漏堆栈跟踪。启用leakDetectionThreshold
后,出现了多个泄漏检测异常。所以可能不是池本身,可能是我的应用程序做错了什么。仍然开放给suggestions@brettw你能查一下我关于这个问题的最新情况吗。仍然存在这个问题。您好@saif您能为我建议配置吗?因为在阅读了您的帖子之后,我也无法修复我的hikari池问题
org.springframework.orm.hibernate5.SpringSessionContext
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL95Dialect