Chapter 20. Object pools 531
public void run() {
// Wait between 1-100 milliseconds before start
synchronized (this) {
try {
this.wait(1 + rand.nextInt(100));
} catch (InterruptedException e) {};
}
try {
customClass = Class.forName(className);
//Get an object pool for specified class
oPool = opm.getPool(customClass);
} catch (Exception ex) {
ex.printStackTrace();
}
int repetitions = rand.nextInt(500);
synchronized (totalNumberOfRepetitions) {
totalNumberOfRepetitions = new Long(totalNumberOfRepetitions.longValue() +
repetitions);
}
//Do something using objects without object pooling
//Repeat the job 1-500 times
//Read the time before starting the job
long startTime = System.currentTimeMillis();
for (int i = 0; i < repetitions; i++) {
doSomething();
}
//Read the time ...