这里我有一段代码由EJB Timer触发,在JBoss EAP 6.2上部署的EAR中运行。
由于onTimeout(Timer timer)
方法中的处理可能比standalone.xml中指定的默认事务超时要长得多,因此我想出了这个解决方案:
//[...]
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import org.jboss.ejb3.annotation.TransactionTimeout;
//[...]
@Startup
@Singleton
public class DataqReaderServiceImpl extends AbstractDataqReaderService {
@Resource
private TimerService timerService;
@Override
@Timeout
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@TransactionTimeout(unit = TimeUnit.MINUTES, value = 60)
protected void onTimeout(Timer timer) {
try {
super.readDataq(timer);
} catch (Exception e) {
timer.cancel();
}
}
}
//[...]
但是,@TransactionTimeout
注释显然会被忽略。代码运行5分钟后,Transaction Reaper即可生效:
2016-12-19 15:12:21,878 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff0a07065b:296fc7c:5857e084:67ef in state RUN
2016-12-19 15:12:21,881 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012095: Abort of action id 0:ffff0a07065b:296fc7c:5857e084:67ef invoked while multiple threads active within it.
2016-12-19 15:12:21,881 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012108: CheckedAction::check - atomic action 0:ffff0a07065b:296fc7c:5857e084:67ef aborting with 1 threads active!
2016-12-19 15:12:21,882 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012121: TransactionReaper::doCancellations worker Thread[Transaction Reaper Worker 0,5,main] successfully canceled TX 0:ffff0a07065b:296fc7c:5857e084:67ef
我的错误在哪儿?
答案 0 :(得分:0)
在尝试了一些后,我发现这似乎是RedHat JBoss EAP 6.2中的一个错误。
这是交易在EAP 6.2.0上开始的地方的跟踪:
2016-12-20 07:21:29,754 TRACE [com.arjuna.ats.arjuna] (EJB default - 10) TransactionReaper::insert ( BasicAction: 0:ffff0a07065b:-60e989f1:5858dbac:45 status: ActionStatus.RUNNING, 300 )
2016-12-20 07:21:29,754 TRACE [com.arjuna.ats.arjuna] (EJB default - 10) ReaperElement::ReaperElement ( BasicAction: 0:ffff0a07065b:-60e989f1:5858dbac:45 status: ActionStatus.RUNNING, 300 )
为TransactionReaper :: insert记录的第二个参数是超时值。
现在这是同一事件的tracelog,但是在EAP 6.4.8上(我验证了6.2.0和6.4.8实例中的默认超时设置为300秒):
09:12:52,913 TRACE [com.arjuna.ats.arjuna] (EJB default - 8) TransactionReaper::insert ( BasicAction: 0:ffff0a076537:-1ab57a18:5858f5d6:31 status: ActionStatus.RUNNING, 3600 )
09:12:52,913 TRACE [com.arjuna.ats.arjuna] (EJB default - 8) ReaperElement::ReaperElement ( BasicAction: 0:ffff0a076537:-1ab57a18:5858f5d6:31 status: ActionStatus.RUNNING, 3600 )
因此,在EAP 6.4.8上使用正确的超时值启动事务。