title: How to deal with timeout exception in Java?
body: <p>Here is my code:</p>
  
  <pre><code> private void synCampaign() {
      List&lt;Campaign&gt; campaigns;
      try {
          campaigns = AdwordsCampaign.getAllCampaign();
          for(Campaign c : campaigns) 
              CampaignDao.save(c);
      } catch (ApiException e) {
          try {
              Thread.sleep(5000);
          } catch (InterruptedException e1) {
              e1.printStackTrace();
          }
          synCampaign();
          e.printStackTrace();
      } catch (RemoteException e) {
          try {
              Thread.sleep(5000);
          } catch (InterruptedException e1) {
              e1.printStackTrace();
          }
          synCampaign();
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p><code>AdwordsCampaign.getAllCampaign()</code> tries to get some remote resource. This may throw a <code>RemoteException</code> because the internet connection times out. When the exception is caught, I just want the thread to sleep for a while, then try to get the remote resource again. </p>
  
  <p>Is there a problem with my code? Or is there a better way?</p>