|
@@ -23,6 +23,35 @@ 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 monkey1 = new Thread(unsafeCopier);
|
|
28
|
+ Thread monkey2 = new Thread(unsafeCopier);
|
|
29
|
+ Thread monkey3 = new Thread(unsafeCopier);
|
|
30
|
+ Thread monkey4 = new Thread(unsafeCopier);
|
|
31
|
+ Thread monkey5 = new Thread(unsafeCopier);
|
|
32
|
+
|
|
33
|
+ monkey1.start();
|
|
34
|
+ monkey2.start();
|
|
35
|
+ monkey3.start();
|
|
36
|
+ monkey4.start();
|
|
37
|
+ monkey5.start();
|
|
38
|
+
|
|
39
|
+ SafeCopier safeCopier = new SafeCopier(introduction);
|
|
40
|
+ Thread safeMonkey1 = new Thread(safeCopier);
|
|
41
|
+ Thread safeMonkey2 = new Thread(safeCopier);
|
|
42
|
+ Thread safeMonkey3 = new Thread(safeCopier);
|
|
43
|
+ Thread safeMonkey4 = new Thread(safeCopier);
|
|
44
|
+ Thread safeMonkey5 = new Thread(safeCopier);
|
|
45
|
+
|
|
46
|
+ safeMonkey1.start();
|
|
47
|
+ safeMonkey2.start();
|
|
48
|
+ safeMonkey3.start();
|
|
49
|
+ safeMonkey4.start();
|
|
50
|
+ safeMonkey5.start();
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+ //unsafeCopier.run();
|
26
|
55
|
|
27
|
56
|
|
28
|
57
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
|
@@ -34,5 +63,9 @@ public class MonkeyTypewriter {
|
34
|
63
|
}
|
35
|
64
|
|
36
|
65
|
// Print out the copied versions here.
|
|
66
|
+ System.out.println(unsafeCopier.copied);
|
|
67
|
+ System.out.println("==========================================================================");
|
|
68
|
+ System.out.println(safeCopier.copied);
|
|
69
|
+
|
37
|
70
|
}
|
38
|
71
|
}
|