Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling all schedules in Glassfish 3.1

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.

like image 528
alexblum Avatar asked Oct 08 '22 22:10

alexblum


2 Answers

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! :)

like image 179
Mr. Rabbit Avatar answered Oct 13 '22 01:10

Mr. Rabbit


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.

like image 20
Piotr Nowicki Avatar answered Oct 13 '22 02:10

Piotr Nowicki