Exception thrown while @Timeout is invoked
arnosgh Jul 6, 2012 11:50 PMHi All,
I have implemented a statlessBean with Timer service. The timer is getting created without any issue, but when the @Timeout method is getting invoked I am getting the below excetion:
ERROR [org.jboss.ejb.txtimer.TimerImpl] (EJB-Timer-ee98a936-c65a-4bbb-b697-93f88ca37f1c[target=jboss.j2ee:ear=app.ear,jar=app.backend.jar,name=AssetCreationCompleteTimer,service=EJB3]) Error invoking ejbTimeout
java.lang.NullPointerException
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:597)
at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
at org.jboss.ejb3.stateless.StatelessContainer.callTimeout(StatelessContainer.java:682)
at org.jboss.ejb3.stateless.StatelessContainer.callTimeout(StatelessContainer.java:199)
at org.jboss.as.ejb3.timerservice.TimedObjectInvokerBridge.callTimeout(TimedObjectInvokerBridge.java:44)
at org.jboss.ejb.txtimer.TimerImpl$TimerTaskImpl.run(TimerImpl.java:664)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
My looks like:
@Stateless
@LocalBinding(jndiBinding = "com.app.backend.maintenance.AssetCreationCompleteTimerLocal")
public class AssetCreationCompleteTimer implements AssetCreationCompleteTimerLocal {
@PersistenceContext(unitName = "unitName")
private EntityManager entityManager;
@Resource(mappedName = "java:/JmsXA")
private QueueConnectionFactory queueConnectionFactory;
private final Logger log = LoggerFactory.getLogger(getClass());
@Resource
private SessionContext sessionContext;
@Override
public void scheduleNextExecution(Date dateToExecute, boolean isCancelExisting) {
TimerService timerService = sessionContext.getTimerService();
for (Object o : timerService.getTimers()) {
if (o instanceof Timer) {
Timer timer = (Timer) o;
// if current Date is greater than or after the existing timers next run date, cancel inactive timer
if (new Date().after(timer.getNextTimeout())) {
timer.cancel();
continue;
}
// if date to schedule next run is less than or before the existing timers next run date, cancel the current timer
// only if isCancelExisting is set to true. This done to ensure that timers don't get re-scheduled on an earlier date unless specifically intended.
if (dateToExecute.before(timer.getNextTimeout())) {
log.info(String.format("%s job is already scheduled for %tc", getClass().getSimpleName(), timer.getNextTimeout()));
if (isCancelExisting) {
log.info(String.format("Cancelling the timer for %s which was scheduled to run at %tc ...", getClass().getSimpleName(), timer.getNextTimeout()));
timer.cancel();
}
}
}
}
if (timerService.getTimers().isEmpty()) {
log.info("Creating Timer with Date {} : Class {}", dateToExecute, getClass().getSimpleName());
timerService.createTimer(dateToExecute, null);
log.info("Timer created for Class : {}", getClass().getSimpleName());
}
}
@Timeout
public void onTimeOut(Timer timer) {
log.info("Timeout triggered ....");
Calendar nextRun = Calendar.getInstance();
nextRun.add(Calendar.MINUTE, 0);
nextRun.add(Calendar.SECOND, getExecutionIntervalSeconds());
//String message = String.format("Next execution scheduled for %tc", nextRun);
log.info("Starting execution of {}", getClass().getSimpleName());
execute(); // exceute logic
}
}
My application is deployed in JBOSS 5.1.
Please help.
Regards
Arnab