|
@@ -20,9 +20,35 @@ public class MonkeyTypewriter {
|
20
|
20
|
"its noisiest authorities insisted on its being received, for good or for\n" +
|
21
|
21
|
"evil, in the superlative degree of comparison only.";
|
22
|
22
|
|
|
23
|
+ StringBuilder sb = new StringBuilder();
|
|
24
|
+ for(int i = 0; i < 500; i++){
|
|
25
|
+ sb.append(introduction + " ");
|
|
26
|
+ }
|
|
27
|
+ String big = sb.toString();
|
23
|
28
|
// Do all of the Monkey / Thread building here
|
24
|
29
|
// For each Copier(one safe and one unsafe), create and start 5 monkeys copying the introduction to
|
25
|
30
|
// A Tale Of Two Cities.
|
|
31
|
+ UnsafeCopier unsafe = new UnsafeCopier(introduction);
|
|
32
|
+ SafeCopier safe = new SafeCopier(introduction);
|
|
33
|
+
|
|
34
|
+ SafeCopier bigSafe = new SafeCopier(big);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+ for(int i = 0; i < 5; i++){
|
|
38
|
+ new Thread(unsafe).start();
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ for(int i = 0; i < 5; i++){
|
|
42
|
+ new Thread(safe).start();
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+// for(int i = 0; i < 5; i++){
|
|
46
|
+// new Thread(bigSafe).start();
|
|
47
|
+// }
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
26
|
52
|
|
27
|
53
|
|
28
|
54
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
|
@@ -33,6 +59,10 @@ public class MonkeyTypewriter {
|
33
|
59
|
System.out.println("MAIN INTERRUPTED");
|
34
|
60
|
}
|
35
|
61
|
|
|
62
|
+ System.out.println(unsafe.copied);
|
|
63
|
+ System.out.println("============");
|
|
64
|
+ System.out.println(safe.copied);
|
|
65
|
+ //System.out.println(bigSafe.copied);
|
36
|
66
|
// Print out the copied versions here.
|
37
|
67
|
}
|
38
|
68
|
}
|