1Z0-804 · Question #102
Given: Which of the four are valid modifications to synchronize access to the valid list between threads t1 and t2?
The correct answer is B. Replace Line 2 with: C. Replace line 3 with: D. Replace line 4 with: G. Replace line 6 with. Away to create synchronized code is with synchronized statements. Unlike synchronized methods, synchronized statements must specify the object that provides theintrinsic lock: public void addName(String name) { synchronized(this) { lastName = name; nameList.add(name); In this…
Question
Given:
Which of the four are valid modifications to synchronize access to the valid list between threads t1 and t2?
Exhibit
Options
- AReplace line 1 with:
- BReplace Line 2 with:
- CReplace line 3 with:
- DReplace line 4 with:
- EReplace line 5 with:
- Freplace line 6 with:
- GReplace line 6 with:
How the community answered
(48 responses)- A2% (1)
- B85% (41)
- E8% (4)
- F4% (2)
Explanation
Away to create synchronized code is with synchronized statements. Unlike synchronized methods, synchronized statements must specify the object that provides theintrinsic lock: public void addName(String name) { synchronized(this) { lastName = name; nameList.add(name); In this example, the addName method needs to synchronize changes to lastName and nameCount, but alsoneeds to avoid synchronizing invocations of other objects' methods. Without synchronized statements, therewould have to be a separate, unsynchronized method for the sole purpose of invoking nameList.add.
Topics
Community Discussion
No community discussion yet for this question.
