Java完整的未来Allof线程附件

发布于 2025-01-22 00:27:27 字数 782 浏览 1 评论 0原文

allof java 完整的future方法。

在我的代码中,我在应用程序的主池中分别运行5个不同的任务。 Something like that:

t1 = CompletableFuture.runAsync(() -> ..., mainPoolExecutor);
t2 = CompletableFuture.runAsync(() -> ..., mainPoolExecutor);
...
t5 = CompletableFuture.runAsync(() -> ..., mainPoolExecutor);

CompletableFuture.allOf(t1, t2, t3, t4, t5).join()

What I found out is that in 99 quantiles it takes 100ms for this code to be finished.同时,最长任务所花费的时间为 50ms 99个分位数中。从我的角度来看,发生这种情况是因为我的民意调查的大小为20个线程,例如,在同一线程上执行任务T1和T3,因此无法从allof方法保证该任务。将在不同的线程上执行。

如果正确,如何处理?在99个分位数中实现 50ms的最佳方法是什么?

我不喜欢增加游泳池尺寸的解决方案。我不确定是否还有另一个解决方案。

There is the allOf java CompletableFuture method.

In my code, I run separately 5 different tasks on the main pool of my application. Something like that:

t1 = CompletableFuture.runAsync(() -> ..., mainPoolExecutor);
t2 = CompletableFuture.runAsync(() -> ..., mainPoolExecutor);
...
t5 = CompletableFuture.runAsync(() -> ..., mainPoolExecutor);

CompletableFuture.allOf(t1, t2, t3, t4, t5).join()

What I found out is that in 99 quantiles it takes 100ms for this code to be finished. At the same time, the time taken by the longest task is 50ms in 99 quantiles. In my point of view, it happens because my poll has size of 20 threads, sometimes, for example, task t1 and t3 are being executed on the same thread, there is no guarantee from allOf method that tasks will be executed on different threads.

If it is correct, how can it be handled? What is the best approach to achieve 50ms in 99 quantiles for all tasks to be finished?

I don't like the solution of increasing the size of the pool. I am not sure if there is another solution though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文