Concurrent ArrayList Modification
Consider the following code. What is the most likely issue to arise when multiple threads concurrently modify the unsynchronized ArrayList?
import java.util.ArrayList;
public class EndlessAdd {
static ArrayList<Integer> list = new ArrayList<>();
public static void main(String[] args) {
for (int i = 0; i < 50; i++) {
new Thread(() -> {
for (int j = 0; j < 1000; j++) {
list.add(j);
}
}).start();
}
}
}
A
ConcurrentModificationException triggered by bulk additions
B
Deadlock due to too many threads acquiring locks simultaneously
C
Race conditions leading to data corruption and unpredictable list state
D
OutOfMemoryError due to rapid, unbounded growth of the ArrayList
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE