0
votes

Consider a Transaction, which takes a long time. During that I would like to execute few small updates on TableSmall, which should be executed instantly and rollback of the main Transaction shouldn't rollback those small updates.

My current problem is that these small updates will lock the TableSmall\ until completion of the Transaction. I need to be able to continue updating the TableSmall even when the Transaction is still running.

Is it okay to annotate the small updates with @Transactional(propagation = Propagation.REQUIRES_NEW) to avoid locking rows/tables of these small updates?

1

1 Answers

0
votes

From documentation.

Create a new transaction, suspending the current transaction if one exists.Analogous to the EJB transaction attribute of the same name.

NOTE: Actual transaction suspension will not work out-of-the-boxon all transaction managers. This in particular applies to org.springframework.transaction.jta.JtaTransactionManager,which requires the javax.transaction.TransactionManager to bemade available it to it (which is server-specific in standard Java EE).

A PROPAGATION_REQUIRES_NEW scope always defines its owntransaction synchronizations. Existing synchronizations will be suspendedand resumed appropriately.

So I think if you run these small updates in only one thread instance, it should works for you like you expect.

Consider also @Transactional(propagation=NESTED) for the small tasks. This link is also interesting.

I was getting locks because in a multithread enviroment, we were calling more than one this method and then the result was that all our transactions were suspended.