|
@@ -1,7 +1,9 @@
|
1
|
1
|
package io.zipcoder;
|
2
|
2
|
|
3
|
3
|
public class MonkeyTypewriter {
|
|
4
|
+
|
4
|
5
|
public static void main(String[] args) {
|
|
6
|
+
|
5
|
7
|
String introduction = "It was the best of times,\n" +
|
6
|
8
|
"it was the blurst of times,\n" +
|
7
|
9
|
"it was the age of wisdom,\n" +
|
|
@@ -25,18 +27,40 @@ public class MonkeyTypewriter {
|
25
|
27
|
// A Tale Of Two Cities.
|
26
|
28
|
|
27
|
29
|
UnsafeCopier unsafeCopier = new UnsafeCopier(introduction);
|
|
30
|
+ SafeCopier safeCopier = new SafeCopier(introduction);
|
|
31
|
+
|
|
32
|
+ Thread[] unsafeMonkey = new Thread[5];
|
|
33
|
+ Thread[] safeMonkey = new Thread[5];
|
|
34
|
+
|
|
35
|
+ for (int i = 0; i < unsafeMonkey.length; i++) {
|
|
36
|
+ unsafeMonkey[i] = new Thread(unsafeCopier);
|
|
37
|
+ safeMonkey[i] = new Thread(safeCopier);
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ for (Thread thread : unsafeMonkey) {
|
|
41
|
+ thread.start();
|
|
42
|
+ }
|
|
43
|
+ for (Thread thread : safeMonkey) {
|
|
44
|
+ thread.start();
|
|
45
|
+ }
|
28
|
46
|
|
29
|
|
- Thread monkey = new Thread(unsafeCopier);
|
30
|
|
- Thread monkey1 = new Thread(unsafeCopier);
|
31
|
|
- Thread monkey2 = new Thread(unsafeCopier);
|
32
|
|
- Thread monkey3 = new Thread(unsafeCopier);
|
33
|
|
- Thread monkey4 = new Thread(unsafeCopier);
|
|
47
|
+// while ( unsafeCopier.stringIterator.hasNext() || safeCopier.stringIterator.hasNext()) {
|
|
48
|
+//
|
|
49
|
+// for (int i = 0; i < unsafeMonkey.length; i++) {
|
|
50
|
+// unsafeMonkey[i] = new Thread(unsafeCopier);
|
|
51
|
+// safeMonkey[i] = new Thread(safeCopier);
|
|
52
|
+// }
|
|
53
|
+//
|
|
54
|
+// for (Thread thread : unsafeMonkey) {
|
|
55
|
+// thread.start();
|
|
56
|
+// }
|
|
57
|
+// for (Thread thread : safeMonkey) {
|
|
58
|
+// thread.start();
|
|
59
|
+// }
|
|
60
|
+//
|
|
61
|
+//
|
|
62
|
+// }
|
34
|
63
|
|
35
|
|
- monkey.start();
|
36
|
|
- monkey1.start();
|
37
|
|
- monkey2.start();
|
38
|
|
- monkey3.start();
|
39
|
|
- monkey4.start();
|
40
|
64
|
|
41
|
65
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
42
|
66
|
// after enough time has passed.
|
|
@@ -45,9 +69,15 @@ public class MonkeyTypewriter {
|
45
|
69
|
} catch(InterruptedException e) {
|
46
|
70
|
System.out.println("MAIN INTERRUPTED");
|
47
|
71
|
}
|
48
|
|
-
|
|
72
|
+ System.out.println("_________________________UNSAFE_TEST__________________________________");
|
49
|
73
|
System.out.println(unsafeCopier.copied);
|
50
|
74
|
|
|
75
|
+ System.out.println("_________________________SAFE_TEST____________________________________");
|
|
76
|
+ System.out.println(safeCopier.copied);
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
51
|
81
|
// Print out the copied versions here.
|
52
|
82
|
}
|
53
|
83
|
}
|