//
// Create some entities
//
em.getTransaction().begin();
for (int i = 0; i < nPeople; i++) {
Person p = new Person();
p.setId(i);
em.persist(p);
}
em.flush();
em.getTransaction().commit();
em.close();
Thread[] newThreads = new Thread[nThreads];
FindPeople[] customer = new FindPeople[nThreads];
for (int i=0; i < nThreads; i++) {
customer[i] = new FindPeople(emfac, 0, nPeople, nIterations, i);
newThreads[i] = new Thread(customer[i]);
newThreads[i].start();
}
//
// Wait for the worker threads to complete
//
for (int i = 0; i < nThreads; i++) {
try {
newThreads[i].join();
}
catch (InterruptedException e) {
this.fail("Caught Interrupted Exception: " + e);
}
}
//
// Run through the state of all runnables to assert if any of them failed.
//
for (int i = 0; i < nThreads; i++) {
assertFalse(customer[i].hadFailures());
}
//
// Clean up the entities used in this test
//
em = emfac.createEntityManager();
em.getTransaction().begin();
for (int i = 0; i < nPeople; i++) {
Person p = em.find(Person.class, i);
em.remove(p);
}
em.flush();
em.getTransaction().commit();
em.close();