Thread[] threadArray = new Thread[threadCount];
LoadPersonThread[] loadPersonThreadArray = new LoadPersonThread[threadCount];
for (int i = 0; i < threadCount; i++) {
int minPersonId = cutoffs[i] + 1;
int maxPersonId = cutoffs[i + 1];
LoadPersonThread lpt = new LoadPersonThread(i, minPersonId, maxPersonId);
Thread t = new Thread(lpt);
loadPersonThreadArray[i] = lpt;
threadArray[i] = t;
t.start();
// Sleep just a little to let the thread start and print any logging messages
// that it may have. This sleeping will not affect performance noticably, but
// will give the thread the chance to start so that all threads will start
// Sleep 10 milliseconds.
waitAMoment();
}
//
// Wait for all of the threads to complete loading their values.
for (int i = 0; i < threadCount; i++) {
Thread t = threadArray[i];
try {
t.join();
} catch (InterruptedException ex) {
Logger.getLogger(PersonList.class.getName()).log(Level.SEVERE, "Error joining FindPersonThread", ex);
}
LoadPersonThread lpt = loadPersonThreadArray[i];
loadPersonThreadArray[i] = null; // Release object memory when we loop, most notably personMatchList
List<PersonMatch> personMatchList = lpt.getPersonMatchList();
for (PersonMatch pm : personMatchList) {
add(pm);
}
}
double timeInterval = (System.currentTimeMillis() - startTime);