[jboss-user] [Beginners Corner] - Re: Can you have an app run every 5 minutes?

hamffjs do-not-reply at jboss.com
Wed Jul 26 16:46:27 EDT 2006


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.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961132#3961132

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961132



More information about the jboss-user mailing list