如何使使异步方式Web请求

编程入门 行业动态 更新时间:2024-10-18 10:14:58
本文介绍了如何使使异步方式Web请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要做一个Web请求从Java REST式服务器。我想为我的Java code异步处理响应。我找了它处理请求的线程和回调的框架。

顺便说一句,我看了看FutureTask提供,它不会似乎是我所需要的,因为它需要客户端等待它在某个时候完成。我在寻找完成后的回调。

解决方案   

顺便说一句,我看了看FutureTask提供,它不会似乎是我所需要的,因为它需要客户端等待它在某个时候完成。

您不要的有无以的调用从启动线程FutureTask.get(),以获得该任务的结果。你可以只具有可赎回传递给 FutureTask提供还处理通信其输出到其他组件。在的get()的方法有哪些,这样你可以得到异步计算,这可能需要等待计算完成,如果还没有结果。

如果您想preFER回调风格,你可以简单地有赎回调用自己构造的回调或处理它自己造成的。

I need to make a web request to a RESTful server from Java. I would like for my Java code to handle the response asynchronously. I am looking for a framework which handles the threading and callbacks of the request.

By the way, I took a look at FutureTask and it does not appear to be what I need because it requires the client to wait for it to complete at some point. I'm looking for a callback upon completion.

解决方案

By the way, I took a look at FutureTask and it does not appear to be what I need because it requires the client to wait for it to complete at some point.

You don't have to call FutureTask.get() from the initiating thread in order to get the results of the task. You could just have the Callable passed to the FutureTask also handle communicating it's output to some other component. The get() methods are there so that you can get the results of the async computation, which may involve waiting for the computation to finish if it has not yet.

If you would prefer the callback style, you can simply have the Callable invoke a callback of your own construction or handle the result on it's own.

更多推荐

如何使使异步方式Web请求

本文发布于:2023-11-13 00:32:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582915.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!