Are you taking CLEP classes? Try clep.ai
| 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

Mark
< Prev
Next >

Consider the BatchUpdater class provided below. If multiple threads call the updateData() method concurrently, which statement best describes the most likely outcome for the data array?

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

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

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

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

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|