This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

One transaction per multiple threads

Jan 11th, 2012, 07:47 AM

The problem is as follows:
I need to start "global" transaction in certain "main" thread.
Then a few "child" threads started in "main" thread and all of these threads share that "global" transaction.
Main thread waits until each of child thread finishes and then commits (or rollbacks) the changes made in the child threads.

Unfortunately neither the task can be simplified and made single threaded nor the specific changes can be made in data schema, e.g. adding 'validity' flags to the tables the mentioned threads operating with.

I guess it's possible in JTA as the spec says "Multiple threads may concurrently be associated with the same global transaction." - JTA 1.1, section 3.2, page 13.

My application is deployed on a pretty ordinary servlet container (Jetty) and one transaction manager is used - DataSourceTransactionManager.
DB is Oracle (and AFAIK it does support nested transaction so the "shared" transaction is possible, at least theoretically).

Could you please point me to the right direction?
Any help is greatly appreciated.

Comment

After digging deeper at this question I decided to refuse this architecture and rather prepare to face potential performance problem and if facing one deal with it in another, less complicated way being with the pretty standard approach to transactions management