Hurry Up and Wait: Synchronizing Threads Using CyclicBarrier

Remember in primary school at the end of each day, when you waited along with the other students for the school bell to ring? Some classrooms may have finished their day's work earlier than others, but everyone still had to wait for the bell before they could leave. The schools did this to make sure that the students left simultaneously at the proper time (and not a moment earlier!). There are similar situations in an application, where you have a number of threads that depend on each other's results and must all reach some milestone before continuing. In this section, we'll show ...

Get Wicked Cool Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.