java.util.ConcurrentModificationException 集合不安全导致
并发操作集合产生的异常,使用安全的集合即可解决,安全集合如下;
List:
- List list = new Vector<>();
- List list = new CopyOnWriteArrayList();
- List list = Collections.synchronizedList(new ArrayList<>());
Set:
- Set set = new CopyOnWriteArraySet();
- Set set = Collections.synchronizedSet(new HashSet<>());
Map:
- Map<String, String> map = new ConcurrentHashMap<>();
- Map<String,String> map = Collections.synchronizedMap(new HashMap<>());