Oct 4th, 2011, 03:10 PM
Does Spring TransactionTemplate create threads?
I've got a problem with a corrupted data structure due to concurrent access. I'm trying to rule out possible causes, but I'm not sure how the Spring TransactionTemplate works.
There are multiple threads passing independent lists to the constructor of a CallbackHandler. This CallbackHandler is then passed to the execute method of the TransactionTemplate. There are no synchronized blocks anywhere.
The list is accessed in the CallbackHandler and from the calling Thread before and after the execute method has finished. As far as I understand calling execute DOESN'T start a new Thread. Therefor this should be safe.
Every thread creates its own independent list and CallbackHandler, only the TransactionTemplate is the same for all.
Or does Spring create some new thread at some point?
Oct 4th, 2011, 10:26 PM
In my opinion Spring does not create threads unless explicitly asked to. As far as transaction are concerned am pretty sure that Spring will not create new threads as context information required for a transaction will be lost at it is stored in thread local variables.
Oct 5th, 2011, 01:18 AM
Spring doesn't create new threads unless explicitly asked to do so. Next to that the TransactionTemplate, once constructed, is thread safe.
Check your transaction settings and also be aware of the fact that a single transaction is bound to a thread, so if you expect all threads to participate in the SAME transaction that isn't going to work...
Tags for this Thread