Search code examples
jakarta-eeejbwebsphere

Unable to cancel a EJB 3.0 Timer


I am trying cancel EJB timers in my application through the following code:

Collection <Timer>timers = timerService.getTimers();

System.out.println("logtimer: No of Active timers = "+timers.size());
if(timers != null){
    for (Timer timer : timers) {
        System.out.println("logtimer: About to cancel Timer "+timer.toString());
        if(timer.getInfo()!=null){
            timer.cancel();
            System.out.println("logtimer: Cancelled Timer "+timer.getInfo());
        }
    }
}

However eventhough I have 3 active timers at present the timer.getInfo() method call always returns a null. What is wrong with my code ?


Solution

  • Timer.getInfo() returns the value you specified when you created the timer (or if you used @Schedule, the info is specified via that annotation). If it returns null, that means you didn't specify a value.