ConcurrentModificationException : This exception may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible.<
The reason you are not receiving a ConcurrentModificationException
is that ArrayList.remove
does not throw one. You can probably get one by starting an additional thread that iterates through the array:
final List tickets = new ArrayList(100000);
for (int i = 0; i < 100000; i++) {
tickets.add("ticket NO," + i);
}
for (int i = 0; i < 10; i++) {
Thread salethread = new Thread() {
public void run() {
while (tickets.size() > 0) {
tickets.remove(0);
System.out.println(Thread.currentThread().getId()+"Remove 0");
}
}
};
salethread.start();
}
new Thread() {
public void run() {
int totalLength = 0;
for (String s : tickets) {
totalLength += s.length();
}
}
}.start();