tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joaquim <laurea...@comcast.net>
Subject Re: removeAbandoned does not work
Date Tue, 10 Dec 2002 19:33:46 GMT
Are you getting any exception?  The close statements are in the try 
catch block,
if you get an exception, they not be executed.  I would put the close 
statements
in a finally statement, to ensure that they would be executed.

Kranthi Yemula wrote:

>Hi,
> 
>I am using tomcat 4.0.3. I am playing with Datasources.
>I am having trouble validating 'removing abandoned database pool
>connections'.
> 
>I did the below:
>-----------------------------------------------
>1) I have set up the below parameters in my server.xml
> 
><!-- configure your DBCP DataSource so that abandoned dB connections are
>removed and recycled -->
><parameter>
><name>removeAbandoned</name>
><value>true</value>
></parameter>
><!-- Use the removeAbandonedTimeout parameter to set the number of seconds a
>dB connection has been idle before it is considered abandoned.
>Default time is 300 seconds. Here we are choosing 60 seconds. -->
><parameter>
><name>removeAbandonedTimeout</name>
><value>20</value>
></parameter>
><!-- The logAbandoned parameter can be set to true if you want DBCP to log a
>stack trace of the code which abandoned the dB connection resources. 
>Default is false. -->
><parameter>
><name>logAbandoned</name>
><value>true</value>
></parameter>
> 
>-----------------------------------------------
> 
>2) I modified my test program so that it does not close  databse connection.
>
> 
>package foo;
> 
>import javax.naming.*;
>import javax.sql.*;
>import java.sql.*;
> 
>public class DBTest {
> 
>  String foo = "Not Connected";
>  int bar = -1;
> 
>  public void init() {
>    try{
>      Context ctx = new InitialContext();
>      if(ctx == null )
>          throw new Exception("Boom - No Context");
> 
>          Context envCtx = (Context) ctx.lookup("java:comp/env");
> 
>          // Look up our data source
>    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Kranthi");
> 
>
>      if (ds != null) {
>        Connection conn = ds.getConnection();
> 
>        if(conn != null)  {
>            foo = "Got Connection "+conn.toString();
>            Statement stmt = conn.createStatement();
>            ResultSet rst =
>                stmt.executeQuery(
>                  "select id, foo, bar from testdata");
>            if(rst.next()) {
>               foo=rst.getString(2);
>               bar=rst.getInt(3);
>            }
>            /*stmt.close();
>            rst.close();
>            conn.close();
>            */
>        }
>      }
>    }catch(Exception e) {
>      e.printStackTrace();
>    }
> }
> 
>----------------------------------------------------------------------------
>--------------
> 
>I call the jsp that calls the above java program. But, its not actually
>closing the open connections.
> 
>Can anybody please help me.
> 
>Thanks,
>KYemula.
>
>
>  
>

-- 
Joaquim Laureano
Lusostar Technologies, LLC
Phone: 732-542-4890
Email: laureano8@comcast.net





--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message