Is AndroidHttpClient thread safe

纵然是瞬间 提交于 2019-12-22 09:38:54

问题


I was wondering, whether is AndroidHttpClient thread safe, as this is not being mentioned in documentation. Means, a single instance of AndroidHttpClient can be shared among multiple threads.


回答1:


Yes, it is thread safe.

AndroidHttpClient is a special implementation of DefaultHttpClient which is pre-configured for Android. It registers the ThreadSafeClientConnManager which allows thread safe HTTP access via a managed connection pool. AndroidHttpClient also applies reasonable default settings for timeouts and socket buffer sizes. It also supports HTTPS by default.

You can find the source code here.




回答2:


It is Thread safe according the code, since it uses

ClientConnectionManager manager =
                new ThreadSafeClientConnManager(params, schemeRegistry);

as per source

The only drawback to this is that it's Api level 8 and above (2.2.x)




回答3:


Yes it's thread safe. Also, be sure to use the factory method:

newInstance(String userAgent, Context context)

when using it with HTTPS to ensure caching of SSL sessions.



来源:https://stackoverflow.com/questions/11103109/is-androidhttpclient-thread-safe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!