并发进行切换代理ip压测的时候 想要知道一共成功请求多少条/失败多少条
- 将请求成功和失败各返回一个字符串 由线程池外的一个map进行接收
- 线程池外在进行map汇总打印结果
Map<Long, Integer> map = new HashMap<Long, Integer>();
// MYObject:为自定义类,取id作为key,然后,进行数目统计
for (MyObject temp : list) {
Integer count = map.get(temp.getId());
map.put(temp.getId(), (count == null) ? 1 : count + 1);
}
// 打印统计
for (Map.Entry<String, Integer> entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey() + " Value : "
+ entry.getValue());
}