nerdexam
Oracle

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…

Concurrency

Question

Given:

Which of the four are valid modifications to synchronize access to the valid list between threads t1 and t2?

Exhibit

1Z0-804 question #102 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)
  • A
    2% (1)
  • B
    85% (41)
  • E
    8% (4)
  • F
    4% (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

#thread synchronization#synchronized list#volatile#concurrent access

Community Discussion

No community discussion yet for this question.

Full 1Z0-804 Practice