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 8859483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:04:24+00:00 2026-06-14T15:04:24+00:00

I am trying to send reqeuest to server…and until request is not responded i

  • 0

I am trying to send reqeuest to server…and until request is not responded i want to execute a loop printing integers..problem is my loop goes on and on, if i execute it till 100 it prints 100 values and if till 1000 it prints 1000. What i want is that the looping should be depended upon the response. as soon as response occurs the loop thread should be stoped…

  public class ServiceInteraction {
  FutureTask<JSONArray> task;
  public JSONArray addUser(List<BasicNameValuePair> postPairs_interaction){
    JSONArray jArray;
    task = new FutureTask<JSONArray>(new Service_C(postPairs_interaction));
    ExecutorService pool = Executors.newFixedThreadPool(2);
    pool.submit(task);
    for(int i = 0 ; i < 1000; i++){
        System.out.println("value is "+i);
    }//End of for loop
    try{
        return (jArray = task.get());
    }catch(InterruptedException e){
        return null;
    }catch(ExecutionException e){
        return null;
    }
  }//End Of addUser

Here is my service_c class code…

public Service_C(List<BasicNameValuePair> postPairs) {
    this.postPairs = postPairs;
}

@Override
public JSONArray call() throws Exception {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost post = new      HttpPost("http://10.0.0.62:8080/IDocWS/"+postPairs.get(0).getValue());
    post.setEntity(new UrlEncodedFormEntity(postPairs));
    ResponseHandler respHandler = new BasicResponseHandler();
    String responseData = (String) httpclient.execute(post,respHandler);

    try {
        JSONArray jArray;
        jArray = new JSONArray(responseData);
        return jArray;

    } catch (JSONException ex) {
        Logger.getLogger(Service.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("Error in getting response from the user");
        return null;
    }
}//End of call method
  • 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-06-14T15:04:28+00:00Added an answer on June 14, 2026 at 3:04 pm

    You can try this:

     for (int i = 0;;i++){
            if (task.isDone()) {
                  break;
            }
            System.out.println("value is "+i);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem when trying to send a POST request. The sending method
I am trying to send request to server in every 2 seconds in a
I'm trying to send a GET request to a App Engine server from a
I'm trying to send json string in the get request to the server, here
I am trying to send request from local server to youtube server bu the
I am trying to send a POST request to my server, everything seems to
I am trying to send a simple URL request to a server with XML
I am trying to send a AJAX request to the server when a user
I'm trying to send a facebook request from the server side api (php). I
I am trying to send a soap request to a remote server and getting

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.