简体   繁体   English

Hikari CP DB 连接未在异步块中释放

[英]Hikari CP DB connection not release in Async block

I am using Spring Boot application which has API controller to generate reports.我正在使用具有 API controller 的 Spring 引导应用程序来生成报告。 The actual service function is wrapped around @Async annotation and function makes DB calls and generates the csv reports.实际服务 function 包裹在 @Async 注释周围,function 进行 DB 调用并生成 csv 报告。 I am also using Hikari CP for connection pool management and JPA + QueryDSL for forming select queries.我还使用 Hikari CP 进行连接池管理,使用 JPA + QueryDSL 形成 select 查询。

I am seeing strange issue in that DB connections are not being released after the files are successfully generated.我看到一个奇怪的问题,即成功生成文件后没有释放数据库连接。 Every new call to the controller/service function creates new active connections and it remains active.对控制器/服务 function 的每次新调用都会创建新的活动连接并保持活动状态。 Its not getting released because of which I am getting Connection is not available error from Hikari once my max pool size limit is reached.它没有被释放,因为一旦达到我的最大池大小限制,我就会从 Hikari 收到 Connection is not available 错误。

Any suggestions why connection is not being released.任何有关未释放连接的建议。 The service function issues only select queries, no updates or inserts.服务 function 仅发出 select 查询,没有更新或插入。

Hikari CP configs: Hikari CP 配置:

spring.datasource.hikari.maximum-pool-size: "80"
spring.datasource.hikari.idle-timeout: "300000"
spring.datasource.hikari.connectionTimeout: "600000"
spring.datasource.hikari.minimum-idle: "15"

My service function我的服务function

@Async
@Override
public void exportListing(String[] filter) {
        try {
}
catch(Exception e)
{
}

I fixed it by wrapping it within @Transactional block which ensures that DB connections are closed once the function completes.我通过将其包装在 @Transactional 块中来修复它,以确保在 function 完成后关闭数据库连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM