added ex U
This commit is contained in:
23
src/exercises/ex_u/TestingCountDownLatch_FamilyTrip.java
Normal file
23
src/exercises/ex_u/TestingCountDownLatch_FamilyTrip.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package exercises.ex_u;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class TestingCountDownLatch_FamilyTrip {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Vehicle seatAlhambra = new Vehicle();
|
||||
seatAlhambra.printVehicleContent();
|
||||
String[] family = {"Jean", "Anna", "Joseph", "Martha", "Eleonore", "Paul", "Catarina"};
|
||||
// Create a countDownLatch
|
||||
CountDownLatch countDownLatch = new CountDownLatch(family.length);
|
||||
|
||||
// Start the family members
|
||||
// and synchronize them before the start
|
||||
for (int i = 0; i < family.length; i++) {
|
||||
new Thread(new FamilyMember(family[i], seatAlhambra, countDownLatch)).start();
|
||||
}
|
||||
countDownLatch.await();
|
||||
|
||||
seatAlhambra.printVehicleContent();
|
||||
System.out.println("Family trip can start");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user