title: Cassandra Asyn connection limit
body: <p>I get the data from one table and then I iterate on that ResultSet to fetch data from another table ( executeAsync() ). I want to control the number of async tasks. </p>
  
  <pre><code>for(Row row : resultSites) {
          String siteName = row.getString("site_name");
          System.out.println(siteName);
          ResultSetFuture future = casCon.session.executeAsync(casCon.boundStatement.bind(siteName));
          Futures.addCallback(future,fCR,MoreExecutors.listeningDecorator(executorService));
      }
  </code></pre>
  
  <p>My Executor and FutureCallback are </p>
  
  <pre><code>    ExecutorService executorService = Executors.newFixedThreadPool(2);
      FutureCallback&lt;ResultSet&gt; fCR = new FutureCallback&lt;ResultSet&gt;() {
                  @Override public void onSuccess(ResultSet result) {
                      System.out.println(result.one());
                  }
                  @Override public void onFailure(Throwable t) {
                  System.out.println("Error while reading Cassandra version: " + t.getMessage());
              }
          };
  </code></pre>
  
  <p>Now by searching I found this and implemented it in my code</p>
  
  <pre><code>PoolingOptions poolingOpts = new PoolingOptions();
              poolingOpts.setCoreConnectionsPerHost(HostDistance.REMOTE, 2);
                 poolingOpts.setMaxConnectionsPerHost(HostDistance.REMOTE, 4);
                 poolingOpts.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.REMOTE, 10);
                 poolingOpts.setMinSimultaneousRequestsPerConnectionThreshold(HostDistance.REMOTE, 2);
                 poolingOpts.setMinSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 2);
                 poolingOpts.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, 10);
  
  
              cluster = Cluster.builder().addContactPoint(ip)
                      .withLoadBalancingPolicy(new DCAwareRoundRobinPolicy())
                      .withPoolingOptions(poolingOpts)
                      .withCredentials(user, pass)
                      .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
                      .build();
  </code></pre>
  
  <p>But when I call </p>
  
  <pre><code>System.out.println(session.getCluster().getConfiguration().getPoolingOptions().getMaxConnectionsPerHost(HostDistance.REMOTE));
  </code></pre>
  
  <p>I get null pointer exception so I am not sure if I have implemented it properly ? Any help or suggestions ?</p>