This is an example of how to test the performance of the pooling example against the performance of the non-pooling example.
import java.sql.*;
import javax.naming.*;
import java.util.*;
import javax.sql.*;
public class ConnectionPoolingTest
{
public static void main(java.lang.String[] args)
throws Exception
{
Context ctx = new InitialContext();
// Do the work without a pool:
DataSource ds = (DataSource) ctx.lookup("BaseDataSource");
System.out.println("\nStart timing the non-pooling DataSource version...");
long startTime = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
Connection c1 = ds.getConnection();
c1.close();
}
long endTime = System.currentTimeMillis();
System.out.println("Time spent: " + (endTime - startTime));
// Do the work with pooling:
ds = (DataSource) ctx.lookup("PoolingDataSource");
System.out.println("\nStart timing the pooling version...");
startTime = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
Connection c1 = ds.getConnection();
c1.close();
}
endTime = System.currentTimeMillis();
System.out.println("Time spent: " + (endTime - startTime));
}
}