|
@@ -23,6 +23,23 @@ public class MonkeyTypewriter {
|
23
|
23
|
// Do all of the Monkey / Thread building here
|
24
|
24
|
// For each Copier(one safe and one unsafe), create and start 5 monkeys copying the introduction to
|
25
|
25
|
// A Tale Of Two Cities.
|
|
26
|
+ UnsafeCopier unsafeCopier = new UnsafeCopier(introduction);
|
|
27
|
+ Thread[] unsafeArray = new Thread[5];
|
|
28
|
+ for (int i =0; i < unsafeArray.length; i++){
|
|
29
|
+ unsafeArray[i] = new Thread(unsafeCopier);
|
|
30
|
+ }
|
|
31
|
+ for (Thread thread: unsafeArray) {
|
|
32
|
+ thread.start();
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ SafeCopier safeCopier = new SafeCopier(introduction);
|
|
36
|
+ Thread[] safeArray = new Thread[5];
|
|
37
|
+ for (int i = 0; i < safeArray.length; i++){
|
|
38
|
+ safeArray[i] = new Thread(safeCopier);
|
|
39
|
+ }
|
|
40
|
+ for (Thread thread: safeArray){
|
|
41
|
+ thread.start();
|
|
42
|
+ }
|
26
|
43
|
|
27
|
44
|
|
28
|
45
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
|
@@ -34,5 +51,8 @@ public class MonkeyTypewriter {
|
34
|
51
|
}
|
35
|
52
|
|
36
|
53
|
// Print out the copied versions here.
|
|
54
|
+ System.out.println(unsafeCopier.copied);
|
|
55
|
+ System.out.println("\n\n\n");
|
|
56
|
+ System.out.println(safeCopier.copied);
|
37
|
57
|
}
|
38
|
58
|
}
|