|
@@ -23,7 +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
|
+ Copier copier = new SafeCopier(introduction);
|
|
27
|
+ Thread thread1 = new Thread(copier);
|
|
28
|
+ Thread thread2 = new Thread(copier);
|
|
29
|
+ Thread thread3 = new Thread(copier);
|
|
30
|
+ Thread thread4 = new Thread(copier);
|
|
31
|
+ Thread thread5 = new Thread(copier);
|
26
|
32
|
|
|
33
|
+ Copier copiers = new UnsafeCopier(introduction);
|
|
34
|
+ Thread thread11 = new Thread(copiers);
|
|
35
|
+ Thread thread22 = new Thread(copiers);
|
|
36
|
+ Thread thread33 = new Thread(copiers);
|
|
37
|
+ Thread thread44 = new Thread(copiers);
|
|
38
|
+ Thread thread55 = new Thread(copiers);
|
|
39
|
+
|
|
40
|
+ thread1.start();
|
|
41
|
+ thread2.start();
|
|
42
|
+ thread3.start();
|
|
43
|
+ thread4.start();
|
|
44
|
+ thread5.start();
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+ thread11.start();
|
|
48
|
+ thread22.start();
|
|
49
|
+ thread33.start();
|
|
50
|
+ thread44.start();
|
|
51
|
+ thread55.start();
|
27
|
52
|
|
28
|
53
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
29
|
54
|
// after enough time has passed.
|
|
@@ -34,5 +59,8 @@ public class MonkeyTypewriter {
|
34
|
59
|
}
|
35
|
60
|
|
36
|
61
|
// Print out the copied versions here.
|
|
62
|
+ System.out.println(copier.copied);
|
|
63
|
+ System.out.println(copiers.copied);
|
|
64
|
+
|
37
|
65
|
}
|
38
|
66
|
}
|