gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:03:12 24 4
gpt4 key购买 nike

如果我有这样的东西

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com