Sorry Chris, just saw your answer to this question now :)
But I think they have pretty much the same content. Felix Am 04.08.25 um 15:57 schrieb Christopher Schultz:
Parameshwara, On 8/2/25 1:54 AM, Parameshwara Bhat wrote:I am working on a task of migrating a running a JSP/JSF application on tomcat-6.0 to tomcat 9.0My installation of tomcat-9.0.87 is on Opensuse-Leap-15.6. Database is postgresql 17, using postgresql-42.7.7.jar for driver.I am able to run legacy application on tomcat-9.0.87 after making following changes ( picked up from tomcat-9.0 docs) to application's connection code.It's unclear what changes you made. You have only posted one code snippet.Doing this kind of thing in a JSP is probably going to cause all kinds of problems. "This kind of thing" is defined as "setting a class member's value during request processing". Note that only a single instance of the JSP's backing Java class will be created, and all requests running in all threads will be sharing this connection object and the this.conn reference to it.try { InitialContext cxt = new InitialContext(); /*if ( cxt == null ) { throw new Exception("Uh oh -- no context!"); }*/ DataSource ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/public_PostgreSQL" ); /*if ( ds == null ) { throws new Exception("Data source not found!"); }*/ try { this.con = ds.getConnection();} catch (SQLException ex) { ex.printStackTrace(); } } catch (NamingException e) { e.printStackTrace(); } /* this.con = DriverManager.getConnection(url, username, password); */My context.xml content is below.I am able to run application only after making maxTotal="40" from maxTotal="20" ; maxIdle="20" from maxIdle="10". Corresponding values for tomcat 6 running installation are maxActive="20", maxIdle="10".<?xml version="1.0" encoding="UTF-8"?> <Context path="/ERP"> <Resource auth="Container" driverClassName="org.postgresql.Driver" maxTotal="40" maxIdle="20" maxWaitMillis="-1" name="jdbc/public_PostgreSQL" password="kapital" type="javax.sql.DataSource" url="jdbc:postgresql://localhost:5444/das" username="das"/> </Context>With maxTotal="40" and maxIdle="20", I am able to barely run once. If I log out and try to login again, application can never login. In fact, I was able to login even once only after changing to maxTotal="40" and maxIdle="20". Otherwise application would be forever stuck at login, never able to enter application. I am able to login the first time I login and never afterwards. I have to kill tomcat-9.0.87 and restart,then I am able to login again.My guess is, pooled connections to database are not released to be re-used.I will thank any help to understand and resolve this. I have read documentation before making changes to DB connection, but I might have missed nuances.You should enable tracking of "abandoned connections" and also enable logging of those abandoned connections as well. I would highly recommend in a development environment setting your maxTotal to 1 (yes, ONE) as this will make it very very obvious if you have any connection leaks in your application, or if you have pool-related deadlocks hiding in there as well.This blog post is relevant but may require some adaptation to use within a JSP setting: https://blog.christopherschultz.net/2009/03/16/properly-handling-pooled-jdbc-connections/-chris --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
OpenPGP_0xEA6C3728EA91C4AF.asc
Description: OpenPGP public key
OpenPGP_signature.asc
Description: OpenPGP digital signature