|
@@ -25,14 +25,33 @@ public class MonkeyTypewriter {
|
25
|
25
|
// A Tale Of Two Cities.
|
26
|
26
|
|
27
|
27
|
|
28
|
|
- // This wait is here because main is still a thread and we want the main method to print the finished copies
|
29
|
|
- // after enough time has passed.
|
30
|
|
- try {
|
31
|
|
- Thread.sleep(1000);
|
32
|
|
- } catch(InterruptedException e) {
|
33
|
|
- System.out.println("MAIN INTERRUPTED");
|
|
28
|
+ Copier unsafeCopier = new UnsafeCopier(introduction);
|
|
29
|
+ Thread[] unsafeThreads = new Thread[] {new Thread(unsafeCopier), new Thread(unsafeCopier), new Thread(unsafeCopier), new Thread(unsafeCopier), new Thread(unsafeCopier)};
|
|
30
|
+ for (Thread thread : unsafeThreads) {
|
|
31
|
+ thread.start();
|
34
|
32
|
}
|
35
|
33
|
|
|
34
|
+ Copier safeCopier = new SafeCopier(introduction);
|
|
35
|
+ Thread[] safeThreads = new Thread[] {new Thread(safeCopier), new Thread(safeCopier), new Thread(safeCopier), new Thread(safeCopier), new Thread(safeCopier)};
|
|
36
|
+ for (Thread thread : safeThreads) {
|
|
37
|
+ thread.start();
|
|
38
|
+ }
|
|
39
|
+// for (int j = 0; j < safeArray.length; j++) safeArray[j].start();
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+ for(Thread thread : safeThreads) {
|
|
44
|
+ try {
|
|
45
|
+ thread.join();
|
|
46
|
+ } catch (InterruptedException e) {
|
|
47
|
+ e.printStackTrace();
|
|
48
|
+ }
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+
|
36
|
52
|
// Print out the copied versions here.
|
|
53
|
+ System.out.println(unsafeCopier.copied);
|
|
54
|
+ System.out.println("---------------------------------------");
|
|
55
|
+ System.out.println(safeCopier.copied);
|
37
|
56
|
}
|
38
|
57
|
}
|