我工作的一段代碼與迭代並獲得在該行一個一個ConcurrentModificationException的,當我從我的IDE上windows--拋出ConcurrentModificationException的系統依賴
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++;
}
這是預期運行的程序,因爲林在迭代時修改列表,以便快速迭代器引發併發修改異常。但是,當我用apache服務器在unix中運行此代碼時,迭代器的下一個方法不會拋出任何異常。那麼,併發修改異常是否取決於操作系統級別?
您確定您的JDK,代碼和數據在兩種環境中都相同嗎?我很抱歉,但我不相信這是可能的。 Java是跨平臺的。 ConcurrentModificationException是從集合中拋出的,也就是從java本身寫成的JDK拋出,所以不能依賴於平臺。 – AlexR 2011-05-19 15:25:02
你應該接受以前的答案.. – 2011-05-19 15:25:33