title: Android app: Why does it timeout on multiple http post
body: <p>I updated my Nexus 5 to Lollipop and now my Android App got this bug:</p>
  
  <p>My App get it's content from my websites api. For this purpose the app contacts the API "Sync", which responses a List of Items that are new or updated. The app reads this List, loops through the different Items and starts a <code>httppost</code> in a AsyncTask to load the content from the API for each Item.
  For beeing able to cancel the update process, I only start the next <code>httppost</code> when the previous is completed.</p>
  
  <p>On lower Android versions there is no problem, but with Lollipop when I start the update the first 4 Items are loaded normally (and fast: 50ms) but the fifth stucks during <code>response = httpClient.execute(httppost);</code> in the following Code:</p>
  
  <pre><code>    HttpPost httppost;
      try {
          httppost = new HttpPost(url);
      } catch (IllegalArgumentException e) {
          Log.e(Globals.TAG_API, "Wrong URL");
          throw e;
      }
      HttpResponse response;
      HttpParams httpParams = new BasicHttpParams();
      httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
      HttpConnectionParams.setTcpNoDelay(httpParams, false);
      HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
      HttpConnectionParams.setSoTimeout(httpParams, 30000);
  
      HttpClient httpClient = new DefaultHttpClient(httpParams);
      HttpEntity entity;
      try {
          Log.d(Globals.TAG,"Start");
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));
          response = httpClient.execute(httppost);
          Log.d(Globals.TAG,"Stop");
          entity = response.getEntity();
      }
  </code></pre>
  
  <p>After 30 seconds the Timeout cancels the Connection. <strong>Also important:</strong> during this 30 seconds the whole Homepage is not reachable anymore. I don't think the bug is in the API, because devices with an older version of Android are using the same API...</p>
  
  <p>Please comment, if you need more Code from the API or the APP, I just hope the bug is in the Code above :)</p>
  
  <p><strong>Update 21.12.2014</strong>
  After a little discussion in the comments, we have found that, that a <code>sleep(300)</code> inside the AsyncTask (in which is the <code>httppost</code>) solves the problem. So the problem was, that too many httppost reached the server and blocked my ip, with the <code>sleep</code> this is reduces ;-)</p>
  
  <p><strong>Update 1.1.2015</strong>
  I did not found if the problem is server-based or in my app. But now I use GoogleVolley for my API and it works awesome!</p>