Collection<Thread> threads = new LinkedList<Thread>();
final AtomicInteger count = new AtomicInteger(0);
WorkQueue queue = WorkQueue.getWorkQueue(numThreads);
Object key = queue.registerTaskGroup(numThreads);
long processStart = System.currentTimeMillis();
verbose("Beginning processing using %d threads", numThreads);
for (int i = 0; i < numThreads; ++i) {
queue.add(key, new Runnable() {
public void run() {
// repeatedly try to process documents while some still
// remain
while (docIter.hasNext()) {
long startTime = System.currentTimeMillis();
Document doc = docIter.next();
int docNumber = count.incrementAndGet();
int terms = 0;
try {
sspace.processDocument(doc.reader());
} catch (Throwable t) {
t.printStackTrace();
}
long endTime = System.currentTimeMillis();
verbose("parsed document #%d in %.3f seconds",
docNumber, ((endTime - startTime) / 1000d));
}
}
});;
}
queue.await(key);
verbose("Processed all %d documents in %.3f total seconds",
count.get(),
((System.currentTimeMillis() - processStart) / 1000d));
}