java - apache commons http client efficiency -


I use Apache Commons http to send the data through every other customer, to make the following code more effective is the way? I know that http is stateless, but there is nothing I can do to improve the base url always since this case (only parameter value change is the same.

 Private zero sendData (string S) {try {HttpClient client = getHttpClient (); HttpPost method = new HttpPost ("http://192.168.1.100:8080/myapp"); System.err.println ("Send to server"); list formparams = New ArrayList (); formparams.add (New BasicNameValuePair ("packet", s); UrlEncodedFormEntity unit = new UrlEncodedFormEntity (formparams, "UTF-8"); method.setEntity (unit); HttpResponse resp = client.execute ( Method); string races = EntityUtils.toString (resp.getEntity ()); println (race);} hold (exception e) {e.printStackTrace ();}} private HttpClient getHttpClient () {if (httpclient == faucet) {HttpClient = New DefaultHttpClient ();} Return httpClient;} 

Use of a multi-threaded connection manager

This will improve the living and improve the opportunity that your connection is ready for every other so that you do not have to re-establish the TCP connection .


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -