Java for循環中設置停頓 邏輯代碼中同樣適用
阿新 • • 發佈:2018-12-07
targe https try 博文 src blank ima 版權 java
1\ for (Object object : jsonArray) {
2\ Thread.currentThread().sleep(1000);
3\ list.add(((JSONObject)object).get("Name"));
4\ }
此處的停頓 適用於邏輯代碼和循環 1000的單位為毫秒
停頓後提示一個未處理的異常
此時需要異常處理
1\ //拋出異常
2\ throws InterruptedException
3\ //或者try catch操作
4\ try {
5\ Thread.currentThread().sleep(1000);
6\ } catch (InterruptedException e) {
7\ e.printStackTrace();
8\ }
9\ ---------------------
作者:超級鴻
來源:CSDN
原文:https://blog.csdn.net/weixin_40195422/article/details/84789856
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
Java for循環中設置停頓 邏輯代碼中同樣適用