You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kranthi Yemula <ky...@once.com> on 2002/12/10 20:16:45 UTC

removeAbandoned does not work

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.


Re: removeAbandoned does not work

Posted by Joaquim <la...@comcast.net>.
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>