本文介绍了如何使使异步方式Web请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要做一个Web请求从Java REST式服务器。我想为我的Java code异步处理响应。我找了它处理请求的线程和回调的框架。
顺便说一句,我看了看FutureTask提供,它不会似乎是我所需要的,因为它需要客户端等待它在某个时候完成。我在寻找完成后的回调。
解决方案
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请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!