|
@@ -20,13 +20,43 @@ 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
|
+
|
|
24
|
+ UnsafeCopier unsafeCopier = new UnsafeCopier(introduction);
|
23
|
25
|
// Do all of the Monkey / Thread building here
|
|
26
|
+ Thread monkey1 = new Thread( unsafeCopier );
|
|
27
|
+ Thread monkey2 = new Thread( unsafeCopier );
|
|
28
|
+ Thread monkey3 = new Thread( unsafeCopier );
|
|
29
|
+ Thread monkey4 = new Thread( unsafeCopier );
|
|
30
|
+ Thread monkey5 = new Thread( unsafeCopier );
|
24
|
31
|
// For each Copier(one safe and one unsafe), create and start 5 monkeys copying the introduction to
|
25
|
32
|
// A Tale Of Two Cities.
|
26
|
33
|
|
27
|
34
|
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+ monkey1.start();
|
|
38
|
+ monkey2.start();
|
|
39
|
+ monkey3.start();
|
|
40
|
+ monkey4.start();
|
|
41
|
+ monkey5.start();
|
28
|
42
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
29
|
43
|
// after enough time has passed.
|
|
44
|
+ SafeCopier safeCopier = new SafeCopier(introduction);
|
|
45
|
+
|
|
46
|
+ Thread safemonkey1 = new Thread( safeCopier );
|
|
47
|
+ Thread safemonkey2 = new Thread( safeCopier );
|
|
48
|
+ Thread safemonkey3 = new Thread( safeCopier );
|
|
49
|
+ Thread safemonkey4 = new Thread( safeCopier );
|
|
50
|
+ Thread safemonkey5 = new Thread( safeCopier );
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+ safemonkey1.start();
|
|
54
|
+ safemonkey2.start();
|
|
55
|
+ safemonkey3.start();
|
|
56
|
+ safemonkey4.start();
|
|
57
|
+ safemonkey5.start();
|
|
58
|
+
|
|
59
|
+ System.out.println();
|
30
|
60
|
try {
|
31
|
61
|
Thread.sleep(1000);
|
32
|
62
|
} catch(InterruptedException e) {
|
|
@@ -34,5 +64,8 @@ public class MonkeyTypewriter {
|
34
|
64
|
}
|
35
|
65
|
|
36
|
66
|
// Print out the copied versions here.
|
|
67
|
+ System.out.println(unsafeCopier.copied);
|
|
68
|
+ System.out.println("======================================================");
|
|
69
|
+ System.out.println(safeCopier.copied);
|
37
|
70
|
}
|
38
|
71
|
}
|