How can I disable all schedulers (@Schedule annotated) in a project deploing on Glassfish 3.1
Maybe there are some config entries to do this?
I have about 20 EJBs with schedulers in my project and if I want to test/fix a small thing I don't want that all/some timer start.
unfortunately I don't know if there are some config entries to solve your problem, but there is a programatical way to do so, by calling the cancel()-method on Timer-Objects provided by TimerService.
Here's an example of a class I simply put into projects when I want to test only small things:
@Stateless
public class ScheduleCancellation {
@Resource
private TimerService timerService;
@Schedule(second = "0", minute = "*", hour = "*")
public void cancelTimers() {
System.out.println("cancelTimers()");
for (Timer timer : timerService.getTimers()) {
System.out.println("schedule gone!");
timer.cancel();
}
}
@Schedule(second = "*", minute = "*", hour = "*")
public void tick() {
System.out.println("tick");
}
}
Hope this helps! :)
Accessing TimerService#getTimers()
will only return timers for this particular EJB. There is no standardized way to access all the timers in the container (actually, here is an enhancement request: http://java.net/jira/browse/EJB_SPEC-47).
I guess you'd need to use some Glassfish proprietary solution and fiddle with their internals (if it's even possible). I'd ask on GlassFish mailing list if I were you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With