我有一个通过 Internet 发送大数据的 J2EE 应用程序(weblogic、oracle)。但它遭受事务超时。所以我按照以下方式重构了应用程序:
计时器具有容器管理的事务,但回调具有 NOT_SUPPORTED 标志。
@Stateless(mappedName = "TransferTimer", name = "TransferTimer")
public class TransferTimer implements ITransferTimerLocal {
@Timeout
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void timeoutCallback(final Timer timer) {
vo = transferController.prepareTransfer();
if (vo != null) {
transferController.sendData(vo);
transferController.finishTransfer(vo);
}
..
新 bean 与 bean 管理事务一起引入。长时间运行的方法根本不处理事务和数据库:
@Stateless
@TransactionManagement(value= TransactionManagementType.BEAN)
public class TransferController implements TransferControllerLocal {
public TransferVO prepareTransfer() {
TransferVO vo = null;
try {
userTransaction.begin();
..
// no transactions must be there - it may take too much time
public void sendData(TransferVO vo) {
client.sendFile(vo.getOrder(), vo.getArchive());
}
虽然抛出 TransactionTimeout 异常,但当 client.sendFile() 成功完成时。
Caused by: weblogic.transaction.internal.TimedOutException: Transaction timed out after 61 seconds
BEA1-263D00276AD109CA0CA4
at weblogic.transaction.internal.ServerTransactionImpl.wakeUp(ServerTransactionImpl.java:1788)
at weblogic.transaction.internal.ServerTransactionManagerImpl.processTimedOutTransactions(ServerTransactionManagerImpl.java:1676)
at weblogic.transaction.internal.TransactionManagerImpl.wakeUp(TransactionManagerImpl.java:1988)
at weblogic.transaction.internal.ServerTransactionManagerImpl.wakeUp(ServerTransactionManagerImpl.java:1586)
at weblogic.transaction.internal.WLSTimer.timerExpired(WLSTimer.java:35)
我不明白。为什么会失败?