aspose file tools*
The moose likes Java in General and the fly likes is an instance of HttpClient  with the SimpleHttpConnectionManager  synchronous? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "is an instance of HttpClient  with the SimpleHttpConnectionManager  synchronous?" Watch "is an instance of HttpClient  with the SimpleHttpConnectionManager  synchronous?" New topic
Author

is an instance of HttpClient with the SimpleHttpConnectionManager synchronous?

James Harold
Greenhorn

Joined: Jul 10, 2012
Posts: 2
I am looking for something that runs http calls in a synchronous manner (i.e. in order) but that also keeps the connection open between calls.

I *think* that the HttpClient (using version 3 ) with the SimpleHttpConnectionManager would accomplish this goal. I setup one instance of the HttpClient then make multiple http calls with that client.

The problem is that during testing, I am seeing a bit of a race condition where two parts of the program are sometimes run in a different order and think it might be related to misunderstanding when to use the SimpleHttpConnectionManager . Can someone confirm that a single instance of the HttpClient with the SimpleHttpConnectionManager should run the calls in order?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

I've checked out the SimpleHttpConnectionManager a short while ago, and I found out it makes no assumptions on thread safety at all. It's up to you, as developer, to make sure the calls are synchronous and sequential. Fortunately for me, my application was single threaded. Unfortunately for you, yours isn't so you'll have to work around that.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
James Harold
Greenhorn

Joined: Jul 10, 2012
Posts: 2
So if it were used in a single threaded application, all calls should run synchronously. That is what I was looking to confirm.

Definitely not a lot of information on this class other then the docs, which sort of imply its synchronous, but don't explicitly state it. Thanks for the reply Rob, its appreciated.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

I think that keeping the proper viewpoint is what helps here.

The HttpConnectionManager is a factory for HttpConnection objects. The HttpClient uses an HttpConnectionManager to acquire the transport needed to execute Http method requests.

The docs plainly say that the connection manager doesn't protect an HttpConnection from being used for multiple requests simultaneously, but since an HttpConnection is responsible for a single request/response cycle at a time, that obliges the application to take proper care not to use it for multiple simultaneous requests.

As I read the docs, the HttpClient won't knowingly violate that limitation. However, if the HttpClient is itself being hit for multiple simultaneous method executions, then it also won't protect you. It's up to you so ensure that the HttpClient is being used serially.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is an instance of HttpClient with the SimpleHttpConnectionManager synchronous?