How do I properly close a HikariCP Connection Pool

后端 未结 1 2087
我在风中等你
我在风中等你 2021-02-19 20:43

I\'m using HikariDataSource to connect to a MariaDB database. The following class returns a Connection.

public class DataS         


        
1条回答
  •  北荒
    北荒 (楼主)
    2021-02-19 21:17

    You don't need to call DataSource's close() for every connection:

    Shutdown the DataSource and its associated pool.

    It's defined only for application termination:

    close() is essential at application termination

    You should continue working with the pool, notice you are closing (correctly) the connection with try with resources

    try (Connection connection = dataSource.getConnection()
    

    0 讨论(0)
提交回复
热议问题