Timer problem
adamw Aug 26, 2005 5:33 PMHello,
I am using the timer service in a very simple way - starting the timer from a service POJO, and after each timeout cancelling it and starting anew. So the code looks like:
@Timeout
public void timeoutHandler(Timer timer) {
try {
(...) - do some timer-things.
// Avoiding WARN.
timer.cancel();
ctx.getTimerService().createTimer(new Date(new Date().getTime() + interval),
null);
} catch (MalformedObjectNameException e) {
e.printStackTrace();
}
}
The timer.cancel() is there to avoid getting this exception on each timeout:
22:09:34,302 WARN [TimerImpl] Timer was not registered with Tx, reseting state: [id=3target=[target=jboss.j2ee:service=EJB3,name=org.jboss.forge.service.ForgeTimer],remaining=-6872,periode=0,in_timeout]
Which is true, as I'm not using transactions at all - and I don't want to, I just don't need them. But I wanted to get rid of it from my logs and added the timer.cancel() as a user advised me to do in this post: http://www.jboss.org/index.html?module=bb&op=viewtopic&t=67977.
Everything works well but once I got the exception that is below and the timer stopped working. Any ideas what could have caused it? Maybe I shouldn't cancel the timer? How to get rid of that warning then?
13:58:46,029 ERROR [TimerImpl] Cannot register txtimer with Tx: [id=15target=[target=jboss.j2ee:service=EJB3,name=org.jboss.forge.service.ForgeTimer],remaining=-372273,periode=0,in_timeout]
13:58:46,345 ERROR [TimerServiceImpl] Cannot create txtimer
java.lang.IllegalStateException: Unable to persist timer
at org.jboss.ejb.txtimer.DatabasePersistencePolicy.insertTimer(DatabasePersistencePolicy.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
at org.jboss.mx.util.JMXInvocationHandler.invoke(JMXInvocationHandler.java:273)
at $Proxy86.insertTimer(Unknown Source)
at org.jboss.ejb.txtimer.TimerServiceImpl.createTimer(TimerServiceImpl.java:212)
at org.jboss.ejb.txtimer.TimerServiceImpl.createTimer(TimerServiceImpl.java:178)
at org.jboss.forge.service.ForgeTimer.scheduleTimer(ForgeTimer.java:29)
at org.jboss.forge.service.ForgeTimer.timeoutHandler(ForgeTimer.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:99)
at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:32)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:66)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:134)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:61)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:39)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:91)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.ejb3.stateless.StatelessContainer.callTimeout(StatelessContainer.java:96)
at org.jboss.ejb.txtimer.TimerImpl$TimerTaskImpl.run(TimerImpl.java:473)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462) Caused by: org.jboss.util.NestedSQLException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=takeshi/33, BranchQual=, localId=33]; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=takeshi/33, BranchQual=, localId=33])
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:79) at org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin.insertTimer(GeneralPurposeDatabasePersistencePlugin.java:142)
at org.jboss.ejb.txtimer.DatabasePersistencePolicy.insertTimer(DatabasePersistencePolicy.java:134)
... 37 more Caused by: javax.resource.ResourceException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=takeshi/33, BranchQual=, localId=33]
at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:331)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:462) at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:894)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:73)
... 39 more
--
Adam