-1

I need your help. I use hikariCP for pool connection and i get someone throuble when i create a query to DB. Connection is established and at DB occur process but response timeline is long about two hours and i want close connection manually. I set timeout config.setConnectionTimeout(TimeUnit.MINUTES.toMillis(2L)); but it not help. It set time for try to connection only but not set time for query and time to get response. How i can manually close connection ?

Porty
  • 19
  • 6

1 Answers1

0

I am still unclear what you are trying to do.

If you want the query to timeout, call Statement.setQueryTimeout() before your long query.

If you simply want the connection to actually be closed when you call Connection.close(), rather than returning to the pool, with such a long query that is going to happen already.

Why? Because the default maxLifetime is 30 minutes. So, if you get a connection from HikariCP and use it for 2 hours, it is going to be well past its lifetime. Therefore, when you call Connection.close() HikariCP will immediately evict it from the pool (i.e. close the actual DB connection).

brettw
  • 9,718
  • 2
  • 37
  • 52