|
@@ -1,6 +1,21 @@
|
1
|
1
|
package io.zipcoder;
|
2
|
2
|
|
3
|
3
|
public class MonkeyTypewriter {
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+ /*
|
|
7
|
+ Unsafe threads work, but commented out for optimization.
|
|
8
|
+ */
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
4
|
19
|
public static void main(String[] args) {
|
5
|
20
|
String introduction = "It was the best of times,\n" +
|
6
|
21
|
"it was the blurst of times,\n" +
|
|
@@ -27,12 +42,30 @@ public class MonkeyTypewriter {
|
27
|
42
|
|
28
|
43
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
29
|
44
|
// after enough time has passed.
|
|
45
|
+ UnsafeCopier unsafeCopier0 = new UnsafeCopier(introduction);
|
|
46
|
+ SafeCopier safeCopier0 = new SafeCopier(introduction);
|
30
|
47
|
try {
|
|
48
|
+// new Thread(unsafeCopier0).start();
|
|
49
|
+// new Thread(unsafeCopier0).start();
|
|
50
|
+// new Thread(unsafeCopier0).start();
|
|
51
|
+// new Thread(unsafeCopier0).start();
|
|
52
|
+// new Thread(unsafeCopier0).start();
|
|
53
|
+
|
|
54
|
+ new Thread(safeCopier0).start();
|
|
55
|
+ new Thread(safeCopier0).start();
|
|
56
|
+ new Thread(safeCopier0).start();
|
|
57
|
+ new Thread(safeCopier0).start();
|
|
58
|
+ new Thread(safeCopier0).start();
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
31
|
62
|
Thread.sleep(1000);
|
32
|
63
|
} catch(InterruptedException e) {
|
33
|
64
|
System.out.println("MAIN INTERRUPTED");
|
34
|
65
|
}
|
35
|
66
|
|
|
67
|
+ System.out.println(safeCopier0.copied);
|
36
|
68
|
// Print out the copied versions here.
|
37
|
69
|
}
|
|
70
|
+
|
38
|
71
|
}
|