HikariCP multithreading separate connection for each thread HikariCP multithreading separate connection for each thread multithreading multithreading

HikariCP multithreading separate connection for each thread


Short answer: don't do that. JDBC connections are not meant to be shared between threads.

From the author of HikariCP (source):

Multithreaded access to Connections was deprecated in JDBC and is not supported by HikariCP either.

HikariCP is fast enough that you can obtain a Connection, execute SQL, and then return it back to the pool many times in the course of a request.

It is a Best Practice to only hold Connections in local variables, preferably in a try-with-resources block, or possibly passed on the stack, but never in a class member field. If you follow that pattern it is virtually impossible to leak a Connection or accidentally share across threads.