title: java.lang.IllegalStateException: Connection pool shut down
body: <p>I am trying to post data to a REST service using Http and I have configured my client as follows: </p>
  
  <pre><code>PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
          cm.setMaxTotal(60);
          cm.setDefaultMaxPerRoute(60);
          CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm).build();
          HttpPost httpPost = new HttpPost(url);
          httpPost.setHeader("Accept", "application/json");
          httpPost.setHeader("Content-type", "application/json");
          CloseableHttpResponse response = null;
  </code></pre>
  
  <p>Now I have an executor service which is responsible for calling the actual posting, I hand over the above params to Executor service as follows: </p>
  
  <pre><code>executor.execute(new LocalThreadPoolExecutor(line, client, httpPost,response ));
  </code></pre>
  
  <p>line is the JSON payload I am trying to send across. </p>
  
  <p>Now my method in executor service looks like: </p>
  
  <pre><code>private void postData(String data, CloseableHttpClient client, HttpPost httpPost,
                           CloseableHttpResponse response) throws Exception {
          System.out.println("Post hit");
          StringEntity entity = new StringEntity(data);
          httpPost.setEntity(entity);
          response = client.execute(httpPost);
          int code = response.getStatusLine().getStatusCode();
          System.out.println("Stat" + code);
  
          logger.info("Response Code: " + code);
  
          String temp;
          String builder = "Response: ";
          BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  
          while ((temp = bufferedReader.readLine()) != null) {
              builder = builder + (temp + "\n");
          }
  
          System.out.println(builder);
          //logger.info(payload);
          client.close();
      }
  </code></pre>
  
  <p>And and I am getting an exception at <code>response = client.execute(httpPost);</code></p>
  
  <p>Which is: </p>
  
  <pre><code>java.lang.IllegalStateException: Connection pool shut down
      at org.apache.http.util.Asserts.check(Asserts.java:34)
      at org.apache.http.pool.AbstractConnPool.lease(AbstractConnPool.java:189)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:257)
      at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:176)
      at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
      at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
      at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
      at consumer.ril.com.LocalThreadPoolExecutor.postData(LocalThreadPoolExecutor.java:80)
      at consumer.ril.com.LocalThreadPoolExecutor.run(LocalThreadPoolExecutor.java:40)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  java.lang.IllegalStateException: Connection pool shut down
      at org.apache.http.util.Asserts.check(Asserts.java:34)
      at org.apache.http.pool.AbstractConnPool.lease(AbstractConnPool.java:189)
      at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:257)
      at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:176)
      at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
      at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
      at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
      at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
      at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
      at consumer.ril.com.LocalThreadPoolExecutor.postData(LocalThreadPoolExecutor.java:80)
      at consumer.ril.com.LocalThreadPoolExecutor.run(LocalThreadPoolExecutor.java:40)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>I know where the problem is, however I am unable to determine how to solve it! </p>
  
  <p>Any help would be highly appreciated!</p>