Turf.java
package ch.hslu.exercises.sw06.ex2;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore;
public final class Turf {
private static final Logger LOG = LoggerFactory.getLogger(Turf.class);
private static final int HORSES = 5;
private Turf() {
}
/**
* Main-Demo.
*
* @param args not used.
*/
public static void main(final String[] args) throws InterruptedException {
final Synch starterBox = new Latch();
final Semaphore counter = new Semaphore(HORSES);
List<Thread> threads = new ArrayList<>();
for (int i = 1; i <= HORSES; i++) {
threads.add(Thread.startVirtualThread(new RaceHorse(starterBox, "Horse " + i, counter)));
}
counter.acquire(HORSES);
starterBox.release();
LOG.info("Start...");
for (Thread thread : threads) {
thread.join();
}
}
}