tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From IT Desk <>
Subject Re: jsp optimization for db driver load and connection
Date Mon, 04 Dec 2006 20:51:40 GMT
Thanks to everyone for the replies.  I had kinda been hoping the 
connection pooling was somehow automatic with the latest version of Tomcat.

I'll pass along the information to the decision-makers  About 15-20 jsps 
would need to be changed.  There's another 30 jsps but they are not high 
use (admin area).

This webapp doesn't even have a web.xml file!  I'd call it Model .05 -- 
not even model 1.  Ha, ha. The code was written by someone else about 3 
years ago.  It was their first and only JSP project.

Thanks for the great help!

Miller, Steve wrote:
> Ugh. Model 1 architecture :-)
> Connection pooling is the way to go here, definitely. Setup Tomcat to do
> it for you automatically on startup. Then, just grab a connection from
> the pool when you need it. Some good documentation on setting up and
> configuring Tomcat to do that is at
> tml
> In you JSP then, all you would have to write is (after importing
> java.sql.* and javax.naming.*):
>             Context initContext = new InitialContext();
>             Context envContext =
> (Context)initContext.lookup("java:/comp/env");
>             DataSource ds = (DataSource)envContext.lookup("jdbc/foo"); 
> 		Connection conn = ds.getConnection();
> 		Statement stmt =
> conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
> 		ResultSet rs = stmt.executeQuery(query1);
> 		// iterator loop and display stuff
> 		ResultSet rs = stmt.executeQuery(query2);
> 		// iterator loop and display stuff
> 		.....
> 		.....
> 		rs.close();
> 		conn.close(); //returns connection to tomcat-managed
> pool...always a good practice to insert this!!
> The advantage to this of course is that several database connections are
> established when tomcat is started and then placed into a pool. All you
> do is grab one that exists....saving a *considerable* amount of
> transaction time and thus speeding up your page loads. In addition,
> should the database parameters change such as URL, username, or
> password, then you only have to change it in one place..the server.xml
> file. This is also important if you move between dev/test/prod
> environments and have to point at different database instances. 
> I don't know how many jsp pages you'll have to alter, but I would
> suggest looking at using a bean that does all of the stuff I wrote out
> above and returns an iterator or result set through a method. Then, do
> the bean stuff in the jsp code (sorry...running out of time
> Again, I don't see any other way to improve performance within the
> scope/limitations you have defined. 
> Steve Miller
> "Grabbing A Tomcat By The Tail"
> ---------------------------------------------------------------------
> To start a new topic, e-mail:
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message