When I'm recreating a timer, it hangs on the scheduleAtFixedRate() function. (modified) code snippets:
This is my timertask (code snippet A):
public static TimerTask taskiPollRequest = new TimerTask() {
public void run() {
if (this.scheduledExecutionTime() < System.currentTimeMillis() + 500) {
Dosomethinghere();
}
}
};
I create my timer like this (code snippet B):
if(myTimer == null) {
myTimer = new Timer();
}
myTimer.scheduleAtFixedRate(
taskiPollRequest, 0, 30*1000);
when I no longer need the timer, I call: myTimer.cancel; myTimer = null;
then when I need it again, i call code snippet B again. but it hangs on scheduleAtFixedRate().
any ideas? please help. thanks.