title: Simultaneous async requests with OkHttp
body: <p>My app is using long polling to keep some local state up to date, but it also needs to communicate with the server while independently/simultaneously maintaining the long-polling connection. </p>
  
  <p>The trouble is, OkHttp blocks any other calls to the server while it waits for the long-polling connection to receive data or timeout.</p>
  
  <p>I've set up two OkHttpClient instances, one for normal API calls to the server, and the other to maintain the long-polling connection.</p>
  
  <pre><code>private static OkHttpClient client = new OkHttpClient();
  private static OkHttpClient longPollingClient = new OkHttpClient();
  </code></pre>
  
  <p>I've tried having the long polling client set its own connection pool (separate from the default, shared connection pool )</p>
  
  <pre><code>ConnectionPool connectionPool = new ConnectionPool(
      LONG_POLL_CLIENT_CONNECTION_POOL_MAX_CONNECTIONS, // 5
      LONG_POLL_CLIENT_CONNECTION_POOL_KEEP_ALIVE_DURATION_MILLIS // 5 mins
  );
  longPollingClient.setConnectionPool(connectionPool);
  </code></pre>
  
  <p>I've also futzed with its dispatcher:</p>
  
  <pre><code>longPollingClient.getDispatcher().setMaxRequests(5);
  longPollingClient.getDispatcher().setMaxRequestsPerHost(5);
  </code></pre>
  
  <p>But no matter what, calls on the vanilla <code>client</code> are blocked by the <code>longPollingClient</code></p>
  
  <p>Note, I'm using separate AsyncTasks for my calls. Does AsyncTask share a single thread in a thread pool? I'm relatively new to Android, so I'm not certain.</p>