问题标签 [scheduledexecutorservice]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - ScheduledExecutorService 一线程多任务
我是新手ExecutorService
,想知道为什么以下代码正确打印“10 15”,即使我只创建了一个线程来处理超时?为什么我可以多次调用 schedule 而不会在单个线程执行程序上取消以前的任务?
java - 如何使用 ScheduledExecutorService 处理重复任务中的错误?
我有一个,它通过(可以改为使用)定期ScheduledExecutorService
调用Runnable。scheduleWithFixedDelay()
scheduleAtFixedRate()
现在正在考虑如果发生错误该怎么办。如果它无法从 (*) 中轻松恢复,我希望选择停止所有进一步的调用,但不确定执行此操作的最佳方法。
显然,无法从 Runnable 抛出已检查的异常,因此希望获得有关如何从以下选项中进行选择的任何指导:
(*) 想知道一般情况,但如果有人感兴趣,我目前正在查看的检查异常是ParserConfigurationException
从DocumentBuilderFactory.newDocumentBuilder()
. 如果抛出此错误,则表明存在严重问题,因此我基本上希望调度完全停止,而不是每次都可能重复错误。
java - 使用 ScheduledExecutorService 以固定间隔并行运行多个线程
目标:每 5 秒监控 5 个 json URL,其中 5 个线程并行运行。
我想运行多个并行线程以每个 n 秒的间隔监控 JSON URL。我正在使用ScheduledExecutorService
这个。
这是创建 5 个线程来监控 5 个 URL 的正确方法吗?我不想在这里使用线程池。在应用程序的生命周期之前,所有 5 个线程都必须处于活动状态。
可以ScheduledExecutorService
在我的情况下提供帮助还是有另一种方法可以实现这一目标?
谢谢
java - ScheduledExecutorService,以不同的时间间隔调度不同的任务
我想要两个任务 - HandlerA 和 HandlerB 分别每 10 秒和每 20 秒执行一次。如果此解决方案是错误的,那么实现此目标的最佳方法是什么?
当我安排另一个任务时,是否会覆盖计划任务?
android - Executors.newSingleThreadScheduledExecutor().schedule 的可靠性
这个执行者有一些已知的问题吗?还是我用错了方法?我需要在单独的线程中安排上传,并且我希望在当前上传完成后的特定时间后触发下一次上传。
因此,我的服务实现中有一些代码摘录:
但是当我检查日志时,我看到以下内容:
所以前三个进展顺利,但最后一个在十八分钟后开始,而不是五分钟!该服务还在 15:43 到 16:01 之间获取位置更新,但是位置侦听器在主线程上运行,并且位置更新之间有几秒钟的时间间隔,因此没有什么应该阻止调度的执行器触发......但它迟到了超过预定延误的三倍!这怎么可能?
java - Java Scheduled Executor 服务能力
我正在设计一个服务器,我需要能够在其中安排数千个任务。该任务每 5 秒执行一次。调度执行器服务是否能够准确地处理数千个任务?我试图在一个线程中进行计时。但实际任务将在线程池中执行。谢谢
我不确定它究竟是如何工作的,所以如果有人能澄清这一点,我将不胜感激!
java - 如何从 ScheduledExecutorService 中删除任务?
我会ScheduledExecutorService
定期执行一些不同的任务scheduleAtFixedRate(Runnable, INIT_DELAY, ACTION_DELAY, TimeUnit.SECONDS);
我也有一个不同Runnable
的,我正在使用这个调度程序。当我想从调度程序中删除其中一项任务时,问题就开始了。
有没有办法做到这一点?
我是否使用一个调度程序来完成不同的任务?实现这一点的最佳方法是什么?
android - 在我按下主页按钮后 ScheduledExecutorService 不在后台运行
我在 onCreate() 和按下主页按钮后创建了它;ScheduledExecutorService 不会在后台每 10 分钟运行一次。为什么?
哪里错了。
请帮帮我。
提前致谢。
java - java.util.Timer 无异常停止
我每 2 分钟去一次 FTP 上传新文件。我用 java.util.Timer 实现了它。但过了一段时间——几天甚至一周——它毫无例外地停止了,也没有任何理由。
我找到了线程: Java无限线程在一段时间后停止
但是里面并没有什么特别的解决办法。我阅读了有关 ScheduledExecutorService 的信息,但据我所知 - 它与 Timer 相同。
请给我一些想法!
android - ScheduledExecutorService does not execute if it has moved from the main activity
I have the code below which is in ONCreate() method of the main activity and works fine. After moving to the next activity (B) which is a list view and then to activity (C ) which is the row selected from the listview and goes to sleep then the ScheduledExecutorService started in the main activity is not executing anymore .
Why is it not executing and how do I fix it? I am noob in Android .Please help me out.
Thanks in Advance .Really appreciate the help.