Reputation: 2202
Can you correct me how does it works? Method marked with transaction annotation. Is DB transaction opened and commited both with spring transaction when it is intercepted. Also are all associated resources in DB stays locked while such method is not completed. For example in transactional method I got some entities from DB, then multiple times updated or removed some of them. This all is happening in spring transaction and DB transaction happens only at the end of transactional method with necessary locks??? What if the method will hang, for example deadlock, will the locked resources stay locked for others in DB? As I see yes..
DB (postgresql) state:
30179 | username | 00:23:05.688157 | IDLE in transaction
6739 | username | 00:23:13.02717 | IDLE in transaction
6748 | username | 00:23:15.266922 | IDLE in transaction
25595 | username | 00:23:22.382349 | IDLE in transaction
25595 | username | 00:23:22.382349 | IDLE in transaction
All of them held locks (23, 21, 20, 5, 6). How this could happen? I have not long operations. Only deadlocks :D But this shouldn't happen!! So as I see some transactional method hang, but resources stayed locked, this caused others or next transactions to stop, waiting for locked resources and all system at some moment stopped working...
Upvotes: 2
Views: 1108
Reputation: 120871
That all has nothing to do with spring, it are "normal" transactions.
What a transaction exact mean, strongly depends on the transaction isolation level you use.
If "you" enter a method anntoated with @Transactional
, a tranaction at DB level it started (or at least if the next sql statement is executed). The transaction is commited when you leave that method.
The @Transactional
annotation has a parameter to controll what should be done if there is allready a transaction for the current thread.
Upvotes: 1