title: Java EJB Modify Schedule Property Values At Runtime
body: <p>I have a Singleton class in Java and I have a timer using the @Schedule annotation. I wish to change the property of the Schedule at runtime. Below is the code:</p>
  
  <pre><code>@Startup
  @Singleton
  public class Listener {
  
     public void setProperty() {
         Method[] methods = this.getClass().getDeclaredMethods();
         Method method = methods[0];
         Annotation[] annotations = method.getDeclaredAnnotations();
         Annotation annotation = annotations[0];
         if(annotation instanceof Schedule) {
              Schedule schedule = (Schedule) annotation;
              System.out.println(schedule.second());
         }
     }
  
      @PostConstruct
      public void runAtStartUp() {
           setProperty();
      }
  
     @Schedule(second = "3")
     public void run() {
         // do something
     }
  }
  </code></pre>
  
  <p>I wish to change the value at runtime of Schedule second based on the information from a Property file. Is this actually possibe? The Property file contains the configuration information. I tried to do @Schedule(second = SOME_VARIABLE) where private static String SOME_VARIABLE = readFromConfigFile(); This does not work. It expects a constant meaning a final and I don't want to set final.</p>
  
  <p>I also saw this post: <a href="https://stackoverflow.com/questions/3062110/modifying-annotation-attribute-value-at-runtime-in-java">Modifying annotation attribute value at runtime in java</a></p>
  
  <p>It shows this is not possible to do.</p>
  
  <p>Any ideas?</p>
  
  <p>EDIT:</p>
  
  <pre><code>@Startup
  @Singleton
  public class Listener {
      javax.annotation.@Resource // the issue is this
      private javax.ejb.TimerService timerService;
      private static String SOME_VARIABLE = null;
  
      @PostConstruct
      public void runAtStartUp() {
           SOME_VARIABLE = readFromFile();
           timerService.createTimer(new Date(), TimeUnit.SECONDS.toMillis(Long.parse(SOME_VARIABLE)), null);
      }
  
      @Timeout
      public void check(Timer timer) {
          // some code runs every SOME_VARIABLE as seconds
      }
  }
  </code></pre>
  
  <p>The issue is injecting using @Resource. How can this be fixed?</p>
  
  <p>The Exception is shown below:</p>
  
  <pre><code>No EJBContainer provider available The following providers: org.glassfish.ejb.embedded.EJBContainerProviderImpl Returned null from createEJBContainer call
  javax.ejb.EJBException
  org.glassfish.ejb.embedded.EJBContainerProviderImpl
  at javax.ejb.embeddable.EJBContainer.reportError(EJBContainer.java:186)
  at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:121)
  at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:78)
  
  @BeforeClass
  public void setUpClass() throws Exception {
      Container container = EJBContainer.createEJBContainer();
  }
  </code></pre>
  
  <p>This occurs during unit testing using the Embeddable EJB Container. Some of the Apache Maven code is located on this post: <a href="https://stackoverflow.com/questions/22938746/java-ejb-jndi-beans-lookup-failed">Java EJB JNDI Beans Lookup Failed</a></p>