Adams answers correctly for money. If you end up rolling on your own (rather than walking the quartz path), you want to kick things into the ServletContextListener . Here's an example using java.util.Timer, which is a more or less dumb version of ScheduledExexutorPool.
public class TimerTaskServletContextListener implements ServletContextListener { private Timer timer; public void contextDestroyed( ServletContextEvent sce ) { if (timer != null) { timer.cancel(); } } public void contextInitialized( ServletContextEvent sce ) { Timer timer = new Timer(); TimerTask myTask = new TimerTask() { @Override public void run() { System.out.println("I'm doing awesome stuff right now."); } }; long delay = 0; long period = 10 * 1000;
And this happens in your web.xml
<listener> <listener-class>com.TimerTaskServletContextListener</listener-class> </listener>
Just more food for thought!
Greg case
source share