final List<ITestThread> testList = new ArrayList<ITestThread>(requestCount);
this.resultList = new ArrayList<ITestActionResult>(requestCount);
// Create parallel requests.
for (int cnt = 0; cnt < requestCount; cnt++) {
ITestThread thread = new TestThread(cnt, action);
testList.add(thread);
}
// Start parallel requests.
// If so dictated, sleep a little between starts.
for (ITestThread thread : testList) {
if (0 != threadTimeStep) {
OS.sleep(threadTimeStep);
}
thread.getThread().start();
}
// Wait until all tests are finished or timeout has come.
long timePassed = 0;
boolean isThreadsDone = false;
while (!isThreadsDone && timePassed < getTimeOut()) {
logStatus("Waiting on " + getMarketPlace().getHomeId() + " for tests to finish (" + (timePassed / JDistUnitConstants.WAIT_ONE_CYCLE) + ")");
// Sleep the next cycle.
OS.sleep(JDistUnitConstants.WAIT_ONE_CYCLE);
timePassed += JDistUnitConstants.WAIT_ONE_CYCLE;
// Take results out.
retrievePendingResults(testList);
// Set break flag if all threads have finished.
isThreadsDone = isTestThreadsDone(testList);
}
// If not all threads finished successfully, stop all remaining
// test threads -- they are timed out, and may die peacefully.
if (!isThreadsDone) {
for (ITestThread thread : testList) {
thread.stopAction();
}
}
}