是抛出ConcurrentModificationException系统依赖 [英] Is throwing ConcurrentModificationException system dependent
问题描述
我正在使用Iterator工作一段代码,并在Windows上从我的IDE运行程序时在线a上发生ConcurrentModificationException -
I am working on a piece of code with Iterator and getting a ConcurrentModificationException at the line a when I run the program from my IDE on windows--
LinkedList ll =new LinkedList();
. . .
. . .
Iterator iter = ll.iterator();
int i=0;
while (iter.hasNext()) {
// GrammarSection agrammarSection = (GrammarSection) iter.next(); //a
String s1 = (String) iter.next();
ll.remove(i);
i++;
}
这是因为我在迭代时修改列表, -fast iterator抛出Concurrentmodification异常。但是,当我使用apache服务器在unix中运行此代码时,迭代器的下一个方法不会抛出任何异常。那么,并发修改异常是否依赖于操作系统级别?
This is expected because Im modifying the list while I'm iterating so the fail-fast iterator throws a Concurrentmodification exception. However, when I run this code in unix with apache server, the next method of the iterator does-not throw any exception. So, does the concurrentmodification exception depend on OS level ?
推荐答案
不,它不应该。
我想在不同的JVM上可能会有所不同,但根据官方规范,链接列表中的迭代器应该能快速失效。
I suppose it could be different on a different JVM, but according to the official spec, iterators on linked list should be fail-fast.
操作系统与它无关。
这篇关于是抛出ConcurrentModificationException系统依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!