return _thread;
}
public void runOnce(final int cachetype) throws Exception {
Enumeration enumeration;
OQLQuery oql;
// clear the table
int del = _conn.createStatement().executeUpdate(
"DELETE FROM tc0x_race");
LOG.debug("row deleted in table core_race: " + del);
_conn.commit();
// create pairs of number
_masterDB.begin();
Race[] jdos = new Race[NUM_OF_VALUE_PAIRS];
RaceSync[] controls = new RaceSync[NUM_OF_VALUE_PAIRS];
switch (cachetype) {
case 0:
_classType = ctf.jdo.tc0x.RaceCount.class;
_className = _classType.getName();
for (int i = 0; i < jdos.length; i++) {
jdos[i] = new RaceCount();
jdos[i].setId(i);
_masterDB.create(jdos[i]);
controls[i] = new RaceSync();
}
break;
case 1:
_classType = ctf.jdo.tc0x.RaceTime.class;
_className = _classType.getName();
for (int i = 0; i < jdos.length; i++) {
jdos[i] = new RaceTime();
jdos[i].setId(i);
_masterDB.create(jdos[i]);
controls[i] = new RaceSync();
}
break;
case 2:
_classType = ctf.jdo.tc0x.RaceNone.class;
_className = _classType.getName();
for (int i = 0; i < jdos.length; i++) {
jdos[i] = new RaceNone();
jdos[i].setId(i);
_masterDB.create(jdos[i]);
controls[i] = new RaceSync();
}
break;
case 3:
_classType = ctf.jdo.tc0x.RaceUnlimited.class;
_className = _classType.getName();
for (int i = 0; i < jdos.length; i++) {
jdos[i] = new RaceUnlimited();
jdos[i].setId(i);
_masterDB.create(jdos[i]);
controls[i] = new RaceSync();
}
break;
default:
LOG.error("Unknown cache type");
}
_masterDB.commit();
// create threads, make a race so each thread
// keeping increment to the pairs of number.
RaceThread[] ts = new RaceThread[NUM_OF_RACING_THREADS];
for (int i = 0; i < ts.length; i++) {
ts[i] = new RaceThread(this, _dbForRace[i], controls, NUM_OF_TRIALS);
ts[i].start();
}
// wait till everybody done
boolean isAllDone = false;
int num;
while (!isAllDone) {
Thread.sleep(1000);
num = 0;
for (int i = 0; i < ts.length; i++) {
if (ts[i].isDone()) {
num++;
}
}
if (num == ts.length) {
isAllDone = true;
}
}
// see if their sum agree
_masterDB.begin();
num = 0;
for (int i = 0; i < jdos.length; i++) {
oql = _masterDB.getOQLQuery("SELECT object FROM " + _className
+ " object WHERE id = $1");
oql.bind(i);
enumeration = oql.execute();
if (enumeration.hasMoreElements()) {
Race tr = (Race) enumeration.nextElement();
if (tr.getValue1() == controls[i].getValue1()) { num++; }
LOG.debug("Number Pair " + i + " -- JDO: "
+ tr.getValue1() + " control: "