-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
53 lines (29 loc) · 979 Bytes
/
Copy pathMain.java
File metadata and controls
53 lines (29 loc) · 979 Bytes
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
// this will create 100 random people
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 Main{
public static void main(String[] args) throws InterruptedException{
// create elevator
ElevatorController elevatorController = new ElevatorController();
Elevator elevator = new Elevator(elevatorController);
// create thread pool
ExecutorService executor = Executors.newFixedThreadPool(100);
// create 100 random people
Person[] people = new Person[100];
for (int i=0; i<100; i++){
people[i] = new Person(elevatorController);
}
for (Person p: people){
executor.submit(p);
}
// start the elevator and wait for request
elevator.start();
// shutdown executor
executor.shutdown();
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES);
}
}