}
public void run() {
try {
while (this.readingThreads != null && this.nextFileToRead < this.units.length) {
ICompilationUnit unit = null;
int position = -1;
synchronized (this) {
if (this.readingThreads == null) return;
while (this.filesRead[this.nextAvailablePosition] != null) {
this.sleepingThreadCount++;
try {
wait(250); // wait until a spot in contents is available
} catch (InterruptedException e) { // ignore
}
this.sleepingThreadCount--;
if (this.readingThreads == null) return;
}
if (this.nextFileToRead >= this.units.length) return;
unit = this.units[this.nextFileToRead++];
position = this.nextAvailablePosition;
if (++this.nextAvailablePosition >= this.contentsRead.length)
this.nextAvailablePosition = 0;
this.filesRead[position] = unit;
this.contentsRead[position] = this.readInProcessMarker; // mark the spot so we know its being read
}
char[] result = unit.getContents();
synchronized (this) {
if (this.filesRead[position] == unit) {
if (this.contentsRead[position] == null) // wake up main thread which is waiting for this file
notifyAll();
this.contentsRead[position] = result;