We meet an scenario that works with multi thread.
In the main Thread, do some logic and update the database, in a point, it will call another service to update database, which is run in another Thread.
We want the two Threads share the same transaction, that means, either operation in either Thread fails, then the operation in another Thread will also be rolled back.
But work for several days, I found some posts say JTA does not support the multi Thread. currently we use Bitronix as the JTA provider, is there any body know if Bitronix support the multi thread in one Transaction? or is there any other JTA provider support this(standalone JTA provider not J2EE container)?
"Multiple threads may concurrently be associated with the same global transaction." - JTA spec v1.1, section 3.2, page 13.
JBossTS will handle that no problem. Checked transaction behaviour aside, the difficulty is not really the transaction manager though. You also need correct handling of the connection(s) to the resource manager i.e. database. If you share one connection between the threads you don't necessarily get any speedup over running serially, as it's a potential bottleneck unless the driver supports efficient multiplexing. On the other hand if you use multiple connections you need to ensure the driver is going to implement isSameRM sensibly to avoid 2PC and also allow transaction branch lock sharing (close coupling) if the Threads need to see one another's uncommitted changes to the db. So in addition to a good transaction manager you're going to need a good connection manager e.g. JCA implementation and a good database driver. Good luck finding those.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With