title: Returning Future from try-resource structure
body: <p>I have the following method which uses Apache Commons Http client sending asynchronous GET to the given URI and returning Future with the response.</p>
  
  <p>CloseableHttpAsyncClient implements Closeable thus I use try/resource constructure.</p>
  
  <pre><code>public static Future&lt;HttpResponse&gt; sendAsyncGet(String uri) throws IOException {
      try (CloseableHttpAsyncClient asyncHttpClient = HttpAsyncClients.createDefault()) {
          asyncHttpClient.start();
          HttpGet httpGet = new HttpGet(uri);
          return asyncHttpClient.execute(httpGet, null);
      }
  </code></pre>
  
  <p>Below you may see the usage:</p>
  
  <pre><code>Future&lt;HttpResponse&gt; future = sendAsyncGet("http://www.apache.org");
  future.get(3, TimeUnit.SECONDS);
  </code></pre>
  
  <p>The problem is that when I call get on a future it doesn't return the desired HttpResponse. It waits until timeout exceeded or forever if I use the overloaded get() method. I guess this is because try/resource wasn't released properly.</p>
  
  <p>How can I improve the given method/code to be able to properly use: Future with try/resource structure included in method body?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>This is maven dependency:</p>
  
  <pre><code>   &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;httpasyncclient&lt;/artifactId&gt;
          &lt;version&gt;4.1.1&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  </code></pre>