/**
* Call by the benchmark framework to load the table data
*/
@Override
public void runLoop() {
final EventObservableExceptionHandler handler = new EventObservableExceptionHandler();
final List<Thread> threads = new ArrayList<Thread>();
for (AbstractTableGenerator generator : this.generators.values()) {
// if (isSubGenerator(generator)) continue;
Thread t = new Thread(generator);
t.setUncaughtExceptionHandler(handler);
threads.add(t);
// Make sure we call init first before starting any thread
generator.init();
} // FOR
assert(threads.size() > 0);
handler.addObserver(new EventObserver<Pair<Thread,Throwable>>() {
@Override
public void update(EventObservable<Pair<Thread, Throwable>> o, Pair<Thread, Throwable> t) {
for (Thread thread : threads)
thread.interrupt();
}
});
// Construct a new thread to load each table
// Fire off the threads and wait for them to complete
// If debug is set to true, then we'll execute them serially
try {
for (Thread t : threads) {
t.start();
} // FOR
for (Thread t : threads) {
t.join();
} // FOR
} catch (InterruptedException e) {
LOG.fatal("Unexpected error", e);
} finally {
if (handler.hasError()) {
throw new RuntimeException("Error while generating table data.", handler.getError());
}
}
profile.saveProfile(this);
LOG.info("Finished generating data for all tables");