| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
hard
Java Thread Synchronization Scope
< Prev
Next >

If multiple threads call updateData() simultaneously, what issue is most likely to occur with respect to the array ‘data’?

public class BatchUpdater {
    private int[] data = new int[100];
    
    public void updateData() {
        for (int i = 0; i < data.length; i++) {
            synchronized(this) {
                data[i] += 1;
            }
        }
    }
}
A

Other threads might observe a partially updated array state since synchronization is applied per iteration rather than for the whole loop.

B

A race condition is completely prevented due to the synchronized block in every iteration.

C

Deadlock will occur because each iteration synchronizes on the same object repeatedly.

D

The program will throw an exception due to concurrent modifications of an array.

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.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy