java - 提交到 ScheduledExecutorService 的任务在 "waiting"运行时会做什么

标签 java concurrency java.util.concurrent

如果我有这样的东西

scheduledExecutorService.schedule(task,60, TimeUnit.SECONDS);

当 60 秒尚未结束时,“任务”会发生什么。是否消耗资源?因此,下一个问题和我的具体用例是,如果我有很多“任务”要安排,这会提高内存/资源效率吗?我的任务是短暂的,但我担心将数百个任务调度到 ScheduledExecutorService 的影响。

最佳答案

What happens to "task" while that 60 seconds is not up yet. Does it consume resources?

它在 PriorityQueue 中等待,所以它会使用一些资源。

Consequently, the next question and my specific use case is what if i have a lot of "tasks" to schedule, would that be memory/resource efficient?

并不比将它们存储在队列中差多少。

My tasks are short-lived but i'm concerned about the implications of scheduling hundreds of tasks to the scheduledExecutorService.

假设每个任务使用 1 KB,您将浪费 100 KB。不太可能成为问题。

假设每个任务使用 1 GB,那么您可能会遇到问题。我建议你用另一种方式。

关于java - 提交到 ScheduledExecutorService 的任务在 "waiting"运行时会做什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51177158/

相关文章:

java - 没有 fragment 的Facebook android sdk登录按钮

java - Appletviewer 抛出 java.lang.NoClassDefFoundError 异常

java - Guava 并发教程/代码

java - 一个没有倒数到零的CountDownLatch如何不被中断返回呢?

java - 阻塞队列 "union"的实现

android - 在后台android中更新时从concurrentHashMap访问数据

java - Fitnesse Framework 在决策表中使用正则表达式?

java - 使用 groovy 的 SOAP 请求

c++ - 在线程之间共享数据时如何从不变性中获益?

java - 根据条件定期或仅运行一次 ScheduledExecutorService