test.runTest(iterations, numOfClients, printLookupTime);
}
private void runTest(final int iterations, int numOfClients, final boolean printTime)
{
final CopyOnWriteArrayList timesList = new CopyOnWriteArrayList();
final Counter counter = new Counter();
long start = System.currentTimeMillis();
System.out.println("Starting run now with " + numOfClients + " clients and " + iterations + " iterations.");
for (int x = 0; x < numOfClients; x++)
{
new Thread()
{
public void run()
{
try
{
for (int i = 0; i < iterations; i++)
{
long startTime = System.currentTimeMillis();
TestClient client = new TestClient();
client.lookup("SimpleSession", SimpleSessionHome.class);
long endTime = System.currentTimeMillis();
timesList.add(new Long(endTime - startTime));
if (printTime)
System.out.println(endTime - startTime);
counter.increment();
long value = counter.getValue();
if (value % 10000 == 0)
{
System.out.println("Executed " + value + " times so far.");
}
}
}
catch (Exception e)
{
System.out.println("Error calling test client to do jndi lookup");
e.printStackTrace();
}
}
}.start();
}
while (timesList.size() < (iterations * numOfClients))
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace(); //TODO: -TME Implement
}
}
long end = System.currentTimeMillis();
System.out.println("Ran test with total of " + timesList.size() + " (iterations: " + iterations +
", number of clients: " + numOfClients + ") in " + (end - start) / 1000 + " seconds.");
long total = 0;
for (int i = 0; i < timesList.size(); i++)
{
total += ((Long) timesList.get(i)).longValue();
}
System.out.println("Average time to make lookup is " + (total / (iterations * numOfClients)) + " milliseconds.");
//System.out.println("Counter says was executed " + counter.getValue() + " times.");