在 Timer.schedule(TimerTask task, long delay)
,它表示如果 delay
为负数,则会抛出异常,但没有说明 delay
是否为零。会发生什么?我尝试了 openjdk,它立即运行。这种行为是在其他地方指定的,还是未定义的(例如,这意味着在其他实现上是无限的,或者某些实现有时会无限,有时会立即执行)?
最佳答案
来自the Java SE7 documentation :
If delay is less than or equal to zero, the timer fires as soon as it is started
所以你得到的结果是预期的行为。
关于java - 当delay为0时,Timer.schedule调度多长时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16723183/