title: Multiple Async Task Hanging the App
body: <p>In my android App, I use multiple AsyncTask using THREAD_POOL_EXECUTOR which makes the tasks run in parallel. Sometime the app hangs. Below is the code I use. </p>
  
  <ol>
  <li>Could you please let me know how to fine tune so as to avoid any hanging issue ?</li>
  <li><p>How to find the point in which app is hanging ?</p>
  
  <pre><code>new fetchInitialCoinsParallel().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
  
  prefCoinList = getPrefCoin();
  if(prefCoinList.size()&gt;0){
      for(int i=0;i&lt;prefCoinList.size();i++){
          new fetchAltCoinsParallel().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
      }
  }
  
  public class fetchAltCoinsParallel extends AsyncTask&lt;String, String, String&gt; {
  @Override
  protected void onPreExecute() {
  }
  
  protected String doInBackground(String... params) {
      try {
          InputStream is = getDataFromURL(params[0]);
          if(is!=null){
              BufferedReader br = new BufferedReader(new InputStreamReader(is));
              synchronized(this){
                  brList.add(br);
              }
  
          }else{
              prefCoinNotLoadedTimeOutCount=prefCoinNotLoadedTimeOutCount+1;
          }
  
  
          if(brList.size()==prefCoinList.size()-prefCoinNotLoadedTimeOutCount){
              try {
                  loadAltCoins(getAltCoinDataParallel());
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
              maingame.dataReady=true;
          }
  
      } catch (IOException e) {
          e.printStackTrace();
      } 
      return null;
  }
  
  protected void onPostExecute(String params) {
  }
  protected void onProgressUpdate(String... progress) {
  }
  </code></pre>
  
  <p>}</p></li>
  </ol>
  
  <p><strong>Thread details</strong>
  <a href="https://i.stack.imgur.com/rbTUw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/rbTUw.png" alt="enter image description here"></a></p>