Is it possible to set up parallel transactions in JTA (Atomikos)

空扰寡人 提交于 2019-12-06 15:44:25

Yes, you can achive this. You talk about so named "nested" transaction First of all for Atomikis you must specify property com.atomikos.icatch.serial_jta_transactions=false

If you operate with TransactionManager directly you have to suspend tx1 before begining tx2 (TransactionManager.suspend()). After commiting transaction tx2 you have to resume tx1. And if there is an error while execution tx2 you must do rollback tx2, resume tx1 and rollback tx1:

Example

TransactionManager tm=...

tm.begin();
Transaction tx1 = tm.getTransaction();
//do somethins in tx1;
tm.suspend(tx1);
tm.begin();
Transaction tx2 = tm.getTransaction();

try{
  //do something in tx2
  tm.commit() ;// try to commit tx2
}cath(Throwable e){
   tx2.rollback();
   tm.resume(tx1)
   tx1.rollback();
   tx1 = null;
}

if(tx1!=null){
  tm.resume(tx1);
  tm.commit();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!