如何在优先执行的情况下实现完整的未来?
我有一个问题,我不确定可完整的未来API是否能够解决我的问题,但想向堆栈溢出社区打开它。
我有一个情况,我想调用2种方法。这些方法之一(方法A)将返回DynamoDB的一些数据。另一种方法(方法B)将从SQL数据库返回一些数据。我想并行执行这些方法。但是,扭曲是客户可以优先要求数据。
例如,用户可以通过`[a“”,“ b”]传递。在这种情况下,我希望这两个任务都可以并行完成,但是如果完成并返回有用的数据以停止在任务B上执行
。未来,我没有找到似乎能够做到这一点的任何方法。方法anyof(pountableFuture<?> ... cfs)
或allof(pountableFuture<?> ... cfs)
似乎适用于这些情况。似乎没有办法偏爱特定的完整future。
我很想知道如何在Java解决这个问题!
I have an issue where I am not sure if the completable future api is able to solve my problem, but would like to open it to the stack overflow community.
I have a case, where I want to call 2 methods. One of these methods (method A) will return some data from DynamoDB. Another method (method B) will return some data from a SQL database. I would like to do these methods in parallel. However, the twist is the customer can ask for data in a certain priority.
For example, a user could pass in `["A" , "B"]. In this case, I would like both tasks to start being done in parallel, but if A finishes and returns useful data to stop execution on task B. If A returns null/not found, then return the result of B.
When reading about completable future's I have not found any methods that seem to be able to do this. The methods anyOf(CompletableFuture<?>... cfs)
or allOf(CompletableFuture<?>... cfs)
seem to apply to these situations. It seems like there is no way to give a preference to a specific CompletableFuture.
I would love to know how to solve this problem in Java!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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