ejb sessionbean 中的事务超时
transaction time out in ejb sessionbean
在 EJB SessionBean 中,我将事务超时设置为 3600 秒。我有一个循环代码可以使用这个 sessionbean。 3600 秒后,sessionbean 事务超时,但循环仍在工作。
我的问题是当事务超时后进入下一个循环时,是否会为sessionbean创建一个新的事务?
或者关于此处使用的交易的任何信息?
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?
视情况而定。如果例如SessionBean#do() 被注释为
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void do() { ...
然后每次调用 do() 都会打开一个新事务。
如果SessionBean#do() 被注释为
@TransactionAttribute(TransactionAttributeType.REQUIRES)
public void do() { ...
并且您的循环方法已经有一个打开的事务,因为它是这样注释的:
@TransactionAttribute(TransactionAttributeType.REQUIRES) // or REQUIRES_NEW
public void loopMethod() { ...
那么整个交易就断了。
有关交易属性,请参阅 https://docs.oracle.com/html/E13981_01/servtran002.htm
在 EJB SessionBean 中,我将事务超时设置为 3600 秒。我有一个循环代码可以使用这个 sessionbean。 3600 秒后,sessionbean 事务超时,但循环仍在工作。 我的问题是当事务超时后进入下一个循环时,是否会为sessionbean创建一个新的事务? 或者关于此处使用的交易的任何信息?
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?
视情况而定。如果例如SessionBean#do() 被注释为
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void do() { ...
然后每次调用 do() 都会打开一个新事务。
如果SessionBean#do() 被注释为
@TransactionAttribute(TransactionAttributeType.REQUIRES)
public void do() { ...
并且您的循环方法已经有一个打开的事务,因为它是这样注释的:
@TransactionAttribute(TransactionAttributeType.REQUIRES) // or REQUIRES_NEW
public void loopMethod() { ...
那么整个交易就断了。
有关交易属性,请参阅 https://docs.oracle.com/html/E13981_01/servtran002.htm