|
@@ -23,16 +23,33 @@ 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 unSafe = new UnsafeCopier(introduction);
|
|
27
|
+ new Thread(unSafe).start();
|
|
28
|
+ new Thread(unSafe).start();
|
|
29
|
+ new Thread(unSafe).start();
|
|
30
|
+ new Thread(unSafe).start();
|
|
31
|
+ new Thread(unSafe).start();
|
26
|
32
|
|
|
33
|
+ SafeCopier safeCopier = new SafeCopier(introduction);
|
|
34
|
+ new Thread(safeCopier).start();
|
|
35
|
+ new Thread(safeCopier).start();
|
|
36
|
+ new Thread(safeCopier).start();
|
|
37
|
+ new Thread(safeCopier).start();
|
|
38
|
+ new Thread(safeCopier).start();
|
27
|
39
|
|
28
|
40
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
29
|
41
|
// after enough time has passed.
|
30
|
42
|
try {
|
31
|
|
- Thread.sleep(1000);
|
32
|
|
- } catch(InterruptedException e) {
|
|
43
|
+ Thread.sleep(100);
|
|
44
|
+ } catch (InterruptedException e) {
|
33
|
45
|
System.out.println("MAIN INTERRUPTED");
|
34
|
46
|
}
|
35
|
47
|
|
36
|
48
|
// Print out the copied versions here.
|
|
49
|
+ System.out.println("Unsafe Copy:\n");
|
|
50
|
+ System.out.println(unSafe.copied+"\n\n");
|
|
51
|
+
|
|
52
|
+ System.out.println("Safe Copy: \n");
|
|
53
|
+ System.out.println(safeCopier.copied+"\n\n");
|
37
|
54
|
}
|
38
|
55
|
}
|