4

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.

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875

3 Answers3

9

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.

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
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)

stuckless
  • 6,515
  • 2
  • 19
  • 27
2

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.

Espen Riskedal
  • 1,425
  • 15
  • 28