-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Need to know transaction.isReadonly while getting connection - spring-jdbc #25323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Is it safe to reuse connection across threads? |
for readonly operations, it is. |
It depends on driver implementation. |
At least, as I tested, oracle, mysql, pgsql are no problem. |
further more, no matter share connection is safe or not, let developers can get the readonly property as earlier as possible is a good manner. Developers may use the readonly property for other purpos. |
So, what's the decision? will you adopt the change request? |
The PR has been declined, reopening to reconsider this. |
Backgroup: I have a large project with more than 500 nodes need to connection to one Database, so connection count is too high. In order to reduce db connections, I want to reuse one connection for all readonly transactions. So, I need to get the "TransactionSynchronizationManager.isCurrentTransactionReadOnly()" in Datasource.getConnection() method. While, in spring-jdbc-5.2.2, DataSourceTransactionManager.doBegin method, the connection is gotten at line 263, the readonly flag is setted at line 298.
Suggestion: Set the readonly flag before getting connection. e.g. in DataSourceTransactionManager.doBegin method
Then I will override a Datasource, that, return one shared connection to all readonly transactions.
The text was updated successfully, but these errors were encountered: