In EJB SessionBean, I set the transaction time out to 3600 seconds. And I have a loop code which may use this sessionbean. After 3600 seconds, the sessionbean is transaction time out, but the loop is still working. My question is that when go to the next loop after the transaction time out, will a new transaction for sessionbean be created? Or any information about the transaction used here?
SessionBean xx = ...;
while(...){ // This loop may be a long time more than 3600s
try{
xx.do();
}catch(Exception e){
}
}
// if xx is transaction time out, the while loop is still working, then will a new transaction for xx be created?
It depends. If e.g. SessionBean#do() is annotated with
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void do() { ...
then for each call of do() a new transaction will be opened.
If e.g. SessionBean#do() is annotated with
@TransactionAttribute(TransactionAttributeType.REQUIRES)
public void do() { ...
and your loop-method has already an open transaction, because it is annotated like this:
@TransactionAttribute(TransactionAttributeType.REQUIRES) // or REQUIRES_NEW
public void loopMethod() { ...
then the whole transaction is broken.
For TransactionAttributes see https://docs.oracle.com/html/E13981_01/servtran002.htm