tx.begin();
if (debug)
logger.debug(getThreadName() + ": Starting " +
nrOfThreads + " concurrent threads.");
ThreadExceptionHandler group = new ThreadExceptionHandler();
Thread[] threads = new Thread[nrOfThreads];
for (int i = 0; i < nrOfThreads; i++) {
// Runnable r = new QueryExecuter(pm);
Runnable r =
new ExecutingMultipleQueriesSimultaneouslyIsThreadSafe().
getQueryExecuter(pm);
Thread t = new Thread(group, r);
t.setName("ThreadID-" + i);
threads[i] = t;
if (debug) logger.debug(getThreadName() + ": Running");
t.start();
}
if (debug)
logger.debug(getThreadName() +
": Waiting for threads to join...");
for (int i = 0; i < nrOfThreads; i++) {
try { threads[i].join(); }
catch (InterruptedException e) { }
}
if (debug) logger.debug(getThreadName() + ": All threads joined.");
tx.commit();
tx = null;
// check unhandled exceptions
Set uncaught = group.getAllUncaughtExceptions();
if ((uncaught != null) && !uncaught.isEmpty()) {
for (Iterator i = uncaught.iterator(); i.hasNext();) {
Map.Entry next = (Map.Entry)i.next();
Thread thread = (Thread)next.getKey();
Throwable problem = (Throwable)next.getValue();