getLog().debug("Acquire customers");
Customer marc = teller.getCustomer("Marc");
Customer rickard = teller.getCustomer("Rickard");
getLog().debug("Acquire accounts");
final Account from = teller.getAccount(marc, 50);
final Account to = teller.getAccount(rickard, 0);
final Object lock = new Object();
iter = getThreadCount();
final int iterationCount = getIterationCount();
getLog().info("Start test. "+getThreadCount()+ " threads, "+getIterationCount()+" iterations");
long start = System.currentTimeMillis();
for (int i = 0; i < getThreadCount(); i++)
{
Thread.sleep(50);
new Thread(new Runnable()
{
public void run()
{
Logger log = Logger.getLogger(getClass().getName());
try
{
for (int j = 0; j < iterationCount; j++)
{
if (exc != null) break;
teller.transfer(from,to,50);
teller.transfer(from,to,-50);
// Thread.currentThread().yield();
// logdebug(idx++);
}
} catch (Exception e)
{
exc = e;
}
synchronized(lock)
{
iter--;
log.info("Only "+iter+" left");
lock.notifyAll();
}
}
}).start();
}
synchronized(lock)
{
while(iter>0)
{
lock.wait();
}
}
if (exc != null) throw exc;
long end = System.currentTimeMillis();
getLog().info("Show balance");
getLog().info(from.getPrimaryKey()+":"+from.getBalance());
getLog().info(to.getPrimaryKey()+":"+to.getBalance());
getLog().info("Time:"+(end-start));
getLog().info("Avg. time/call(ms):"+((end-start)/(getThreadCount()*getIterationCount()*6)));
}