Schedule the same task for different time interval

368 Views Asked by At

Is it possible to schedule one task for different time intervals? Here is the fixed interval example:

Timer gTimer = new Timer();
Calendar startDate = Calendar.getInstance();

startDate.set(Calendar.HOUR_OF_DAY, 9);
startDate.set(Calendar.MINUTE, 45);
startDate.set(Calendar.SECOND, 00);

ScheduleClass scheduleClass = new ScheduleClass();
gTimer.schedule(scheduleClass, startDate.getTime(), 1000 * 60 * 2); //interval is 2 minutes

This snippet of the scheduleClass has the run function and it is successful to run every 2 minutes. My question is: How can I set the interval to every 2, 5 and 7 minutes?

When I copy the scheduler three times it throws this error:

SEVERE: StandardWrapper.Throwable

java.lang.IllegalStateException: Task already scheduled or cancelled`

All suggestions are welcome!

0

There are 0 best solutions below