Reputation: 2297
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);
Upvotes: 0
Views: 116
Reputation: 328608
If you can use an external library, cron4j can help for that kind of complex scheduling. Probably not worth it if this is a one off.
Upvotes: 0
Reputation: 198093
The simplest solution would just be to wrap CSDelightAlertTask
in a wrapper that only runs the underlying task if and only if the time is between 0900 and 1800.
Upvotes: 4