I have following code which call a task after every 20 min and its working fine. Now above this i want that it only work between 0900 to 1800
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleWithFixedDelay(new CSDelightAlertTask(), 0, 20, TimeUnit.MINUTES);
The simplest solution would just be to wrap
CSDelightAlertTaskin a wrapper that only runs the underlying task if and only if the time is between 0900 and 1800.