On 19/07/18 20:28, Gordon Sim wrote:
On 19/07/18 16:11, Kim van der Riet wrote:
The TimerTask class has two methods which change and/or set the time
when the timer will fire. Both methods assume a timer period has been
set when the task was originally created.
setUpNextFire() is called *after* the timer has already fired, and
allows the task to be fired again for the same period as originally used.
restart() is called *before* the timer has fired, and resets the timer
so that the original period is restarted from the moment of the call,
effectively delaying the firing.
Currently, the setUpNextFire() method checks that the timer has in
fact fired, and that the period has been set before allowing the
nextFireTime to be set for a future time.
However, the restart() method makes no equivalent check, and allows
the nextFireTime to be moved forward irrespective of the state of the
timer. Surely this method needs to check that the timer has *not yet*
fired before allowing the nextFireTime to be moved forward? I am
looking at a multithreaded case right now where the timer is allowing
a restart() to occur *after* the timer has moved from state WAITING to
state CALLING, ie the timer has fired.
It seems to me that a check similar to that used in setUpNextFire()
should be present in restart(). The conditions under which it reports
an error if it should be illegally called is debatable, however.
Not sure what the intention was, but perhaps the simplest solution would
be to add another method that does what you want, i.e. only delays if
timer has not fired, and returns a boolean indicating whether it delayed
or not. That way you can get the semantics you want but the existing
semantics aren't broken incase there is some subtle case that expects to
be allowed to restart the timer even if it has just fired.
The doxygen comment for the method states:
This can be called either with the TimerTask already added to
a Timer or after the task has been triggered. It has the effect
of delaying the task triggering by the initially specified
duration.
The first sentence suggests it is intentional that it will 'restart' the
timer even if already fired (or firing). (The second sentence admittedly
muddies things a little, since you can't really delay something that has
already happened).
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org