tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edson Alves Pereira <eapere...@panamericano.com.br>
Subject RE: Severity less - DBCP not closing connection.
Date Fri, 21 Nov 2003 13:51:44 GMT
	You must ensure that your connection manager is closing all
ResultSets, Statements, PreparedStatement and finally all connection. With
that you DBCP will work. Store a copy of all those objets in Vectors and
when you close the connectionm manager, it will close all objetcts stored
also.

> ----------
> De: 	Antony Paul[SMTP:antonypaul24@hotmail.com]
> Responder: 	Tomcat Users List
> Enviada: 	sexta-feira, 21 de novembro de 2003 8:34
> Para: 	Tomcat Users List
> Assunto: 	Severity less - DBCP not closing connection.
> 
> I hope it is not posted twice. I wrote this mail in forenoon and when
> tried
> to send internet connection lost. I am retyping everything.
> 
>     I have seen DBCP not closing a connection if the request is forwarded
> to
> same page in the try block before the request is forwarded. With
> sendRedirect no problem. This occurs when the connection is obtained
> through
> JNDI look up datasource. I tested the same code in stand alone java
> application using manual pooling which works fine. I am using Tomcat
> 4.1.27
> and DBCP 1.1 (I upgraded it today), JDK 1.3.1 and Oracle 8i.
>   My configuration and code is given below.
> --------------------------------------------------------------------------
> --
> -----------------------
> <Context path="/test" docBase="test"
>         debug="0" reloadable="true" crossContext="true">
> 
>   <Logger className="org.apache.catalina.logger.FileLogger"
>              prefix="test_log." suffix=".txt"
>              timestamp="true"/>
> 
>   <Resource name="jdbc/Test"
>                auth="Container"
>                type="javax.sql.DataSource"/>
> 
>   <ResourceParams name="jdbc/Test">
>     <parameter>
>       <name>factory</name>
>       <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>     </parameter>
> 
>  <parameter>
>       <name>maxActive</name>
>       <value>1</value>
>     </parameter>
> 
>     <parameter>
>       <name>maxIdle</name>
>       <value>1</value>
>     </parameter>
> 
>     <parameter>
>       <name>maxWait</name>
>       <value>100000</value>
>     </parameter>
> 
>     <parameter>
>      <name>username</name>
>      <value>scott</value>
>     </parameter>
>     <parameter>
>      <name>password</name>
>      <value>tiger</value>
>     </parameter>
> 
>     <parameter>
>        <name>driverClassName</name>
>        <value>oracle.jdbc.driver.OracleDriver</value>
>     </parameter>
> 
>  <parameter>
>       <name>url</name>
>       <value>jdbc:oracle:thin:@localhost:1521:DB</value>
>     </parameter>
> 
>  <parameter>
>   <name>removeAbandoned</name>
>   <value>true</value>
>  </parameter>
>  <parameter>
>   <name>removeAbandonedTimeout </name>
>   <value>30</value>
>  </parameter>
>   </ResourceParams>
> </Context>
> 
> --------------------------------------------------------------------------
> --
> ----------------------
> <html>
> <body>
> <%@ page import="java.sql.*"%>
> <%@ page import="javax.sql.*"%>
> <%@ page import="javax.naming.*"%>
> <%@ page
> import="org.apache.commons.dbcp.datasources.SharedPoolDataSource"%>
> <%@ page import="org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS"%>
> <%
> /*DriverAdapterCPDS cpds = new DriverAdapterCPDS();
> cpds.setDriver("oracle.jdbc.driver.OracleDriver");
> cpds.setUrl("jdbc:oracle:thin:@localhost:1521:DB");
> cpds.setUser("scott");
> cpds.setPassword("tiger");
> 
> SharedPoolDataSource tds = new SharedPoolDataSource();
> tds.setConnectionPoolDataSource(cpds);
> tds.setMaxActive(1);
> tds.setMaxIdle(1);
> tds.setMaxWait(3000); */
> 
> Context initContext = new InitialContext();
> Context envContext  = (Context)initContext.lookup("java:/comp/env");
> DataSource ds =
> (DataSource)initContext.lookup("java:/comp/env/jdbc/Test");
> 
> PreparedStatement pstmt = null;
> ResultSet rs = null;
> Connection conn = null;
> 
> String action = request.getParameter("action");
> if("1".equals(action)){
>  long time = 0;
> 
>  try{
>   conn = tds.getConnection();
>   conn = ds.getConnection();
>   pstmt = conn.prepareStatement("select empno,ename from scott.emp where
> empno=?");
>   pstmt.setString(1,"7369");
>   rs = pstmt.executeQuery();
>   while(rs.next()){
>    System.out.println("Ename - "+rs.getString(1)+" - "+rs.getString(2));
>   }
>   time = System.currentTimeMillis();
>   System.out.println("Before forward -
> 0");time=System.currentTimeMillis();
>  
> application.getRequestDispatcher("/TestDB.jsp?action=2").forward(request,r
> esponse);
>   System.out.println("After forward -
> "+(System.currentTimeMillis()-time));
> 
>  }catch(SQLException sqle){
> 
>   System.out.println("1 " +sqle);
>  }finally{
>   if(rs!=null)rs.close();
>   if(pstmt!=null) pstmt.close();
>   if(conn!=null)conn.close();
>  }
> }else if("2".equals(action)){
>  long time = 0;
>  System.out.println("In Two start - time =
> 0");time=System.currentTimeMillis();
>  try{
>   conn = tds.getConnection();
>   conn = ds.getConnection();
>   pstmt = conn.prepareStatement("select empno,ename from scott.emp where
> empno=?");
>   pstmt.setString(1,"7499");
>   rs = pstmt.executeQuery();
>   while(rs.next()){
>    System.out.println("Ename - "+rs.getString(1)+" - "+rs.getString(2));
>   }
>  }catch(SQLException sqle){
> 
>   System.out.println("2 "+sqle);
>  }finally{
>   if(rs!=null)rs.close();
>   if(pstmt!=null) pstmt.close();
>   if(conn!=null)conn.close();
>  }
>  System.out.println("In Two end - "+(System.currentTimeMillis()-time));
> }
> %>
> 
> 
> I work with one connection to test for connection leak and any bottlenecks
> in code. It works fine if I put the forward() after the end of finally
> block. I want to know whether it is bug or config error or Tomcat behaves
> so.
> 
> Antony Paul.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message