本文介绍了如何使用Guava ListenableFuture和Futures.chain()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个家庭作业任务,需要我学习如何使用Guava并发库。



在任务中我有几个线程池,



每个池有几个工作线程,执行简单的任务(大部分模拟使用 Thread.sleep(long) / code>),所有这些简单任务存储在模拟消息板的容器对象中。



每个简单任务都有其他任务的依赖关系列表,



我如何从Guava库中使用 ListenableFuture Futures.chain()



我在网上搜索了大量的示例代码,不知道如何使用。

解决方案

您可能有兴趣阅读,链接到Guava首页(幻灯片11及以后)。他们真的帮助我理解了 ListenableFuture ,并为什么这么有用。



我的猜测是,你的任务是理解Futures如何工作,以及Guava的 ListenableFuture Futures.chain()如何简化协调多个任务。



使用ListenableFuture的唯一开源代码是:








我不知道是否使用 Futures.chain()


I have a homework task that requires me to learn how to use the Guava concurrency library.

In the task I have several thread pools, where each one is controlled by an individual object.

Each pool has several working threads that perform simple tasks (mostly emulating doing stuff by using Thread.sleep(long)) and all those simple tasks are stored in a container object that emulates a messageboard.

Each simple task has a dependency list of other tasks, and it cannot be executed until all of those tasks are completed.

How can I benefit from the Guava library using the ListenableFuture and the Futures.chain()?

I have searched everywhere for some extensive example code online, but didn't find anything that I understand how to use.

解决方案

You might be interested in reading the presentation slides on Guava util.concurrent, linked on the Guava homepage (slide 11 and onward). They really helped me crystallize my understanding of ListenableFuture and why it's so useful.

My guess is that the goal of your assignment is to understand how Futures work, and how Guava's ListenableFuture and Futures.chain() simplifies their use when coordinating multiple tasks.

The only open source code that comes to mind that uses ListenableFuture is sitebricks-mail:

I don't know if it uses Futures.chain(), though.

这篇关于如何使用Guava ListenableFuture和Futures.chain()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 22:59