|
@@ -1,6 +1,8 @@
|
1
|
1
|
package io.zipcoder;
|
2
|
2
|
|
3
|
3
|
public class MonkeyTypewriter {
|
|
4
|
+ private static final int fMONKEYS = 5;
|
|
5
|
+
|
4
|
6
|
public static void main(String[] args) {
|
5
|
7
|
String introduction = "It was the best of times,\n" +
|
6
|
8
|
"it was the blurst of times,\n" +
|
|
@@ -23,16 +25,21 @@ public class MonkeyTypewriter {
|
23
|
25
|
// Do all of the Monkey / Thread building here
|
24
|
26
|
// For each Copier(one safe and one unsafe), create and start 5 monkeys copying the introduction to
|
25
|
27
|
// A Tale Of Two Cities.
|
26
|
|
-
|
|
28
|
+ UnsafeCopier uc = new UnsafeCopier(introduction);
|
|
29
|
+ for (int i = 0; i < fMONKEYS; i++) {
|
|
30
|
+ Thread monkey = new Thread(uc);
|
|
31
|
+ monkey.start();
|
|
32
|
+ }
|
27
|
33
|
|
28
|
34
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
29
|
35
|
// after enough time has passed.
|
30
|
36
|
try {
|
31
|
37
|
Thread.sleep(1000);
|
32
|
|
- } catch(InterruptedException e) {
|
|
38
|
+ } catch (InterruptedException e) {
|
33
|
39
|
System.out.println("MAIN INTERRUPTED");
|
34
|
40
|
}
|
35
|
41
|
|
36
|
42
|
// Print out the copied versions here.
|
|
43
|
+ System.out.println(uc.getCopy());
|
37
|
44
|
}
|
38
|
45
|
}
|