如何list循环遍历元素时不会因为某个元素执行业务时而中断列表中所有元素继续执行

List list = new ArrayList<>();
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
              List list = new ArrayList<>();
        List interruptList = new ArrayList<>();
        List connectList = new ArrayList<>();
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.add("https://www.csdn.net/?spm=1001.2101.3001.4476");
        list.parallelStream().forEach(item -> {
            try {
                String resString = HttpClientUtil.doPostJsonParams(item, "{}");
                SynchronizeCompany.CompanyResult companyResult = JSON.parseObject(resString, SynchronizeCompany.CompanyResult.class);
                if (companyResult.getResult().equals("success")) {
                    connectList.add(item);
                } else {
                    interruptList.add(item);
                }
            } catch (Exception e) {
                e.printStackTrace();
                interruptList.add(item);
            }
        });

你可能感兴趣的:(Java,list,java)