Android的计时器时间表VS scheduleAtFixedRate [英] Android Timer schedule vs scheduleAtFixedRate

查看:372
本文介绍了Android的计时器时间表VS scheduleAtFixedRate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Android应用程序,它记录的音频,每10分钟。我使用的是定时器来做到这一点。但是,什么是时间表和scheduleAtFixedRate之间的区别?是否有任何性能优势在使用一个比其他?

I'm writing an Android application that records audio every 10 minutes. I am using a Timer to do that. But what is the difference between schedule and scheduleAtFixedRate? Is there any performance benefit in using one over the other?

推荐答案

的区别是最好的这非Android文档:

固定利率定时器( scheduleAtFixedRate())的基础上,开始时间(所以每次迭代过程将在的startTime + iterationNumber执行* delayTime )。

Fixed-rate timers (scheduleAtFixedRate()) are based on the starting time (so each iteration will execute at startTime + iterationNumber * delayTime).

在固定速率执行,每次执行预定相对于初始执行的安排执行时间。如果一个执行被延迟,因任何原因(如垃圾回收或其他后台活动),两个或两个以上执行将出现快速连续赶上。

In fixed-rate execution, each execution is scheduled relative to the scheduled execution time of the initial execution. If an execution is delayed for any reason (such as garbage collection or other background activity), two or more executions will occur in rapid succession to "catch up."

固定延时定时器(时间表())的基础上,previous执行(所以每次迭代过程将在 lastExecutionTime + delayTime执行)。

Fixed-delay timers (schedule()) are based on the previous execution (so each iteration will execute at lastExecutionTime + delayTime).

在固定延迟执行,每次执行计划相对于previous执行的实际执行时间。如果一个执行被延迟,因任何原因(如垃圾回收或其他后台活动),后续的执行将被推迟为好。

In fixed-delay execution, each execution is scheduled relative to the actual execution time of the previous execution. If an execution is delayed for any reason (such as garbage collection or other background activity), subsequent executions will be delayed as well.

除此之外,没有差别。你不会找到一个显着的性能差异,无论是。

Aside from this, there is no difference. You will not find a significance performance difference, either.

如果你是在你想留在别的同步的情况下,利用这一点,你需要使用 scheduleAtFixedRate()。从延迟时间表()可以漂移,并引入错误。

If you are using this in a case where you want to stay synchronized with something else, you'll want to use scheduleAtFixedRate(). The delay from schedule() can drift and introduce error.

这篇关于Android的计时器时间表VS scheduleAtFixedRate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆