exam questions

Exam 1z0-819 All Questions

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

Exam 1z0-819 topic 1 question 28 discussion

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

Given the code fragment:

Which statement is true?

  • A. It never finishes.
  • B. The action of CyclicBarrier is called five times.
  • C. It finishes without any exception.
  • D. Threads in executorService execute for each of the two threads.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

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
ASPushkin
3 weeks, 3 days ago
Selected Answer: A
A. correct Once 2 threads are waiting at the CyclicBarrier, all threads are released and can continue running. It happens two times. So, last 5th thread is waiting forever. conditions to go through : The last thread arrives; or Some other thread interrupts the current thread; or Some other thread interrupts one of the other waiting threads; or Some other thread times out while waiting for barrier; or Some other thread invokes reset() on this barrier. If any thread is interrupted while waiting, then all other waiting threads will throw BrokenBarrierException and the barrier is placed in the broken state. B. wrong it called two times C. wrong it never finishes D. is not correct Threads in executorService execute for each threads (5).
upvoted 1 times
...
ASPushkin
4 months, 1 week ago
Selected Answer: A
D. failed The barrier is called cyclic because it can be re-used after the waiting threads are released. The number of executed threads will be a multiple of two. it will be 4 out of 5 threads. A. correct Once 2 threads are waiting at the CyclicBarrier, all threads are released and can continue running. It happens two times. So, last 5th thread is waiting forever.
upvoted 1 times
...
d7bb0b2
1 year ago
C: finish ok and print the list ANY ORDER [1, 3, 2, 0, 4]
upvoted 1 times
d7bb0b2
1 year ago
wait a moment lol: A is correct :D not fisnish: Explanation: A. It does finish. After all threads reach the barrier, the action of the CyclicBarrier is executed and then the executor service is shut down. B. The action of CyclicBarrier is called only once when all five threads reach the barrier. C. It finishes without any exception. The CyclicBarrier ensures that all threads have reached a common barrier point before proceeding. If any thread is interrupted while waiting, it will throw an InterruptedException, and if the barrier is broken while a thread is waiting, it will throw a BrokenBarrierException. However, these exceptions are caught and handled in the code. D. The ExecutorService executes a task for each of the five threads, not two.
upvoted 2 times
...
...
duydn
1 year, 2 months ago
Selected Answer: A
public static void main(String[] args) { List<Integer> list = new CopyOnWriteArrayList<>(); ExecutorService executorService = Executors.newFixedThreadPool(5); CyclicBarrier barrier = new CyclicBarrier(2, () -> System.out.println(list)); IntStream.range(0,5).forEach(n -> executorService.execute(() -> { try { list.add(n); barrier.await(); } catch (InterruptedException | BrokenBarrierException e) { System.out.println("err"); } })); executorService.shutdown(); } -> A
upvoted 1 times
...
RoxyFoxy
1 year, 2 months ago
Selected Answer: A
it never finishes.
upvoted 1 times
...
eldonivan
1 year, 4 months ago
If you run this in the compiler, it outputs but check the run, it does not stop. it does not finish
upvoted 1 times
...
Matt_G
1 year, 6 months ago
Selected Answer: A
Running this locally, the code never finishes and the contents of the list is printed out twice (which may be in a random order). As the CyclicBarrier has a party count of two, and an odd number of threads, there will always remain one thread waiting on the barrier. Change to adding 6 numbers and it will finish fine.
upvoted 4 times
...
Stavok
1 year, 7 months ago
Selected Answer: C
It finishes smoothly, TESTED
upvoted 1 times
...
Mukes877
1 year, 7 months ago
Selected Answer: B
The correct statement is: B. The action of CyclicBarrier is called five times. Explanation: The code creates a CyclicBarrier with a party size of 2 and an action that prints the list. It then launches 5 threads using the executorService, each adding an element to the list and waiting at the barrier using barrier.await(). Since the party size is 2, the barrier action will be triggered when 2 threads reach the barrier. As there are 5 threads, this will happen a total of 5/2 = 2 times. Each time the barrier action is called, it will print the current state of the list. Therefore, option B is the correct statement. The action of the CyclicBarrier is called five times.
upvoted 1 times
...
SuperDabicho
1 year, 8 months ago
Selected Answer: C
It finished cool, guys (Option C is correct)
upvoted 1 times
...
Londeka
1 year, 11 months ago
C is correct.
upvoted 1 times
...
TADIEWA
2 years ago
A is correct
upvoted 4 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