Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
hard

ArrayList Concurrent Modification

Mark
< Prev
Next >

Which potential concurrency issue is demonstrated by the execution of the following code snippet?

import java.util.ArrayList;

public class ExceptionThread {
    static ArrayList<Integer> list = new ArrayList<>();
    public static void main(String[] args) {
        list.add(1);
        list.add(2);
        Thread t = new Thread(() -> {
            try {
                list.remove(0);
            } catch(Exception e) {
                System.out.println("Error");
            }
        });
        t.start();
        // Main thread iterates concurrently without synchronization
        for (Integer i : list) {
            System.out.println(i);
        }
    }
}
A

Race condition in the computation of element removal

B

Deadlock due to the exception handling block locking the entire list

C

Memory barrier violation because of the generic exception catch block

D

Concurrent modification of the list during iteration that may trigger a ConcurrentModificationException

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|