2 Replies Latest reply on Jul 27, 2006 5:20 AM by jaikiran

    Can you have an app run every 5 minutes?

    ericchile

      I am new to JBoss, but I have experance with Tomcat and Struts. I have also played with webservices, jsf, and session beans.

      I have some standalone code that works well that is written in Java. Is it possiable to convert this code so that it can be deployed in a war file and ran automaticly every 5 minutes?

      I know it could be done with a cron job, but we would like to keep all the appliacations in the same area. thanks

        • 1. Re: Can you have an app run every 5 minutes?
          hamffjs

          I don't know if it would be the best approach, but you do set up a Servlet that loads on startup and schedules a TimerTask instance using a Timer instance.

          For example, in the init method of your Servlet

          public void init() throws ServletException {
          Timer timer = new Timer();
          // This class needs to extend the abstract TimerTask class
          // The code to be executed needs to put in the public void run() method
          RepeatableTask repeatableTask = new RepeatableTask();

          long interval = 1000 * 60 * 5; // 5 minutes in millis

          // this will cause the task start immediately and repeat every 5 minutes
          timer.scheduleAtFixedRate(repeatableTask, 0, interval);
          }

          Hope that helps.

          • 2. Re: Can you have an app run every 5 minutes?
            jaikiran

            You can use a Scheduler(which is nothing but an MBean) in JBoss. The Scheduler will act like a service and will be started when you start jboss. You can configure the Scheduler to invoke your class every 'x' mins.

            Have a look at:

            http://wiki.jboss.org/wiki/Wiki.jsp?page=Scheduler