Questions tagged «timertask»

3
Timertask或Handler
假设我想每隔10秒执行一次操作,而不必更新视图。 问题是:将timer与timertask一起使用会更好(我的意思是更有效): final Handler handler = new Handler(); TimerTask timertask = new TimerTask() { @Override public void run() { handler.post(new Runnable() { public void run() { <some task> } }); } }; timer = new Timer(); timer.schedule(timertask, 0, 15000); } 或只是带有延迟的处理程序 final Handler handler = new Handler(); final Runnable r …

11
如何使用ScheduledExecutorService每天在特定时间运行某些任务?
我想每天早上5点执行某项任务。因此,我决定使用ScheduledExecutorService此功能,但到目前为止,我已经看到了一些示例,这些示例演示了如何每隔几分钟运行一次任务。 而且我找不到任何示例来说明如何每天在特定时间(上午5点)每天运行任务,并且还考虑了夏令时的事实- 以下是我的代码,每15分钟运行一次- public class ScheduledTaskExample { private final ScheduledExecutorService scheduler = Executors .newScheduledThreadPool(1); public void startScheduleTask() { /** * not using the taskHandle returned here, but it can be used to cancel * the task, or check if it's done (for recurring tasks, that's not * going to be …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.