这是我的代码:
private void synCampaign() {
List<Campaign> 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();
}
}
AdwordsCampaign.getAllCampaign()
试图获取一些远程资源。这可能会抛出一个RemoteException
,因为互联网连接超时。当异常被捕获时,我只想让线程休眠一段时间,然后再次尝试获取远程资源。
我的代码有问题吗?或者,还有更好的方法?