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?
You can view the source code for
TransactionTemplatehere.As you can see, no new threads are created.
Are you sure your thread safety bug doesn’t lie in another area of the code? Perhaps it would be helpful to see some examples of what you are doing.