So I am implementing connection pooling, with HikariCP. It seems simple enough, but I have some questions
I saw a tutorial and said that the code should look like this:
Connection connection = null;
try{
connection = hikary.getConnection();
...
...
}catch(SQLException e){
e.printStackTrace()
}finally{
if(connection != null)
connection.close(); // why?
}
So I know I'm probably asking a dumb question, but I don't understand what the point of pooling is, if you're closing the connection each time you get one?
Wouldn't that be the whole purpose of pooling connections? to recycle the connection?
Another question is that I'm assuming this hikari.getConnection()
method is thread safe? I'm 99% sure it is but, I just go ahead and ask while I'm at it.