Search code examples
javajakarta-eeejbapplication-server

While (true) behavior in application server


How do I achieve a while (true) like behavior with an application server?
If I need to change my persistent data every few seconds, and with each cycle, procedures A,B,C should be called:

public class Runner
{    
    List values;

    public void repeat() 
    {
        while (true)
        {
            changeSomeDataA();
            changeSomeDataB();
            changeSomeDataC();
        }
    }
}

Solution

  • Use @Schedule annotation for timer service of EJB. like

      @Schedule(second="*/3", minute="*", hour="*")
      public void automaticChangeOnTimer() {
            changeSomeDataA();
            changeSomeDataB();
            changeSomeDataC();
            logger.info("Automatic called the method");
      }
    

    For details look at following link:

    http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html