concurrentmodificationexceptionMap

fslejnso  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(91)

为什么我要得到 ConcurrentModificationException . 对于这种编程风格,它不应该出现。我错过什么了吗?我找不到解决那个问题的办法。这段代码是用@scheduled in spring每秒调用一次的。

Iterator<Entry<String, Integer>> iterator = map.entrySet().iterator();
     while (iterator.hasNext()) {
        Entry<String, Integer> entry= iterator.next(); // this row throw the expection
        while (entry.getValue().compareTo(value) <= 0) {
        iterator.remove();
        }
      }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题