开发者

On Android, does the DefaultHttpClient properly cleanup the HttpPost when an exception is thrown?

I am seeing a problem with reusing my http-client after an HttpPost's execute fails. It can be a timeout or service not available (maybe others). The request might throw a socket-timeout and when i later use the client (with a new HttpPost object) it will throw an illegal state exception. My research indicates that this occurs when the socket is not marked for "reuse" as in the case that naturally occurs if you have two threads and one is in the middle of processing its request before the second thread tries to use the http-client (hence its socket).

I think there is a bug in the http-client code, but there could be either som开发者_如何学Pythone 'best practises' that I am not following correctly or some known work around.

Any help on this would be appreciated.


My research indicates that this occurs when the socket is not marked for "reuse" as in the case that naturally occurs if you have two threads and one is in the middle of processing its request before the second thread tries to use the http-client (hence its socket).

HttpClient is not thread-safe by default. You need to use a ThreadSafeClientConnManager.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜