(022)FastJson 序列化导致的 java.util.ConcurrentModificationException
·
问题
- 在应用启动的时候,程序出现异常。存储类的部分字段如下:

- 每分钟进行检测:

- 出现了:

解决
- ConcurrentHashMap 是线程安全,这个问题,是因为 SiegeWarRoomCache 通过 FastJson 存储在 redis中,在启动的时候加载。虽然字段做了
的处理,但是在 FastJson 发序列化的时候,该字段的值被覆盖private Set<Long> roomActors = new ConcurrentHashSet<>();
正确的应该是:public Set<Long> getRoomActors() { return roomActors; } public void setRoomActors(Set<Long> roomActors) { this.roomActors = roomActors; }public Set<Long> getRoomActors() { return roomActors; } public void setRoomActors(Set<Long> roomActors) { this.roomActors.clear(); this.roomActors.addAll(roomActors); }
更多推荐



所有评论(0)