|
@@ -23,6 +23,30 @@ 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 monkeyTyping1 = new Thread(unsafeCopier);
|
|
28
|
+ Thread monkeyTyping2 = new Thread(unsafeCopier);
|
|
29
|
+ Thread monkeyTyping3 = new Thread(unsafeCopier);
|
|
30
|
+ Thread monkeyTyping4 = new Thread(unsafeCopier);
|
|
31
|
+ Thread monkeyTyping5 = new Thread(unsafeCopier);
|
|
32
|
+ monkeyTyping1.start();
|
|
33
|
+ monkeyTyping2.start();
|
|
34
|
+ monkeyTyping3.start();
|
|
35
|
+ monkeyTyping4.start();
|
|
36
|
+ monkeyTyping5.start();
|
|
37
|
+
|
|
38
|
+ SafeCopier safeCopier = new SafeCopier(introduction);
|
|
39
|
+ Thread monkeyTyping6 = new Thread(safeCopier);
|
|
40
|
+ Thread monkeyTyping7 = new Thread(safeCopier);
|
|
41
|
+ Thread monkeyTyping8 = new Thread(safeCopier);
|
|
42
|
+ Thread monkeyTyping9 = new Thread(safeCopier);
|
|
43
|
+ Thread monkeyTyping10 = new Thread(safeCopier);
|
|
44
|
+ monkeyTyping6.start();
|
|
45
|
+ monkeyTyping7.start();
|
|
46
|
+ monkeyTyping8.start();
|
|
47
|
+ monkeyTyping9.start();
|
|
48
|
+ monkeyTyping10.start();
|
|
49
|
+
|
26
|
50
|
|
27
|
51
|
|
28
|
52
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
|
@@ -32,7 +56,10 @@ public class MonkeyTypewriter {
|
32
|
56
|
} catch(InterruptedException e) {
|
33
|
57
|
System.out.println("MAIN INTERRUPTED");
|
34
|
58
|
}
|
35
|
|
-
|
36
|
59
|
// Print out the copied versions here.
|
|
60
|
+ System.out.println("UNSAFE\n");
|
|
61
|
+ System.out.println(unsafeCopier.copied);
|
|
62
|
+ System.out.println("\nSAFE\n");
|
|
63
|
+ System.out.println(safeCopier.copied);
|
37
|
64
|
}
|
38
|
65
|
}
|