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

Concurrency Race Condition With 2D Array

Mark
< Prev
Next >

Consider the ArrayUpdater class shown above. If two threads simultaneously call the fill method on the same ArrayUpdater object with different arguments for value, which concurrency issue is most likely to occur?

public class ArrayUpdater {
    private int[][] data = new int[4][4];

    public void fill(int value) {
        for (int i = 0; i < data.length; i++)
            for (int j = 0; j < data[i].length; j++)
                data[i][j] = value;
    }

    public int[][] getData() {
        return data;
    }

    public static void main(String[] args) {
        ArrayUpdater updater = new ArrayUpdater();
        Thread t1 = new Thread(() -> updater.fill(1));
        Thread t2 = new Thread(() -> updater.fill(2));
        t1.start();
        t2.start();
    }
}
A

Null pointer exception because the data array is not initialized.

B

Deadlock due to competing locks on the data array.

C

Array index bounds exception due to incorrect loop boundaries.

D

Race condition that results in a 2D array with a mix of 1s and 2s due to non-atomic fill operations.

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|