用while多次呼叫一個方法
阿新 • • 發佈:2020-07-02
public static boolean download(String url, String api_key, String sign,
List<BasicNameValuePair> parameList, RenameDownload rename) throws InterruptedException, IOException {
boolean flag = down(url, api_key, sign, parameList, rename);
int i = 0;
while (flag == false && i < 4) {
LOG.info(LanguageUtils.message.getSTATUS_CODE() + FAIL + "," + LanguageUtils.message
.getTIPS_DOWN_FAIL() + "----" + "第" + (i + 1) + "次下載失敗嘗試重新下載");
Thread.sleep(5 * 1000); //設定暫停的時間 5 秒
flag = down(url, api_key, sign, parameList, rename);
i++;
if (flag == true) {
break;
}
}
return flag;
}
public static boolean down(String url, String api_key, String sign, List<BasicNameValuePair>
parameList, RenameDownload rename) {
return true;
}
return 返回值反給呼叫本函式的函式:比如這裡的down的返回值return true,這個true 會傳給download裡的flag
然後用flag去做一些判斷等操作