我在单个bean中使用以下@Schdule注释每分钟打勾一个自动收报机方法:
@Schedule(minute = "*/1", hour = "*", persistent = false)
public void tick() {
for (ScheduledTask scheduledTask : scheduledTasks) {
logger.info("Start Task [" + scheduledTask.toString() + "]");
taskHandler.handleScheduledTask(scheduledTask);
}
}
其中taskHandler是另一个单一bean,以下是handleScheduledTask方法:
@Override
@Asynchronous
public void handleScheduledTask(ScheduledTask task) {
.
.
.
// handle the scheduled task ....
.
}
但是,有时候滴答方法可能会在2分钟后调用。在这种情况下,服务器日志中出现以下错误,并且不再调用tick方法
Exception occurred during commit of transaction Name=[EJB com.edafa.scheduler.Scheduler.tick()],
Xid=BEA1-4A8475B5C0D922F29728(1717681887), Status=Rolled back.
[Reason=javax.transaction.SystemException: Timed out while in 'Logging' state],
numRepliesOwedMe=0,numRepliesOwedOthers=0,seconds since begin=93,seconds left=30,
XAServerResourceInfo[WLStore_web2sms_domain__WLS_Web2SMS-Core_mServer]=(
ServerResourceInfo[WLStore_web2sms_domain__WLS_Web2SMS-Core_mServer]=
(state=rolledback,assigned=Web2SMS-Core_mServer),
xar=WLStore_web2sms_domain__WLS_Web2SMS-Core_mServer1769014156,
re-Registered = false),
XAServerResourceInfo[Web2SMS-DB_web2sms_domain]=(
ServerResourceInfo[Web2SMS-DB_web2sms_domain]=(state=rolledback,assigned=Web2SMS-Core_mServer),
xar=weblogic.jdbc.wrapper.JTSEmulateXAResourceImpl@4d91c7c5,re-Registered = false),
SCInfo[web2sms_domain+Web2SMS-Core_mServer]=(state=rolledback),
properties=({weblogic.jdbc.remote.Web2SMS-DB=t3://172.23.250.74:3574,
weblogic.transaction.name=[EJB com.edafa.scheduler.Scheduler.tick()]}),
OwnerTransactionManager=ServerTM[ServerCoordinatorDescriptor=(
CoordinatorURL=Web2SMS-Core_mServer+172.23.250.74:3574+web2sms_domain+t3+,
XAResources={
WSATGatewayRM_Web2SMS-Core_mServer_web2sms_domain,
WLStore_web2sms_domain__WLS_Web2SMS-Core_mServer,
Web2SMS-DB_web2sms_domain, Web2SMS-SMSGW-DB_web2sms_domain, ALARMS_DB_web2sms_domain
},
NonXAResources={})],
CoordinatorURL=Web2SMS-Core_mServer+172.23.250.74:3574+web2sms_domain+t3+):
weblogic.transaction.RollbackException: Timed out while in 'Logging' state
at weblogic.transaction.internal.TransactionImpl.throwRollbackException(TransactionImpl.java:1878)
at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:359)
at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:250)
at weblogic.ejb.container.internal.BaseLocalObject.postInvoke1(BaseLocalObject.java:336)
at weblogic.ejb.container.internal.BaseLocalObject.postInvoke(BaseLocalObject.java:436)
at weblogic.ejb.container.internal.TimerDrivenLocalObject.postInvoke(TimerDrivenLocalObject.java:58)
at weblogic.ejb.container.timer.TimerImpl.timerExpired(TimerImpl.java:517)
at weblogic.timers.internal.TimerImpl.run(TimerImpl.java:304)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:550)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
Caused by: javax.transaction.SystemException: Timed out while in 'Logging' state
at weblogic.transaction.internal.ServerTransactionImpl.wakeUp(ServerTransactionImpl.java:1842)
at weblogic.transaction.internal.ServerTransactionManagerImpl.processTimedOutTransactions(ServerTransactionManagerImpl.java:1690)
at org.glassfish.transaction.TransactionManagerImplCommon.wakeUp(TransactionManagerImplCommon.java:1159)
at weblogic.transaction.internal.ServerTransactionManagerImpl.wakeUp(ServerTransactionManagerImpl.java:1603)
at weblogic.transaction.internal.WLSTimer.timerExpired(WLSTimer.java:20)
... 4 more
&GT。
答案 0 :(得分:1)
我通过保留调度程序计时器解决了这个问题:
@Schedule(minute = "*/1", hour = "*", persistent = true)
public void tick() {
for (ScheduledTask scheduledTask : scheduledTasks) {
logger.info("Start Task [" + scheduledTask.toString() + "]");
taskHandler.handleScheduledTask(scheduledTask);
}
}
到目前为止,这解决了问题并且每分钟执行tick方法