Yesterday I came across HikariCP and spent the whole night studying it. I'm really impressed with the amount of detail and effort put into fine tuning its implementation and design.
Straight to the point, I could not determine how it actually deals with connections that are checked back into the pool with their autoCommit
set to false
, while neither commit()
nor rollback()
is issued on them, for example, due to an exception. This potentially can be the source of many serious transactional problems for the next requester that expects a fresh connection but unfortunately receives this connection with its dangling transaction state.
While C3P0 and Tomcat's JDBC pool have some of these so called Knobs for this very purpose (through configuration or interception), I could not find anything in HikariCP's documentation or support group. Please correct me if I'm wrong, but writing a simple unit test showed me that the pool does nothing about this.
I need to know if this observation is actually correct and I'm not missing anything about it. Also, if there is any plan for addressing this in HikariCP since it is critical for me.
Thanks.
Summary. "HikariCP is solid high-performance JDBC connection pool. A connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required. Connection pools may significantly reduce the overall resource usage." - You can find out more here.
After inserting the outdated prices, the employee realizes that they are no longer valid and calls the Connection method rollback to undo their effects. (The method rollback aborts a transaction and restores values to what they were before the attempted update.)
Overview. Hikari is a JDBC DataSource implementation that provides a connection pooling mechanism. Compared to other implementations, it promises to be lightweight and better performing.
spring.datasource.hikari.connection-timeout=60000. Controls the maximum number of milliseconds that you will wait for setting up a connection from the pool. spring.datasource.hikari.idle-timeout=600000. Controls the maximum amount of time that a connection is allowed to sit idle in the pool.
I am one of the authors of HikariCP. HikariCP does not automatically execute either commit or rollback if auto commit is turned off. It is generally expected that an application that is turning off auto commit explicitly is prepared to properly handle these (recommended in a finally
block) -- as in this example from the official JDBC documentation.
We are willing to add automatic "rollback" behavior to HikariCP (but not automatic "commit") if a connection is returned to the pool with auto commit set to false. Please open a feature request if you wish this behavior.
UPDATE: HikariCP 1.2.2 and above perform an automatic "rollback" for closed connections with auto-commit set to 'false'. Additionally, it will reset transaction isolation level to the configured default, and as noted in comments below will of course close open Statements, etc.
UPDATE: HikariCP 2.3.x and above now additionally track transaction state when auto-commit is set to false
, and will bypass the automatic rollback operation if the transaction state is clean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With