|
@@ -23,16 +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 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();
|
|
32
|
+
|
|
33
|
+ SafeCopier safe = new SafeCopier(introduction);
|
|
34
|
+ new Thread(safe).start();
|
|
35
|
+ new Thread(safe).start();
|
|
36
|
+ new Thread(safe).start();
|
|
37
|
+ new Thread(safe).start();
|
|
38
|
+ new Thread(safe).start();
|
|
39
|
+
|
26
|
40
|
|
27
|
41
|
|
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.
|
30
|
44
|
try {
|
31
|
45
|
Thread.sleep(1000);
|
32
|
|
- } catch(InterruptedException e) {
|
|
46
|
+ } catch (InterruptedException e) {
|
33
|
47
|
System.out.println("MAIN INTERRUPTED");
|
34
|
48
|
}
|
35
|
|
-
|
36
|
|
- // Print out the copied versions here.
|
|
49
|
+ System.out.println("Unsafe: " + unsafe.copied + "\n\n\n\n\n\n");
|
|
50
|
+ System.out.println("Safe: " + safe.copied);
|
37
|
51
|
}
|
38
|
52
|
}
|