June 2017
Beginner
1296 pages
69h 23m
English
... ArrayWriter(1, sharedSimpleArray);
14 ArrayWriter writer2 = new ArrayWriter(11, sharedSimpleArray);
15
16 // execute the tasks with an ExecutorService
17 ExecutorService executorService = Executors.newCachedThreadPool();
18 executorService.execute(writer1);
19 executorService.execute(writer2);
20
21 executorService.shutdown();
22
23 try {
24 // wait 1 minute for both writers to finish executing
25 boolean tasksEnded =
26 executorService.awaitTermination(1, TimeUnit.MINUTES);
27
28 if (tasksEnded) {
29 System.out.printf("%nContents of SimpleArray:%n");
30 System.out.println(sharedSimpleArray); // print contents
31 }
32 else {
33 System.out.println(
34 "Timed out while waiting for tasks to finish.");
35 }
36 }
37 catch (InterruptedException ex) { ...