Reputation: 3532
I understand that ThreadSafeClientConnManager uses a connection pool and, when the client needs a connection, picks a connection from that one. SingleClientConnManager, instead, uses just one connection.
What I want to understand is: does this have implications also about safeness? Do I have to understand that SingleClientConnManager is unsafe?
On SingleClientConnManager documentation page I read:
This manager is good only for single-threaded use.
Than I suppose the answer is yes, but I must be sure of this...
Upvotes: 1
Views: 666
Reputation: 12058
I'm not sure about what you are refering as safe
, but here goes a quick explanation about Thread safe
concept.
When you have a code with more then one thread, the OS switchs between them time to time, and you have "almost" no control when this switch happens.
Supose that global
is a global object and thread A does the following:
//Thread A
global = 2;
Log.d("Thread A: ", global);
And OS switchs from thread A to B between first and second line above :
//Thread B
global = 5;
Log.d("Thread B: ", global);
You would see in your log:
Thread B: 5;
Thread A: 5;
Because thread B overriten the value on global
.
Thread Safe
Thread safe code, is code that have been written in a way that prevents the type of issues showed above (using shynchronized blocks, etc.) and can be safelly called from different threads without problems.
Thread unsafe, means that if you calling the code from different threads and are not "lucky" enough, at some point in time the threads will swith in a point similar tothe one described above and your program will produce unpredictable results.
If you are using a single thread, they are both safe. In this case, the thread unsafe is preferable as usually it is more efficient.
Regards.
Upvotes: 1