Example of Simple Retry Technique to Deal with Timeouts in Android

 <div><a href="http://orderessayonlineon.com/">academic writing help online</a> - <a href="http://spyphoneapp-software.com/">software spy phone download</a> - <a href="http://iphonespyapponline.com/">iphone spy</a> - <a href="http://buyessay-onlinein.com/">coursework writing service</a> - <a href="http://cellphonespyappon.com/">spy cell phone voicemail</a> - <a href="http://orderessayonlineon.com/">do my essay for money</a> - <a href="http://cellphonespyappon.com/">cell phone spy iphone free</a></div>  import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URI; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; public class TestHttpGet { public String executeHttpGetWithRetry() throws Exception { int retry = 3; int count = 0; while (count &lt; retry) { count += 1; try { String response = executeHttpGet(); /** * if we get here, that means we were successful and we can * stop. */ return response; } catch (Exception e) { /** * if we have exhausted our retry limit */ if (count &lt; retry) { /** * we have retries remaining, so log the message and go * again. */ System.out.println(e.getMessage()); } else { System.out.println(&quot;could not succeed with retry...&quot;); throw e; } } } return null; } public String executeHttpGet() throws Exception { BufferedReader in = null; try { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); request.setURI(new URI(&quot;http://w3mentor.com/&quot;)); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(&quot;&quot;); String line = &quot;&quot;; String NL = System.getProperty(&quot;line.separator&quot;); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); String result = sb.toString(); return result; } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } }

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.