Thanks Tim and Chris for the response. Sorry, it took a while for me to 
respond. We are not storing connections in the session. We have a singleton 
class called DBManager and in its private constructor we have JNDI lookup for 
the datasource and  create a connection object there.

  Context init = new InitialContext();
  Context ctx = (Context) init.lookup("java:comp/env");
  DataSource ds = (DataSource) ctx.lookup("jdbc/jalasevaDB");
  myCon = ds.getConnection();
  stmt = myCon.createStatement();

And other classes which require database access get this DBManager instance to 
do query,update etc.
To answer Tim's question, we are not explicitly closing connection and 
statement objects as the context xml has these resource parameters.

removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"

Shouldn't DBCP take care of creating new connection if the connection object is 
stale?

I have been pulled into do other related work, haven't got the time to explore 
this problem further. 
I will update once I get to work on this. Thanks very much for the response. 
Meanwhile I would 
welcome your suggestions.

Thanks
Seetha

-----Original Message-----
From: Christopher Schultz [mailto:[EMAIL PROTECTED]
Sent: Friday, July 21, 2006 6:09 PM
To: Tomcat Users List
Cc: [EMAIL PROTECTED]
Subject: Re: Tomcat fails to refresh connections when mySQL server on
linux is shutdown and restarted


Seetha,

> Are you getting the connection anew after restarting the server?  It looks
> like you have this case:
> 
> T0    Connection x = Datasource.getConnection()
> T1    Do some stuff
> T2    Shutdown / restart MySQL
> T3    x.prepareStatement() or other stuff
> ... FAIL
> 
> The connection pool will only renew the connection on the
> Datasource.getConnection() (the validation query, SELECT 1, will only run on
> getConnection() -- in your case with test on borrow)

You could get this kind of thing happening if you were storing JDBC
Connections in the user's session. If the Connection is shut down and
serialized along with the session during the restart, then you will have
an invalid Connection in the session when Tomcat comes back up.

Do you do anything like this in your application?

-chris




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

Reply via email to