public static final synchronized HttpClient createHttpClient(int timeout){
  HttpParams params=new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(params,timeout);
  HttpConnectionParams.setSoTimeout(params,2 * timeout);
  HttpClientParams.setRedirecting(params,true);
  HttpClientParams.setAuthenticating(params,true);
  HttpClientParams.setCookiePolicy(params,CookiePolicy.BROWSER_COMPATIBILITY);
  List<String> authPref=new ArrayList<String>();
  authPref.add(AuthPolicy.DIGEST);
  authPref.add(AuthPolicy.BASIC);
  params.setParameter(AuthPNames.TARGET_AUTH_PREF,authPref);
  params.setParameter(ClientPNames.MAX_REDIRECTS,1);
  params.setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS,true);
  DefaultHttpClient httpclient;
  if (httpConnectionManager == null) {
    httpclient=new DefaultHttpClient(params);
    httpConnectionManager=httpclient.getConnectionManager();
  }
 else {
    httpclient=new DefaultHttpClient(httpConnectionManager,params);
  }
  return httpclient;
}

public static final synchronized HttpClient createHttpClient ( int timeout ) { HttpParams params = new BasicHttpParams ( ) ; HttpConnectionParams . setConnectionTimeout ( params , timeout ) ; HttpConnectionParams . setSoTimeout ( params , 2 * timeout ) ; HttpClientParams . setRedirecting ( params , true ) ; HttpClientParams . setAuthenticating ( params , true ) ; HttpClientParams . setCookiePolicy ( params , CookiePolicy . BROWSER_COMPATIBILITY ) ; List < String > authPref = new ArrayList < String > ( ) ; authPref . add ( AuthPolicy . DIGEST ) ; authPref . add ( AuthPolicy . BASIC ) ; params . setParameter ( AuthPNames . TARGET_AUTH_PREF , authPref ) ; params . setParameter ( ClientPNames . MAX_REDIRECTS , 1 ) ; params . setParameter ( ClientPNames . ALLOW_CIRCULAR_REDIRECTS , true ) ; DefaultHttpClient httpclient ; if ( httpConnectionManager == null ) { httpclient = new DefaultHttpClient ( params ) ; httpConnectionManager = httpclient . getConnectionManager ( ) ; } else { httpclient = new DefaultHttpClient ( httpConnectionManager , params ) ; } return httpclient ; }
create an httpclient with connection timeouts and other parameters set . save and reuse the connection manager across invocations ( this is what requires synchronized access ) .
