+ /**
+ * Restarts the timer if the interval has changed. If the timer is not currently
+ * running, then it updates the interval, but does not start the timer.
+ *
+ * @param intervalMs desired interval, or {@code null} to leave it unchanged
+ */
+ public synchronized void restart(Long intervalMs) {
+ if (intervalMs != null && intervalMs > 0 && intervalMs != this.intervalMs) {
+ this.intervalMs = intervalMs;
+
+ if (timer != null) {
+ terminate();
+ start();
+ }
+ }