Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connection pool shutdown android

I have a class for Httpclient. The same instance is used throughout the application. So if the client == null it should create one else it will return the existing instance. Everything works until i try to release the resource on exit by doing: client.getConnectionManager().shutdown();....after this i am not able to login again. It gives Sysem error saying : connection pool shutdown. Heres the class:

public class HttpClientFactory {
    private static DefaultHttpClient client;        
    public synchronized static DefaultHttpClient getThreadSafeClient() {
    if (client != null)
        return client;

    client = new DefaultHttpClient();
    SchemeRegistry schemeRegistry = new SchemeRegistry(); 
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));  
    HttpParams params = new BasicHttpParams();  
    SingleClientConnManager mgr = new SingleClientConnManager(params, schemeRegistry);  
    client = new DefaultHttpClient(mgr, params);

    return client;
}
}

After this i simply run client.getConnectionManager().shutdown(); onBackPressed(), can somebody please help me

like image 568
user484691 Avatar asked Apr 05 '11 21:04

user484691


2 Answers

Ok..i got the solution...I was not setting it back to null and connection shutdown is suppose to be done in the same global class...

like image 85
user484691 Avatar answered Nov 11 '22 01:11

user484691


I have faced similar issue, but set

client.getConnectionManager().shutdown()
client.getConnectionManager() = null

could not resolved the problem.

Finally, I found out that, I did close all connections in onPostExecute, which is incorrect, so after moving them into doInBackground, it works.

Hope this helps someone!

like image 37
Lunf Avatar answered Nov 11 '22 00:11

Lunf