I have a client that interacts with a restful web service using CXF. I want to make use of asynchronous mode provided by CXF since 2.7.0 http://cxf.apache.org/javadoc/latest/org/apache/cxf/jaxrs/client/WebClient.html. I haven't really found a good example of a client using this feature
Previously I had code that did some thing like this
Response response = webclient.get();
updated code:
Future<Response> responseFuture = webclient.async().get();
// code to get future response ...
My questions:
Is this all I need to do and how will the client behavior change? My understanding is that previously it would create a separate thread for each client request. Now it will perform multiple requests using a single thread or thread pool?
Also, what is the best way for me to monitor what it is doing in the background in the two different cases?
Well, yes and no.
That's all you need to do in your code, yes. However, by default, CXF would still use an HttpURLConnection object which requires a dedicated thread per request. Thus, under the covers, it would use CXF's thread pools for this.
However, you can add CXF's async based transport (see http://cxf.apache.org/docs/asynchronous-client-http-transport.html ) which would allow hundreds of outstanding requests with very few threads used.