public void runSpeedCompare( int loops, boolean inJvm, int port, String outFile )
{
String header = "loops;start time;end time;duration in ms;average single duration in ms";
EJServer server = new EJServer( new TestHandler(), port );
server.enablePersistentConnections( true );
try
{
System.out.println( "Starting EJServer..." );
server.start();
System.out.println( "Waiting 3 seconds..." );
Thread.sleep( 3000 );
}
catch ( Exception e1 )
{
e1.printStackTrace();
System.exit( -1 );
}
EJClient client1 = new EJClient( "localhost", port );
client1.enablePersistentConnection( true );
client1.setInJVM( inJvm );
EJClient client2 = new EJClient( "localhost", port );
client1.enablePersistentConnection( true );
client2.setInJVM( inJvm );
Runnable r1 = new Runner( client1 );
Runnable r2 = new Runner( client2 );
Date start = new Date();
try
{
for ( int go = 0; go < loops; go++ )
{
try
{
Thread a = new Thread( r1 );
Thread b = new Thread( r2 );
a.start();
b.start();
a.join();
b.join();
}
catch ( Throwable e )
{
e.printStackTrace();
break;
}
}
}
finally
{
client1.close();
client2.close();
}
Date end = new Date();
System.out.println( "Stopping server..." );
server.stop();
long duration = end.getTime() - start.getTime();
DateFormat df = new SimpleDateFormat( dFormat );
BigDecimal resultF = BigDecimal.valueOf( (duration * 1.00) / (loops * 1.00) )
.setScale( 2, BigDecimal.ROUND_HALF_UP );