tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Fountain" <tfount...@benefitconcepts.com>
Subject RE: Suggestions for connection pooling
Date Thu, 25 Oct 2007 20:59:13 GMT
Ok - I think I have my answer but I'm going to pass it by the community
to verify.

First, my setup is:
	Apache Tomcat 5.5.23 running as windows service
	JVM 1.5.0_12-b04 (Sun) 
	Windows 2003 Server

Apache is installed in C:\Apache\Tomcat.  The location of the XML files
is C:\Apache\Tomcat\conf\context.xml and
C:\Apache\Tomcat\webapps\Reports\WEB-INF\web.xml.

I added the following to the context.xml:
    <Resource name="jdbc/myDatabase" auth="Container"
type="javax.sql.DataSource"
 
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"

              initialSize="5"
              maxActive="-1"
              maxIdle="-1"
              minIdle="0"
              maxWait="10000"

 
url="jdbc:sqlserver://<servername>\<instance>;integratedSecurity=true;da
tabaseName=ReportingSupport"
              username=""
              password=""

              validationQuery="SELECT 1"
              testOnBorrow="true"
              testOnReturn="true"
              testWhileIdle="true"
              timeBetweenEvictionRunsMillis="60000"
              numTestsPerEvictionRun="5"
              minEvictableIdleTimeMillis="600000"
              poolPreparedStatements="true"
              maxOpenPreparedStatements="0"

              removeAbandoned="true"
              removeAbandonedTimeout="300"
              logAbandoned="true"
    />

I added the following to the web.xml (within the <web-app> tag):
  <resource-ref>
    <description>Resource for connecting to the SQL Server</description>
    <res-ref-name>jdbc/myDatabase</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>

In my code I simply do:
	Context initCtx = new InitialContext();
	Context envCtx = (Context)initCtx.lookup("java:comp/env");
	DataSource ds = (DataSource)envCtx.lookup("jdbc/myDatabase");
	Connection conn = ds.getConnection();
	...do something...
	conn.close();

Now, my goal is to utilize connection pooling.  Does (a) this
implementation achieve that and (b) the close statement suffice to
return the object to the pool and not actually close the connection?  Or
do I also need to set "conn = null;"?

Thanks,
Tony

-----Original Message-----
From: Tony Fountain [mailto:tfountain@benefitconcepts.com] 
Sent: Thursday, October 25, 2007 2:39 PM
To: Tomcat Users List
Subject: RE: Suggestions for connection pooling

Thanks for the reference.  This looks like what I need.  Now to go read
up a bit more to grasp the concept.

Tony

-----Original Message-----
From: mgainty@hotmail.com [mailto:mgainty@hotmail.com]
Sent: Thursday, October 26, 2000 2:30 PM
To: Tony Fountain
Subject: Re: Suggestions for connection pooling

DBCP

http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.h
tml#Database%20Connection%20Pool%20(DBCP)%20Configurations

Plenty of good examples on JNDI Configurations

M--


----- Original Message -----
Wrom: XRQBGJSNBOHMKHJYFMYXOEAIJJPHSCRTNHGSWZIDREXCAXZ
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Thursday, October 25, 2007 1:19 PM
Subject: Suggestions for connection pooling


Platform:
Apache Tomcat 5.5.23 running as windows service JVM 1.5.0_12-b04 (Sun)
Windows 2003 Server

We are running software on this platform that we purchased and
integrated into our product.  We replaced the default authentication
class of the product with our own implementation.  This resulted in a
Java class that performs many database calls to SQL Server 2005.  This
all works and I'm in a mode of optimizing it and found that I'm creating
a database connection for every call (sometimes a single action sends
many requests).  I've been researching options for implementing
connection pooling but I have found many variations and no really solid
examples.  I'm pretty new to Java / Tomcat so I'm in search of
suggestions and recommendations from more experienced individuals on the
following topics:

* How configure a JNDI resource (versus hardcoding the connection in the
class - which is what I do now).  I've tried this with some examples and
have been unable to get it to work.
* How can I implement connection pooling?  Do I need to roll my own
solution or is there a magical way to tap into Tomcat and allow it to
manage the connection pool (latter is preferred).

Config file and Java code examples would be very helpful as well.  Also,
keep in mind that even though the JVM is at 1.5, the product is compiled
at 1.4 if that makes a difference.

Thanks!
Tony


________________________________________________________________________
This Email has been scanned for all viruses by PAETEC Email Scanning
Services, utilizing MessageLabs proprietary SkyScan infrastructure. For
more information on a proactive anti-virus service working around the
clock, around the globe, visit http://www.paetec.com.
________________________________________________________________________

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe,
e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


________________________________________________________________________
This Email has been scanned for all viruses by PAETEC Email Scanning
Services, utilizing MessageLabs proprietary SkyScan infrastructure. For
more information on a proactive anti-virus service working around the
clock, around the globe, visit http://www.paetec.com.
________________________________________________________________________

________________________________________________________________________
This Email has been scanned for all viruses by PAETEC Email Scanning
Services, utilizing MessageLabs proprietary SkyScan infrastructure. For
more information on a proactive anti-virus service working around the
clock, around the globe, visit http://www.paetec.com.
________________________________________________________________________

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message