how to share one transaction between multi threads

前端 未结 1 1428
孤街浪徒
孤街浪徒 2021-01-02 07:03

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 datab

相关标签:
1条回答
  • 2021-01-02 07:34

    "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.

    0 讨论(0)
提交回复
热议问题