List<String> ips = new ArrayList<String>();Map<String, Boolean> map = new HashMap<String, Boolean>();// 线程数量CountDownLatch latch = new CountDownLatch(ips.size());System.out.println(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));ips.forEach(ip -> { Thread thread = new Thread() { public void run() { map.put(ip, PortConnectUtil.connect(ip)); // 线程计数器 latch.countDown(); } }; thread.start();});// 1. 所有线程执行完毕再进行下面的操作latch.await();System.out.println(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));System.out.println(map);