How should I cancel EAP5 ejb3 timers whenever the server performs a shutdown?

Solution Verified - Updated -

Issue

I am trying to cancel EAP5 ejb3 timers whenever the server performs a shutdown

I have tried to create the following eap5 timer with a cancel in a @PreDestro annotated method ie:

@Stateless
@Depends({ "jboss.ejb:service=EJBTimerService" })
public class MyEAP5TimerBean implements MyEAP5TimerLocal {

    private static final String INFO = MyEAP5TimerBean.class.getName();

    static final AtomicLong counter = new AtomicLong();

    private static final Logger log = Logger.getLogger(MyEAP5TimerBean.class);

    @Resource
    private SessionContext sessionCtx;

    @Override
    public void startTimer() {
        TimerService timerService = sessionCtx.getTimerService();
        log.info(INFO + " timerService=" + timerService);
        timerService.createTimer(5000L, 5000L, INFO);
        log.info("created timer " + INFO);
    }

    @PreDestroy
    public void stopTimer() {
        TimerService timerService = sessionCtx.getTimerService();
        log.info(INFO + " timerService=" + timerService);
        Collection<Timer> timers = timerService.getTimers();
        for (Timer timer : timers) {
            if (timer.equals(INFO)) {
                timer.cancel();
                log.info("cancelled timer " + INFO);
            }
        }
    }

    @Timeout
    public void ejbTimeout(Timer timer) {
        long value = counter.incrementAndGet();
        log.info("timer " + INFO + " " + value);
    }

}

But this does not work.

Environment

Red Hat JBoss Enterprise Application Platform 5.2.0

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content