• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is an instance of HttpClient with the SimpleHttpConnectionManager synchronous?

 
James Harold
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Harold
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic