Hello All,
I am working on a task of migrating a running a JSP/JSF application on
tomcat-6.0 to tomcat 9.0
My 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.
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.
<?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>
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".
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.
Parameshwara Bhat