With a pool, you do not add a connection to the pool to receive it later. You do the exact opposite: you get a connection from the pool when you need it, and close the connection when you are done with it to return it to the pool. HikariDataSource, as its name indicates, is a data source. DataSource is the object from which you get the connections.
The pool handles opening a connection for you. It puts you on a waiting queue if connections are not automatically available, etc.
Depending on the properties of the pool, the pool can open connections immediately or on demand, constantly open a certain number of connections, reduce the size of the pool after a given amount of unused time, etc.
This is very well documented: https://github.com/brettwooldridge/HikariCP#user-content-configuration-knobs-baby
Sample code (Java 7 and later):
try (Connection connection = ds.getConnection()) {
Sample code (before Java 7):
Connection connection = ds.getConnection(); try {
Jb nizet
source share