Jta transcations

I have code for jta transactions as follows:

try{
  //start jta user transcation utx


//commit utx

}catch(Exception ex){
   try{
     //rollback utx
   }catch(Exception){
    //print error "cannot rollback
   }
}
finally{
  if(null != utx && utx.getStatus() == Status.STATUS_ACTIVE){
                    utx.commit();
  }
}

I do not understand why utx is committed at the end?

+3
source share
2 answers

The end in the block finallyis called only if the status of the transaction STATUS_ACTIVE, that is, it has not been fixed and not canceled. it looks like security to ensure that the transaction is either canceled or committed at the end of the method, in case it utx.commit()was forgotten in the try block of the method.

+4
source

, ​​ finally . , . ACTIVE.

.

,

+1

Source: https://habr.com/ru/post/1776686/


All Articles