PS:delay太大又没意义了,要的就是立即执行啊,至少延迟不能太大。
4 个解决方案
#1
看api的说明
* <p>Corresponding to each <tt>Timer</tt> object is a single background
* thread that is used to execute all of the timer's tasks, sequentially.
* Timer tasks should complete quickly. If a timer task takes excessive time
* to complete, it "hogs" the timer's task execution thread. This can, in
* turn, delay the execution of subsequent tasks, which may "bunch up" and
* execute in rapid succession when (and if) the offending task finally
* completes.
*
Timer使用单线程来跑所有定时任务,按顺序地。如果有一个任务用了太久的执行时间,则它会“hog”住整个执行线程。这将会延迟后续的任务执行;
那么对于一次性的任务,他们虽然会被前面的任务拖延时间,但是终归是要执行一次的。
对于定时的循环的任务,则会给人一种丢失了前一(几)轮运行的感觉。
* <p>Corresponding to each <tt>Timer</tt> object is a single background
* thread that is used to execute all of the timer's tasks, sequentially.
* Timer tasks should complete quickly. If a timer task takes excessive time
* to complete, it "hogs" the timer's task execution thread. This can, in
* turn, delay the execution of subsequent tasks, which may "bunch up" and
* execute in rapid succession when (and if) the offending task finally
* completes.
*
Timer使用单线程来跑所有定时任务,按顺序地。如果有一个任务用了太久的执行时间,则它会“hog”住整个执行线程。这将会延迟后续的任务执行;
那么对于一次性的任务,他们虽然会被前面的任务拖延时间,但是终归是要执行一次的。
对于定时的循环的任务,则会给人一种丢失了前一(几)轮运行的感觉。
#2
有可能的,系统繁忙时,你的线程一直拿不到执行权就无法执行了
#3
嗯,不过我说的不是定时任务,就是执行一次的任务,delay≈0
#4
之所以要delay,是因为一些任务,初始化时,需要一些资源准备的时间。如果任务本身申请资源速度快到可以忽略不计,就可以不设置delay的。
#1
看api的说明
* <p>Corresponding to each <tt>Timer</tt> object is a single background
* thread that is used to execute all of the timer's tasks, sequentially.
* Timer tasks should complete quickly. If a timer task takes excessive time
* to complete, it "hogs" the timer's task execution thread. This can, in
* turn, delay the execution of subsequent tasks, which may "bunch up" and
* execute in rapid succession when (and if) the offending task finally
* completes.
*
Timer使用单线程来跑所有定时任务,按顺序地。如果有一个任务用了太久的执行时间,则它会“hog”住整个执行线程。这将会延迟后续的任务执行;
那么对于一次性的任务,他们虽然会被前面的任务拖延时间,但是终归是要执行一次的。
对于定时的循环的任务,则会给人一种丢失了前一(几)轮运行的感觉。
* <p>Corresponding to each <tt>Timer</tt> object is a single background
* thread that is used to execute all of the timer's tasks, sequentially.
* Timer tasks should complete quickly. If a timer task takes excessive time
* to complete, it "hogs" the timer's task execution thread. This can, in
* turn, delay the execution of subsequent tasks, which may "bunch up" and
* execute in rapid succession when (and if) the offending task finally
* completes.
*
Timer使用单线程来跑所有定时任务,按顺序地。如果有一个任务用了太久的执行时间,则它会“hog”住整个执行线程。这将会延迟后续的任务执行;
那么对于一次性的任务,他们虽然会被前面的任务拖延时间,但是终归是要执行一次的。
对于定时的循环的任务,则会给人一种丢失了前一(几)轮运行的感觉。
#2
有可能的,系统繁忙时,你的线程一直拿不到执行权就无法执行了
#3
嗯,不过我说的不是定时任务,就是执行一次的任务,delay≈0
#4
之所以要delay,是因为一些任务,初始化时,需要一些资源准备的时间。如果任务本身申请资源速度快到可以忽略不计,就可以不设置delay的。