I am using the following code as scheduler in java web deployment
public class ReportScheduler implements ServletContextListener {
private ScheduledExecutorService scheduler;
@Override
public void contextInitialized(ServletContextEvent sce) {
scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new ReportLoader(sce.getServletContext()), 0, 10, TimeUnit.SECONDS);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
scheduler.shutdownNow();
}
The ReportLoader class which implements runnable is as follows:
public class ReportLoader implements Runnable {
ServletContext context;
public ReportLoader(ServletContext context) {
System.out.println("1");
this.context = context;
StartUp();
}
private void StartUp() {
System.out.println("start");
(new Thread(this)).start();
}
@Override
public void run() {
System.out.println("scheduled");
try {
//Files.delete(path);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
But my Scheduler does not seem to be working as nothing is getting printed on the tomcat (which is my server) log, as one would expect to.
Is there any mistake that i am making, or something more that i need to ensure so that the scheduler works properly ?
The intention of the scheduler is to delete folders at regular intervals on the local PC.