-
Notifications
You must be signed in to change notification settings - Fork 0
/
Turf.java
43 lines (33 loc) · 1002 Bytes
/
Turf.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package ch.hslu.AD.SW06.HorseRace;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Logger;
public class Turf {
private static final Logger LOG = Logger.getLogger("RaceHorse");
private static final int STARTER_BOXES = 5;
public static void main(String[] args) {
Sync starterBox = new Latch();
List<Thread> horses = new ArrayList<>();
for(int i = 1; i < 1 + STARTER_BOXES; i++) {
Thread t = new Thread(new RaceHorse(starterBox), "Horse " + i);
horses.add(t);
t.start();
}
LOG.info("Pferde bereit machen ...");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LOG.info("Start ...");
starterBox.release();
LOG.info("Pruefen ob Startabbruch notwendig ...");
//if(new Random().nextInt(2) == 0) {
if(false) {
LOG.info("Fehlstart - Startabbruch notwendig.");
horses.stream().forEach(t -> t.interrupt());
}
}
}