-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainMultipleElevators.java
More file actions
65 lines (34 loc) · 1.2 KB
/
Copy pathMainMultipleElevators.java
File metadata and controls
65 lines (34 loc) · 1.2 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
45
46
47
48
49
50
51
52
53
54
55
56
57
// this will create 2 elevators
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 MainMultipleElevators{
public static void main(String[] args) throws InterruptedException{
// create two elevators
ElevatorController elevatorController1 = new ElevatorController();
ElevatorController elevatorController2 = new ElevatorController();
Elevator elevator1 = new Elevator(elevatorController1);
Elevator elevator2 = new Elevator(elevatorController2);
// create thread pool
ExecutorService executor = Executors.newFixedThreadPool(100);
// create 100 random people
Person[] people = new Person[100];
for (int i=0; i<50; i++){
people[i] = new Person(elevatorController1);
}
for (int i=50; i<100; i++){
people[i] = new Person(elevatorController2);
}
for(int i = 0; i<100; i++){
executor.submit(people[i]);
}
// start the elevators and wait for request
elevator1.start();
elevator2.start();
executor.shutdown();
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES);
}
}