jjzjj

ConcurrentModificationException

全部标签

java - 抛出 ConcurrentModificationException 系统依赖

我正在使用Iterator处理一段代码,当我在Windows上从我的IDE运行该程序时,在a行得到了一个ConcurrentModificationException--LinkedListll=newLinkedList();......Iteratoriter=ll.iterator();inti=0;while(iter.hasNext()){//GrammarSectionagrammarSection=(GrammarSection)iter.next();//aStrings1=(String)iter.next();ll.remove(i);i++;}这是预料之中的,因为

Java Collections.sort() 缺少 ConcurrentModificationException

我偶然发现了这个奇怪的错误。似乎Collections.sort()不会以一种在迭代同一列表时能够检测并发修改的方式修改排序列表。示例代码:Listmy_list=newArrayList();my_list.add(2);my_list.add(1);for(Integernum:my_list){/**printlist*/StringBuildersb=newStringBuilder();for(Integeri:my_list)sb.append(i).append(",");System.out.println("List:"+sb.toString());/**sortl

在 ArrayList 中插入时出现 java.util.ConcurrentModificationException

这个问题在这里已经有了答案:Howtoavoidjava.util.ConcurrentModificationExceptionwheniteratingthroughandremovingelementsfromanArrayList(24个答案)关闭9年前。importjava.util.ArrayList;importjava.util.Iterator;importjava.util.ListIterator;publicclassMyList{publicstaticvoidmain(String[]args){ArrayListal=newArrayList();al.a

java - 清除子列表时出现 ConcurrentModificationException

这个问题在这里已经有了答案:WhyisaConcurrentModificationExceptionthrownandhowtodebugit(8个答案)关闭3年前。为什么当我在主列表之后清除子列表时,下面的代码会抛出ConcurrentModificationExcrption,但如果我先清除子列表,然后再清除主列表,则不会?ArrayListmasterList=newArrayList();ListsubList;//AddsomevaluestothemasterListfor(inti=0;i

java - 为什么即使同步了列表也会出现ConcurrentModificationException?

我有Android多线程应用程序。两个或多个触发器可能会运行同一部分代码。我有一个对象列表。我让它被Collections.synchronizedList同步privateListmGroupItemSampleList;mGroupItemSampleList=newArrayList();mGroupItemSampleList=Collections.synchronizedList(mGroupItemSampleList);但是有时我在线上遇到异常:Collections.sort(mGroupItemSampleList,newGroupItemSampleCompara

java - 基于其中元素数量的 java.util.List 的异常行为

这个问题在这里已经有了答案:WhyisaConcurrentModificationExceptionthrownandhowtodebugit(8个答案)关闭3年前。我知道如果在某些线程使用迭代器遍历集合时更改集合,iterator.next()将抛出ConcurrentModificationException。.但它会根据列表中元素的数量显示不同的行为。我尝试了一个代码片段,其中我在for-each循环中遍历了一个列表,并在遍历之间使用列表的remove()方法从列表中删除了一个元素。理想情况下,它应该在这种情况下抛出ConcurrentModificationException

java - 在 ConcurrentModificationException 之后,Java 集合是否保证处于有效、可用的状态?

我正在使用ImmediateModeGUIpattern编写一个GUI应用程序,并且UI在独立于为应用程序的实际功能提供支持的引擎的线程上运行。GUI线程最终迭代许多概念上由引擎线程“拥有”的对象列表,并且这些列表极少更改。GUI线程是垂直同步的,这意味着它以大约60Hz的频率运行,而引擎线程以大约200Hz的频率运行。有时,UI中的操作会更改引擎中集合的内容,我有一个消息传递系统将Runnable发布到引擎线程以执行这些突变,以确保这些突变不会与引擎中的内容发生冲突发生在引擎中。这样,我可以确保引擎始终看到一致的数据View,这对我的应用程序非常重要。因为引擎负责所有的数据变化,所以

添加另一个对象时出现 java.util.ConcurrentModificationException

我正在为这个异常而苦恼。我的代码有什么问题?我只想在另一个ArrayList中分隔Person的重复名称publicclassGlennTestMain{staticArrayListps;staticArrayListduplicates;publicstaticvoidmain(String[]args){ps=newArrayList();duplicates=newArrayList();noDuplicate(newPerson("Glenn",123));noDuplicate(newPerson("Glenn",423));noDuplicate(newPerson("J

java - HashMap 的迭代器是快速失败而 HashTable 的枚举器不是?

我正在查找这两个类之间的区别,这一点出现在很多答案中,这个博客是来源:http://javarevisited.blogspot.com/2010/10/difference-between-hashmap-and.html但是我并不完全明白。有人可以详细说明吗?也许举个例子?感谢关注! 最佳答案 Fail-fast意味着当您在遍历内容时尝试修改内容,它将失败并抛出ConcurrentModificationException。Setkeys=hashMap.keySet();for(Objectkey:keys){hashMap.

Java : ConcurrentModificationException while iterating over list

这个问题在这里已经有了答案:IteratingthroughaCollection,avoidingConcurrentModificationExceptionwhenremovingobjectsinaloop(31个答案)WhyisaConcurrentModificationExceptionthrownandhowtodebugit(8个答案)关闭3年前。当我执行下面的代码时,我得到了ConcurrentModificationExceptionCollectionmyCollection=Collections.synchronizedList(newArrayList(1