You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Will Stranathan <wi...@thestranathans.com> on 2001/10/02 05:11:10 UTC
Tyrex Pools
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>
Re: Tyrex Pools
Posted by Will Stranathan <wi...@thestranathans.com>.
Ah - that makes sense. However, it seems to still be doing the same
thing. I just threw together a simple JSP to test it, and put the ds
lookup in jspInit(). The lookup is only getting executed once, but it
still looks like no connections are getting re-used.
Anything else for me to look at?
Will Stranathan
<%!
DataSource ds = null;
public void jspInit() {
try {
Context ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Directory");
System.out.println("did lookup");
} catch (Exception e) {
e.printStackTrace();
}
}
%>
<%
Connection conn = null;
if (ds != null) {
try {
conn = ds.getConnection();
etc....
Remy Maucherat wrote:
> Instead, I would retrieve the DataSource in the init() method of the
> servlet, and put it in an instance variable.
>
> Remy
>
>
Re: Tyrex Pools
Posted by Remy Maucherat <rm...@home.com>.
> 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?
The JNDI implementation of Catalina doesn't rebind after the lookup. So it
you do 200 lookups, you'll get 200 different data source instances. I was
unsure if it was a good idea to rebind resolved objects (for example, Tyrex
JNDI implementation doesn't), so I didn't do it.
Instead, I would retrieve the DataSource in the init() method of the
servlet, and put it in an instance variable.
Remy