java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -


i have used httpclient3.1(java) connection pooling below :

import org.apache.commons.httpclient.httpclient; import org.apache.commons.httpclient.multithreadedhttpconnectionmanager; import org.apache.commons.httpclient.params.httpclientparams; import org.apache.commons.httpclient.params.httpmethodparams; import org.apache.log4j.logger;  public class httpclientmanager {      private static logger logger = logger.getlogger(httpclientmanager.class);     private static multithreadedhttpconnectionmanager connectionmanager = new multithreadedhttpconnectionmanager();     private static httpclientparams clientparams = new httpclientparams();     static {         try {             clientparams.makelenient();             clientparams.setauthenticationpreemptive(false);             clientparams.setparameter(httpmethodparams.so_timeout, new integer(30000)); // set so_timeout             clientparams.setparameter(httpmethodparams.head_body_check_timeout, new integer(3000)); // head responses should come in 3 seconds or less             clientparams.setparameter(httpmethodparams.reject_head_body, boolean.true); // should reject body sent part of head request             clientparams.setparameter(httpmethodparams.status_line_garbage_limit, new integer(0)); // not tolerate garbage in status line             clientparams.setparameter(httpclientparams.max_redirects, new integer(5)); // we'll follow redirects 5 times.             clientparams.setconnectionmanagertimeout(30000); // we'll wait 30 seconds before timing out on getting connection out of connection manager         } catch(throwable ex) {             logger.error("exception setting timeouts etc client connection factory", ex);             system.out.println("exception setting timeouts etc client connection factory"+ex);         }     }     private static httpclient client = new httpclient(clientparams, connectionmanager);      /**      * handle common httpclient uses multithreaded connection pool manager      * code uses shares pool.      * should ok use pools other 1 in case threads in pool stuck on proxying web videos etc.       * @return      */     public static httpclient getclient() {         return client;     }  } 

i client in following way : httpclient client = httpclientmanager.getclient(); , start calling methods on , call method.releaseconnection(); following exception of time :

java.net.sockettimeoutexception: read timed out   java.net.socketexception: software caused connection abort: recv failed java.net.connectexception: connection timed out: connect 

so planning go httpclient4.3.2 , seen code below connection pooling

poolinghttpclientconnectionmanager cm = new poolinghttpclientconnectionmanager();                 cm.setmaxtotal(100);                 cm.closeexpiredconnections();                  closeablehttpclient httpclient = httpclients.custom().setconnectionmanager(cm).build(); 

is fine go or there other way implement same ?

thanks


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

php - ternary operator in a dynamic dropdown menu -