Java – throw concurrentmodificationexception system dependency

I'm using the iterator to process a piece of code and get the concurrentmodificationexception on line a when I run the program from the 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++;
   }

This is expected because I modified the list during iteration, so the failed fast iterator threw a concurrency exception However, when I run this code in UNIX using an Apache server, the next method of the iterator does not throw any exceptions So, do concurrent modification exceptions depend on the operating system level?

Solution

No, it shouldn't It should collapse anyway

I think it may be different on different JVMs, but according to the official spec, the iterators on the linked list should fail quickly

The operating system has nothing to do with it

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>