参考:http://chen-yongkai.iteye.com/blog/1673241
原文摘抄如下:
运行时修改TimerTask的执行周期
java.util.TimerTask类的执行周期period变量的声明如下:
- /**
- * Period in milliseconds for repeating tasks. A positive value indicates
- * fixed-rate execution. A negative value indicates fixed-delay execution.
- * A value of 0 indicates a non-repeating task.
- */
- long period = 0;
TimerTask并未提供修改period的公共方法,但我们可以借助java反射修改其值。
- public abstract class ReschedulableTimerTask extends TimerTask {
- public void setPeriod(long period) {