Answer is A, tested
public static void main(String[] args) {
final List<String> list = new CopyOnWriteArrayList<>();
final AtomicInteger ai = new AtomicInteger(0);
final CyclicBarrier barrier = new CyclicBarrier(2, new Runnable() {
@Override
public void run() {
System.out.println(list);
}
});
Runnable r = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000 * ai.incrementAndGet());
list.add("X");
barrier.await();
}catch (Exception e){
}
}
};
new Thread(r).start();
new Thread(r).start();
new Thread(r).start();
new Thread(r).start();
}
output :
[X, X]
[X, X, X, X]
//CyclicBarrier works for all every 2 threads reached to the barrier
This section is not available anymore. Please use the main Exam Page.1z0-809 Exam Questions
Log in to ExamTopics
Sign in:
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.
jduarte
Highly Voted 3 years, 11 months agosteefaand
Most Recent 10 months, 4 weeks agoMatthewTannous
2 years, 5 months agoSvetleto13
3 years, 7 months agoSvetleto13
3 years, 7 months agoAbdullah_Rahahleah
4 years agopul26
4 years agoTarik2190
3 years, 7 months ago