I started doing a little testing on the Tyrex pools on my local machine,
and it doesn't appear to actually be pooling the connections. In a 1
minute period, I managed to get 118 hits (none of the connection lasted
for the entire minute - they lasted at most 5 seconds) and I checked my
outgoing connections, and had 128 (I'm assuming my stress-tester didn't
count 10 connections that were active when I told it to stop.)
Anyhow, the point is, every time I request a connection from the pool,
I'm getting a brand new connection - not a recycled one. I'm calling
close() on the connection in a finally block (and it is getting called).
Is there something else I have to do on the DataSource to ensure that
the connection gets recycled properly? Or am I missing some
configuration in my server.xml?
Regards,
Will Stranathan
Connection conn = null;
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Directory");
conn = ds.getConnection();
// etc.
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
conn.close();
System.out.println("closed connection");
} catch (Exception ex) {
System.err.println("Error closing connection");
}
}
<Resource name="jdbc/Directory" auth="SERVLET"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/Directory">
<parameter><name>user</name><value>...</value></parameter>
<parameter><name>password</name><value>...</value></parameter>
<parameter><name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value></parameter>
<parameter><name>driverName</name><value>jdbc:mysql://localhost/directory</value></parameter>
</ResourceParams>