/* Taken from https://java2blog.com/java-cyclicbarrier-example/ (accessed 24.08.2022) and slightly modified. */ import java.util.concurrent.CyclicBarrier; public class CyclicBarrierMain { public static void main(String[] args) { /* * When 5 students have arrived, the party can start. */ Runnable startParty = new StartParty(); CyclicBarrier cyclicBarrier = new CyclicBarrier(5 , startParty); Student student1 = new Student(cyclicBarrier,1000); Student student2 = new Student(cyclicBarrier,2000); Student student3 = new Student(cyclicBarrier,3000); Student student4 = new Student(cyclicBarrier,1000); Student student5 = new Student(cyclicBarrier,2000); Student student6 = new Student(cyclicBarrier,3000); //Create and start 6 threads new Thread(student1,"Student-1").start(); new Thread(student2,"Student-2").start(); new Thread(student3,"Student-3").start(); new Thread(student4,"Student-4").start(); new Thread(student5,"Student-5").start(); new Thread(student6,"Student-6").start(); } }