Look below code:
@Stateless @Local(FidsConJob.class) public class FidsConJobBean implements FidsConJob { private Timer ConJob; public void startup() { ConJob = ctx.getTimerService().createTimer(new Date(System.currentTimeMillis()), 6000, "FidsConJob"); } @Timeout public void timeoutHandler(Timer timer) { if(timer.equals(ConJob)) System.out.println("Same timer"); else System.out.println("Different timer"); } }
11:24:09,630 INFO [STDOUT] Different timer
@Stateless @Local(FidsConJob.class) public class FidsConJobBean implements FidsConJob { private Timer ConJob; public void startup() { ConJob = ctx.getTimerService().createTimer(new Date(System.currentTimeMillis()), 6000, "FidsConJob"); } @Timeout public void timeoutHandler(Timer timer) { if(ConJob.equals(timer)) System.out.println("Same timer"); else System.out.println("Different timer"); } }
11:27:44,909 ERROR [TimerImpl] Error invoking ejbTimeout: javax.ejb.EJBException
: java.lang.NullPointerException
17.2.2 Timeout Callbacks
If the timed object needs to make use of the identity of the timer to recognize the significance of the
timer expiration, it may use the equals method to compare it with any other timer references it might
have outstanding.
17.2.4 Timer Identity
The Bean Provider cannot rely on the == operator to compare timers for ?object equality?. The Bean
Provider must use the Timer.equals(Object obj) method.