In my code i m trying to write a task which should be triggered every 24 h. The first trigger should be when the timer is scheduled and then every 7 in the morning. I m using
Calendar today = Calendar.getInstance();
timer.schedule(task1, today.getTime(), TimeUnit.MILLISECONDS.convert(24, TimeUnit.HOURS));
Your are providing
07:00:00 of the current day (not the next day) as
So if the time is after 7am, your
firstTime is in the past. Probably this is why the task is started immediately.
If the time is "after midnight" which is probably before 7am, the
firstTime is in the future. So you have to wait for 7am for the task to start.