... void main(String[] arg) {
 9         // construct the shared object
10         SimpleArray sharedSimpleArray = new SimpleArray(6);
11
12         // create two tasks to write to the shared SimpleArray
13         ArrayWriter writer1 = new 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) {
39               System.out.printf("%nContents of SimpleArray:%n" ...

Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.