views:

28

answers:

1

Hi, I would like to understand how the asynchronous invocation model in jax ws works. If for example I use Future invokeAsync(T msg, AsyncHandler handler) then my program can resume and when the response from the web service arrives, the result will be passed to my AsyncHandler. If I have several threads in the same program and one thread calls invokeAsync and resumes operation and immediately another thread (perhaps more) tries to also call invokeAsync to the same web service (perhaps different operation but same portType) how will this situation be handled by the framework? Will a series of POSTs go the same web service (POST for thread1, POST for thread2 etc) or after a response arrives then the next POST will be send (POST for thread1 when response arrives pass result to the callback handler and then POST for thread2?)

Thanks

A: 

I can't say for Jax in particular, but the only way that makes sense to me is if the posts are independent. It would be crazy (IMO) for the client to wait until the web service had returned the first response before it made the next request.

Jon Skeet
I am not sure what you mean independent POSTs. My understanding is that there is a single TCP connection to the same web service for all threads. So isn't it suppose to follow a series of HTTP transactions? Request-Response and then next Request. Or am I confused on this? We could have a POST and then a new POST to the same web service before the previous response comes?
akmer
@akmer: What makes you think there will be a single TCP connection? Is that something specific to jax? There's no reason why you would *have* to have a single TCP connection. Many APIs will keep a *pool* of connections and allow you to set some sensible limit of concurrent connections to the same server, but it would be unusual for that limit to be 1.
Jon Skeet
@Jon Skeet. My understanding is that in HTTP1.1 the connection is kept and not closed after the response of the server (by connection:keep-alive) for performance. So you are saying that normally the APIs will have some short of state and understand that although the request will be send to the same url, not reuse the connection (due to the pending response) but use a pooled available connection? So if I have 8 threads the API will make 8 tcp connections to push the requests to the same web service?
akmer
@akmer: Yes, you can reuse connections if you want, and keep a pool of them - but if you want to create more than one request at a time, you want to use more than one connection. Each connection can only have one request at a time.
Jon Skeet
So if HTTP says that each client SHOULD have at most 2 connections with the same server then if my 8 threads make asynchronous invocations to the same web service only 2 threads can send the request and the others will have to wait. Correct? There can be no pipelining in the http connection? Semantics is only request/response? Correct?
akmer
If you've got your client configured that way, yes. In my experience, clients which do pooling allow you to specify how many concurrent requests to have per server - it's not unreasonable to configure it to 4 or 8, IMO. (I believe modern browsers use one of those settings by default.) I don't believe HTTP connections allow multiple active requests/responses in a single connection. There can be chunking of the request or response, but not multiplexing.
Jon Skeet
Thanks Jon. I will raise flag to your answer
akmer