Questions tagged «concurrentmodification»

10
为什么在此示例中没有得到java.util.ConcurrentModificationException?
注意:我知道该Iterator#remove()方法。 在下面的代码示例中,我不明白为什么List.remove在main方法抛出ConcurrentModificationException,但不是在remove方法。 public class RemoveListElementDemo { private static final List<Integer> integerList; static { integerList = new ArrayList<Integer>(); integerList.add(1); integerList.add(2); integerList.add(3); } public static void remove(Integer toRemove) { for(Integer integer : integerList) { if(integer.equals(toRemove)) { integerList.remove(integer); } } } public static void main(String... args) { remove(Integer.valueOf(2)); Integer toRemove = Integer.valueOf(3); for(Integer …

8
为什么会引发ConcurrentModificationException以及如何对其进行调试
我正在使用Collection(HashMapJPA间接使用的a ,它确实发生了),但显然代码是随机抛出的ConcurrentModificationException。是什么原因引起的,如何解决此问题?通过使用一些同步,也许吗? 这是完整的堆栈跟踪: Exception in thread "pool-1-thread-1" java.util.ConcurrentModificationException at java.util.HashMap$HashIterator.nextEntry(Unknown Source) at java.util.HashMap$ValueIterator.next(Unknown Source) at org.hibernate.collection.AbstractPersistentCollection$IteratorProxy.next(AbstractPersistentCollection.java:555) at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296) at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242) at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219) at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169) at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.