Java完整的未来Allof线程附件
有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论