Hello, I am creating an application that will execute a block of code at certain periods of time (for example, every 30 minutes). I would like this period to be strict, I mean that I would like to be sure that the period will be 30 minutes, not 28 minutes or whenever os wants to execute it.
I have a Timer object and use it like this:
timer=new Timer();
timer.scheduleAtFixedRate(new GetLastLocation(), 0, this.getInterval());
where GetLastLocation is a handler class that extends TimerTask. This works great, but I would like to change the interval, what I am doing now, using timer.scheduleAtFixedRate twice and changing the interval parameter to say newInterval, but I think it’s just having two timers running each interval and a new interval now, I right?
I also try to cancel the timer and then use the scheduleAtFixedRate () method, but this throws an exception, as indicated in the documentation.
what can i do to fix this? welcomes maxsap
source
share