... occupiedCells, "buffer cells:  ");
59
60         for (int value : buffer) {
61            System.out.printf(" %2d  ", value); // output values in buffer
62         }
63
64         System.out.printf("%n               ");
65
66         for (int i = 0; i < buffer.length; i++) {
67            System.out.print("---- ");
68         }
69
70         System.out.printf("%n               ");
71
72         for (int i = 0; i < buffer.length; i++) {
73            if (i == writeIndex && i == readIndex) {
74               System.out.print(" WR"); // both write and read index
75            }
76            else if (i == writeIndex) {
77               System.out.print(" W  "); // just write index
78            }
79            else if (i == readIndex) {
80               System.out.print("  R  "); // just read index
81            }
82            else {
83               System.out.print("  "); // neither index
84            }
85         }
86
87         System.out.printf("%n%n");
88      }
89   }

Synchronizing access to a shared three-element ...

Get Java How to Program, Early 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.