Back Forum Reply New

Spring JTA share TX multiple threads

I'm using declarative transaction demarcation with Spring. My TX manager is set to JTA.

I have a method which runs inside a transaction. It has the @Transactional annotation.
This method creates on its turn several new threads.
Finally it will block until all threads are processed, then it returns.

Each of the created threads must run inside a transaction.
They also have the @Transactional annotation set, but this time the attribute on requires_new.

This works great. However, I was thinking, suppose I want to make those threads participate in the already existing 'outer' transaction.
This way I have one single  transaction and I just use threading to speed things up.
But any failure in any thread would result in the TX to be rolled back.

Ok; so I tried setting the TX attributes for the threads  on 'required' : nothing,  the threads still kept working in their own transaction.

When you think of it, it makes sense that the TX manager  creates a new transaction for each thread.
How would the  TX manager be able to distinguish my application thread against a quot;realquot; quot;new requestquot; thread?

Besides the fact that I have a clue why its like this; is there a way to change this?

Using EJBs you do have this option, since invoking another SLSBs shares the transaction context.
And normally other SLSBs could be working inside another thread.
Well I don't know about local SLSBs, but it sure is for remote ones.
(I also agree that  corba deals with the TX stuff in the latter case, so that is something else then simply two different threads...)

So the question is; is there a way to 'share' my transaction over multiple threads?

No body ?                                                       .
¥
Back Forum Reply New