Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 861169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:56:08+00:00 2026-05-15T08:56:08+00:00

I use apache commons http client to send data via post every second, is

  • 0

I use apache commons http client to send data via post every second, is there a way to make the following code more efficient? I know http is stateless, but is there anything I can do to improve since the base url is always the same in this case(only the parameter value change.

private void sendData(String s){ 
      try
         {
              HttpClient client = getHttpClient();


              HttpPost method = new HttpPost("http://192.168.1.100:8080/myapp");
              System.err.println("send to server "+s);
              List formparams = new ArrayList();
              formparams.add(new BasicNameValuePair("packet", s));

              UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
              method.setEntity(entity);

              HttpResponse resp=client.execute(method);
              String res = EntityUtils.toString(resp.getEntity());
              System.out.println(res);

         }
         catch (Exception e)
         {
              e.printStackTrace();

         }
    }
 private HttpClient getHttpClient() {
  if(httpClient==null){
   httpClient = new DefaultHttpClient();
  }
  return httpClient;
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:56:09+00:00Added an answer on May 15, 2026 at 8:56 am

    Use a multi-threaded connection manager,

    http://hc.apache.org/httpclient-3.x/threading.html#MultiThreadedHttpConnectionManager

    This will improve the keep-alive and improve the chance that your connection is ready every second so you don’t have to reestablish the TCP connection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use org.apache.commons.collections.CollectionUtils in android with following code import java.util.ArrayList; import
I've got the following code for a file upload with Apache's HTTP-Client (org.apache.http.client): public
I use a code that imports the following package: import org.apache.commons.httpclient.*; I use eclipse.
I'm trying to use the StringEscapeUtils.escapeXML() function from org.apache.commons.lang... There are two versions of
I am trying to figure out how to use Apache Commons IO DirectoryWalker .
I am trying to download an image from URL. I use the Apache Commons
I am trying to use GLSMultipleLinearRegression (from apache commons-math package) for multiple linear regression.
I'm trying to use VFS S3 a plugin for the Apache Commons VFS for
So I use apache HttpComponents to handle http request in java. Now I want
I'm using Apache Common library for HTTP operations: HttpClient client = getClient(); PutMethod put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.