exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 57 discussion

Actual exam question from Oracle's 1z0-809
Question #: 57
Topic #: 1
[All 1z0-809 Questions]

Given:
class Worker extends Thread {
CyclicBarrier cb;
public Worker(CyclicBarrier cb) { this.cb = cb; }
public void run () {
try {
cb.await();
System.out.println("Worker"¦");
} catch (Exception ex) { }
}
}
class Master implements Runnable { //line n1
public void run () {
System.out.println("Master"¦");
}
}
and the code fragment:
Master master = new Master();
//line n2
Worker worker = new Worker(cb);
worker.start();
You have been asked to ensure that the run methods of both the Worker and Master classes are executed.
Which modification meets the requirement?

  • A. At line n2, insert CyclicBarrier cb = new CyclicBarrier(2, master);
  • B. At line n2, insert CyclicBarrier cb = new CyclicBarrier(1);
  • C. At line n2, insert CyclicBarrier cb = new CyclicBarrier(1, master);
  • D. At line n2, insert CyclicBarrier cb = new CyclicBarrier(master);
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
aymanj
Highly Voted 3 years, 4 months ago
Correct answer is C .. CyclicBarrier constructor takes as arguments the maximum number of threads until release and a Runnable Object .. CyclicBarrier cb = new CyclicBarrier( int i , RunnableObject) ;
upvoted 7 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 3 weeks ago
C is the Correct answer
upvoted 1 times
...
steefaand
5 months, 3 weeks ago
Selected Answer: C
C is correct, since second argument for CyclicBarrier is Runnable which will be executed when barrier is fulfilled.
upvoted 1 times
...
WilsonKKerll
2 years, 4 months ago
Answer is C. Output : Master! Worker. Question is 'both the Worker and Master classes are executed'. If new CyclicBarrier(1); is output : Worker.
upvoted 1 times
...
Svetleto13
3 years, 3 months ago
C,tested
upvoted 2 times
...
lxktnjjn
3 years, 3 months ago
Answer is B. Constructors for CyclicBarrier CyclicBarrier(int parties), CyclicBarrier(int parties, Runnable barrierAction) - Creates a new CyclicBarrier that will trip when the given number of parties (threads) are waiting upon it, and which will execute the given barrier action when the barrier is tripped, performed by the last thread entering the barrier So 2nd parameter is what will be done after tripping barrier.
upvoted 1 times
lxktnjjn
3 years, 3 months ago
In question there is no need to execute Master 2nd time.
upvoted 2 times
xijxeyho
3 years, 3 months ago
C is OK. Master is executed as Runnable.
upvoted 2 times
...
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago