I have a ScheduledExecutorService and I do a task every 15 mins (in a web application in Tomcat).
In a ServletContextListener in contextDestroyed I have done:
Runtime.getRuntime().addShutdownHook(new Thread(){ @Override public void run(){ scheduler.shutdown(); } }); The scheduler is started like:
final Runnable r = new Runnable(){ @Override public void run() { System.out.println("My task"); //Do some task } }; updater.scheduleWithFixedDelay(r, 30, 15, TimeUnit.MINUTES); Question:On shutdown any remaining task isn't executed.
There is a task running but I don't see any logs so it seems it is not executed. Why?
UPDATE:
If I start tomcat and then after 2 mins I shutdown then isn't the task considered as scheduled and must run? I mean if a task is submitted isn't it considered as pending? Or it must be actually running?