-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriver.java
47 lines (31 loc) · 1.45 KB
/
Driver.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
44
45
46
47
import java.util.Random;
public class Driver{
public static final int NUM_THREADS = 8;
public static long[] times;
public static void main(String[] args) {
//make an array of threads
DriverThread[] threads = new DriverThread[NUM_THREADS];
times = new long[NUM_THREADS];
//this is populating our array of random numbers, that is global, which is copied by each thread individually
Random r = new Random();
for (int i = 0; i < DriverThread.N; i++) DriverThread.numsToSort[i] = r.nextInt(100);
//instantiate each thread, making a new driver incrementing seed each time to call different methods
for (int i = 0; i < NUM_THREADS; i++){
threads[i] = new DriverThread(i);
threads[i].start();
}
//we're going to call join here so that we wait until everyone's done to print out their times.
for (DriverThread t : threads) {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
for (DriverThread t : threads){
System.out.println("\n\nThread: " + t.seed + " executed in: " + t.executionTime + " ms");
//for (int i : t.sortedNums) System.out.print(i + " ");
}
}
//this method is going to take in a seed which will choose which sort to use, and then we are going to just return the sorted array
}