如何在优先执行的情况下实现完整的未来?

发布于 2025-02-05 13:49:27 字数 432 浏览 2 评论 0原文

我有一个问题,我不确定可完整的未来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 技术交流群。

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

发布评论

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