title: HttpURLConnection inside a loop
body: <p>I'm trying to connect to one URL that I know that exist but I don't know when.
  I don't have access to this server so I can't change anything to receive a event.</p>
  
  <p>The actual code is this.</p>
  
  <pre><code>URL url = new URL(urlName);
  for(int j = 0 ; j&lt; POOLING &amp;&amp; disconnected; j++){
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      int status = connection.getResponseCode();
      if(status == HttpURLConnection.HTTP_OK || status == HttpURLConnection.HTTP_NOT_MODIFIED){
          //Some work
      }else{
          //wait 3s
          Thread.sleep(3000);       
      }
  }
  </code></pre>
  
  <p>Java not is my best skill and I'm not sure if this code is good from the point of view of performance.
  I'm opening a new connection every 3 seconds? or the connection is reused?</p>
  
  <p>If I call to disconnect() I ensure that no new connections are open in the loop, but... it will impact in performance?.</p>
  
  <p>Suggestions? What is the fast/best ways to know it a URL exist?</p>