Does each stacked transaction use a separate connection?

Viewed 225

I have multiple stacked transactions created by calling stacked methods with:

@Transactional(propagation = Propagation.REQUIRES_NEW)

so the result is transaction waiting for new transaction waiting for new transaction...

Do each of these transactions use a separate db connection from the connection pool, possibly starving the pool?

P.S.: I know that I shouldn't stack new transactions due to errors not rolling back all transactions, but I'm curious about the behaviour.

1 Answers

Yes, when you are using REQUIRES_NEW you will get a new transaction for every method call . New transaction means, new database connection from the pool is being used.

And yes, that means potentially starving it.

You might enjoy this database transactions book for more detailed information including lots of code examples: https://www.marcobehler.com/books/1-java-database-connections-transactions

Related