|
@@ -1,5 +1,7 @@
|
1
|
1
|
package io.zipcoder;
|
2
|
2
|
|
|
3
|
+import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
4
|
+
|
3
|
5
|
public class MonkeyTypewriter {
|
4
|
6
|
public static void main(String[] args) {
|
5
|
7
|
String introduction = "It was the best of times,\n" +
|
|
@@ -24,9 +26,37 @@ public class MonkeyTypewriter {
|
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
|
|
|
29
|
+ //creation of unsafe threads with the object being passed into; additionally starting threads
|
|
30
|
+ UnsafeCopier unsafeCopier = new UnsafeCopier(introduction);
|
|
31
|
+
|
|
32
|
+ Thread UnsafeMonkeys1 = new Thread(unsafeCopier);
|
|
33
|
+ Thread UnsafeMonkeys2 = new Thread(unsafeCopier);
|
|
34
|
+ Thread UnsafeMonkeys3 = new Thread(unsafeCopier);
|
|
35
|
+ Thread UnsafeMonkeys4 = new Thread(unsafeCopier);
|
|
36
|
+ Thread UnsafeMonkeys5 = new Thread(unsafeCopier);
|
|
37
|
+
|
|
38
|
+ UnsafeMonkeys1.start();
|
|
39
|
+ UnsafeMonkeys2.start();
|
|
40
|
+ UnsafeMonkeys3.start();
|
|
41
|
+ UnsafeMonkeys4.start();
|
|
42
|
+ UnsafeMonkeys5.start();
|
|
43
|
+
|
|
44
|
+ SafeCopier safeCopier = new SafeCopier(introduction);
|
|
45
|
+ Thread SafeMonkeys1 = new Thread(safeCopier);
|
|
46
|
+ Thread SafeMonkeys2 = new Thread(safeCopier);
|
|
47
|
+ Thread SafeMonkeys3 = new Thread(safeCopier);
|
|
48
|
+ Thread SafeMonkeys4 = new Thread(safeCopier);
|
|
49
|
+ Thread SafeMonkeys5 = new Thread(safeCopier);
|
|
50
|
+
|
|
51
|
+ SafeMonkeys1.start();
|
|
52
|
+ SafeMonkeys2.start();
|
|
53
|
+ SafeMonkeys3.start();
|
|
54
|
+ SafeMonkeys4.start();
|
|
55
|
+ SafeMonkeys5.start();
|
27
|
56
|
|
28
|
57
|
// This wait is here because main is still a thread and we want the main method to print the finished copies
|
29
|
58
|
// after enough time has passed.
|
|
59
|
+
|
30
|
60
|
try {
|
31
|
61
|
Thread.sleep(1000);
|
32
|
62
|
} catch(InterruptedException e) {
|
|
@@ -34,5 +64,7 @@ public class MonkeyTypewriter {
|
34
|
64
|
}
|
35
|
65
|
|
36
|
66
|
// Print out the copied versions here.
|
|
67
|
+ System.out.println(safeCopier.copied);
|
|
68
|
+ System.out.println(unsafeCopier.copied);
|
37
|
69
|
}
|
38
|
70
|
}
|