|
@@ -1,5 +1,7 @@
|
1
|
1
|
package io.zipcoder;
|
2
|
2
|
|
|
3
|
+import com.sun.org.apache.regexp.internal.REDebugCompiler;
|
|
4
|
+
|
3
|
5
|
public class MonkeyTypewriter {
|
4
|
6
|
public static void main(String[] args) {
|
5
|
7
|
String introduction = "It was the best of times,\n" +
|
|
@@ -24,6 +26,40 @@ public class MonkeyTypewriter {
|
24
|
26
|
// For each Copier(one safe and one unsafe), create and start 5 monkeys copying the introduction to
|
25
|
27
|
// A Tale Of Two Cities.
|
26
|
28
|
|
|
29
|
+ UnsafeCopier unsafe = new UnsafeCopier(introduction);
|
|
30
|
+ SafeCopier safe = new SafeCopier(introduction);
|
|
31
|
+
|
|
32
|
+ Thread monkey = new Thread(unsafe);
|
|
33
|
+ Thread ape = new Thread(unsafe);
|
|
34
|
+ Thread orangutan = new Thread(unsafe);
|
|
35
|
+ Thread primate = new Thread(unsafe);
|
|
36
|
+ Thread octanarian = new Thread(unsafe);
|
|
37
|
+
|
|
38
|
+ monkey.start();
|
|
39
|
+ ape.start();
|
|
40
|
+ orangutan.start();
|
|
41
|
+ primate.start();
|
|
42
|
+ octanarian.start();
|
|
43
|
+
|
|
44
|
+ Thread King = new Thread(safe);
|
|
45
|
+ Thread Ceasar = new Thread(safe);
|
|
46
|
+ Thread Maurice = new Thread(safe);
|
|
47
|
+ Thread Koba = new Thread(safe);
|
|
48
|
+ Thread Red = new Thread(safe);
|
|
49
|
+
|
|
50
|
+ King.start();
|
|
51
|
+ Ceasar.start();
|
|
52
|
+ Maurice.start();
|
|
53
|
+ Koba.start();
|
|
54
|
+ Red.start();
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+ // System.out.println("======================");
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
27
|
63
|
|
28
|
64
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
29
|
65
|
// after enough time has passed.
|
|
@@ -32,7 +68,11 @@ public class MonkeyTypewriter {
|
32
|
68
|
} catch(InterruptedException e) {
|
33
|
69
|
System.out.println("MAIN INTERRUPTED");
|
34
|
70
|
}
|
35
|
|
-
|
36
|
71
|
// Print out the copied versions here.
|
|
72
|
+ System.out.println(unsafe.copied);
|
|
73
|
+
|
|
74
|
+ System.out.println("======================");
|
|
75
|
+
|
|
76
|
+ System.out.println(safe.copied);
|
37
|
77
|
}
|
38
|
78
|
}
|