I would like to restart my timer when I receive a KeepAlive, the problem is that sometimes it doesn't restart, instead of that it creates a new one, so, finally the timer reaches the limit:
public class KeepAliveTimer {
long macAddress;
Timer timer;
String ip;
public KeepAliveTimer(long mac, String ipAddress){
this.macAddress = mac;
this.ip = ipAddress;
timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
timerFinished();
}
};
timer.schedule(timerTask, 10*60*1000);
}
public void update() {
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
timerFinished();
}
};
timer.cancel();
timer.purge();
timer = new Timer();
timer.schedule(timerTask, 10*60*1000);
}
public void timerFinished() {
//tasks
}
}
The object KeepAliveTimer is created when received the first keepAlive and updated by following ones