|
@@ -23,7 +23,22 @@ 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
|
|
-
|
|
26
|
+ UnsafeCopier unsafe = new UnsafeCopier(introduction);
|
|
27
|
+ Thread[] threads = new Thread[5];
|
|
28
|
+ for(int i = 0; i < threads.length; i++){
|
|
29
|
+ threads[i] = new Thread(unsafe);
|
|
30
|
+ }
|
|
31
|
+ for(Thread t : threads){
|
|
32
|
+ t.start();
|
|
33
|
+ }
|
|
34
|
+ SafeCopier safeCopier = new SafeCopier(introduction);
|
|
35
|
+ Thread[] threads2 = new Thread[5];
|
|
36
|
+ for(int i = 0; i < threads2.length; i++){
|
|
37
|
+ threads2[i] = new Thread(safeCopier);
|
|
38
|
+ }
|
|
39
|
+ for(Thread t2 : threads2){
|
|
40
|
+ t2.start();
|
|
41
|
+ }
|
27
|
42
|
|
28
|
43
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
29
|
44
|
// after enough time has passed.
|
|
@@ -32,7 +47,8 @@ public class MonkeyTypewriter {
|
32
|
47
|
} catch(InterruptedException e) {
|
33
|
48
|
System.out.println("MAIN INTERRUPTED");
|
34
|
49
|
}
|
35
|
|
-
|
|
50
|
+ System.out.println(unsafe.copied);
|
|
51
|
+ System.out.println(safeCopier.copied);
|
36
|
52
|
// Print out the copied versions here.
|
37
|
53
|
}
|
38
|
54
|
}
|