I am using ScheduledExecutorService
to run a particular task at 3 AM
in the morning everyday. Now I am not sure whether my below code will call MyTask()
every 3 AM
in the morning? As I am not sure whether my logic is right or not
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
Date aDate = ......// Current date or parsed date;
Calendar with = Calendar.getInstance();
with.setTime(aDate);
int hour = with.get(Calendar.HOUR);
int intDelayInHour = hour < 3 ? 3 - hour : 24 - (hour - 3);
scheduler.scheduleAtFixedRate(new MyTask(), intDilayInHour, 24, TimeUnit.HOURS);
And to test this out, I need to wait for one day to see if it is working out and I don't want to do that.
Can anyone help me to identify whether my above code is right or not?