Once the server is down, this snippet is keep calling the server repeately, how to stop?
<p>Once the server is down, this snippet is keep calling the server repeatedly, how could I make it stop the repeated calling once the request fails? Maybe a catch/error block? But I'm not sure how to implement it. Thanks!</p>

<pre><code>HttpURLConnection httpConn = null;
InputStream is = null;
OutputStream os = null;
String xmlResponse = null;

try {
   //Open Connection

       String CollectionId="123";
       String GetHTML="1";

       String urlString = "http://tester.com/webservices/ContentWS.asmx/GetCollection?CollectionId="+CollectionId+"&amp;GetHTML="+GetHTML;

       System.out.println(urlString);

       //String encodedUrl = URLEncoder.encode(urlString,"UTF-8");

   URL url = new URL(urlString);
   httpConn = (HttpURLConnection)url.openConnection();

   //Setup Request
   httpConn.setRequestMethod("GET");
   httpConn.setDoOutput(true);
   httpConn.setReadTimeout(10000);
   httpConn.connect();

   xmlResponse = convertStreamToString(httpConn.getInputStream());
  }
  catch (IOException e) {
      e.printStackTrace();
   }

String htmlContent = "";
   try {
       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
       DocumentBuilder db = dbf.newDocumentBuilder();
       InputSource input = new InputSource();
       input.setCharacterStream(new StringReader(xmlResponse));

       Document doc = db.parse(input);
       NodeList nodes = doc.getElementsByTagName("Item");

       // iterate the Items
               int i = 0;
               int j = 0;
               Date now = new Date();
       for (i = 0; i &lt; 2; i++) {
                  //Grab HTML to append to htmlContent
                  NodeList teaser = doc.getElementsByTagName("Html");
                  Element line = (Element) teaser.item(i);
                  htmlContent += getCharacterDataFromElement(line);
       }
   }
   catch (Exception e) {
       e.printStackTrace();
   }
htmlContent = ...
</code></pre>
