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