thorntail

Quartz scheduler thorntail


I am new to thorntail. I have integrated quartz in thorntail and able to hit it as REST API. But can I store the scheduler information in context so that scheduler runs once the application is up instead of hitting a URL to run it? Please correct me if I am wrong .


Solution

  • The question doesn't have much details, but if I understand you correctly, you want to run some code when the application starts. There are at least these 2 ways how to do it:

    1. Using CDI, create an @ApplicationScoped bean with an observer for the @Initialized(ApplicationScoped.class) event:

      @ApplicationScoped
      public class Initializer {
          public void init(@Observes @Initialized(ApplicationScoped.class) Object event) {
              ...
          }
      }
      

      This requires the io.thorntail:cdi fraction.

    2. Using EJB, create a @Singleton @Startup EJB and add a @PostConstruct method:

      @Singleton
      @Startup
      public class Initializer {
          @PostConstruct
          public void init() {
              ...
          }
      }
      

      This requires the io.thorntail:ejb fraction.

    I assume you already use CDI, so the 1st variant is probably preferable.