/** * Creates a new {@code 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. * * @param parties the number of threads that must invoke {@link #await} * before the barrier is tripped * @param barrierAction the command to execute when the barrier is * tripped, or {@code null} if there is no action * @throws IllegalArgumentException if {@code parties} is less than 1 */ publicCyclicBarrier(int parties, Runnable barrierAction) { if (parties <= 0) thrownewIllegalArgumentException(); this.parties = parties; this.count = parties; this.barrierCommand = barrierAction; }