I’ve seen many answers on this topic but still can’t find a clean solution.
public class ProcessScheduler {
static {
Timer timer=new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
LogProcessorServiceImpl.processPageRequestsLogs();
}
}, 0, 120);
}
}
How do I make this execute and be happy with quality solution? My application is based on Spring (unfortunately) and I know I can reference this class in one of my controllers and it’d probably work. But that’s silly. There just must be a better way. I’m on Tomcat with no EJB support, so timer annotation will not work for me. Also, I don’t want to do CRON. I want to schedule all my maintenance tasks within this scheduler class.
Servlet classes can be loaded via web.xml (1). Can we do something similar on non-servlet classes?
Instead of writing this in a static block, I would prefer to
javax.servlet.ServletContextListenercontextInitializedmethodcontextDestroyedmethod to cancel the timerconfigure the class as
<listener>inweb.xmlfile for my application.