-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFault.java
More file actions
52 lines (29 loc) · 1.21 KB
/
Copy pathMainFault.java
File metadata and controls
52 lines (29 loc) · 1.21 KB
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
44
// this will stimulate a fault occuring after a random time within the first 10 seconds
// this will start a backup elevator and remove the people currently in the elevator to a backup elevator
import java.util.*;
import java.lang.*;
import java.util.Timer;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.Random;
public class MainFault{
public static void main(String[] args) throws InterruptedException{
ElevatorController elevatorController = new ElevatorController();
// if the boolean true is added to the constructor a fault will be created
Elevator elevator = new Elevator(elevatorController, true);
// start the elevator and wait for request
elevator.start();
// create thread pool
ExecutorService executor = Executors.newFixedThreadPool(20);
// create 20 random people to show the transfer of people from faulty elevator to backup elevator
Person[] people = new Person[20];
for (int i=0; i<20; i++){
people[i] = new Person(elevatorController);
}
for (Person p: people){
executor.submit(p);
}
executor.shutdown();
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES);
}
}