I have some trouble using timers and timertasks... Heres the problem -
I have a class that implements TimerTask. A
test code creates some Timer objects and calls schedule() with this TimerTask object. It goes something like this -
public void doIt() {
// _timer.cancel(); //NOTE : THIS LINE DOESNT SEEM TO IMPACT ANYTHING
//Re-start the timer.
_timer = null;
_timer = new Timer();
_timer.schedule(timertask, _timeout);
}
Now, if i call this doIt() method a couple of times, I get an
IllegalStateException saying the timer is already cancelled (if i pass the same timertask object every time).
My understanding is that, if I create new Timer objects every time, and call schedule on the same timertask object, it shouldnt complain. Help me get rid of this exception.
Thanks
Karthik.