tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sasidhar prabhakar <sasidhar1...@gmail.com>
Subject Re: DBCP abandoned trace - unable to understand the leak
Date Wed, 10 Nov 2010 09:41:51 GMT
On Wed, Nov 10, 2010 at 3:02 AM, Pid <pid@pidster.com> wrote:

> On 04/11/2010 12:04, sasidhar prabhakar wrote:
> > dataSource = ConnectionUtil.getDataSource();
> > }
>
> Is the class you posted the only DAO?  Could the leak be from another
> class?
>

Some other DAOs are there. Which takes more than removeAbandonedTimeout.
Except timeout I didn't find any unclosed connections, statements and
results.


>
> Can you post ConnectionUtil.java?
>
>

This is DAO class

import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class ConnectionUtil {
private static Log log = LogFactory.getLog(ConnectionUtil.class);

private static String dataSourceJNDIName = "java:comp/env/jdbc/ds";
private static DataSource dataSource;

public static DataSource getDataSource() {
if(dataSource == null) {
try {
log.info("In the ConnectionUtil:getDataSource():Befor calling lookup on
context");
Context ctx = new InitialContext();
dataSource = (DataSource)ctx.lookup(dataSourceJNDIName);
ctx.close();
} catch(Exception e) {
log.error("Can not create DataSource "+e.getMessage());
throw new IllegalStateException(e.getMessage());
}
}
return dataSource;
}

public static void setDataSource(DataSource ds) {
dataSource = ds;
}

public static Connection getConnection() throws SQLException {
return getDataSource().getConnection();
}

public static void beginTransaction(Connection conn) throws SQLException {
conn.setAutoCommit(false);
}

public static void endTransaction(Connection conn) throws SQLException {
conn.setAutoCommit(true);
}

public static void commit(Connection conn) throws SQLException {
conn.commit();
}

public static void rollback(Connection conn) throws SQLException {
conn.rollback();
}

public static void close(Connection conn) {
if (conn != null) {
try {

if( !conn.isClosed() )
conn.close();

} catch(SQLException e) {
log.error("SQL Exception caught while closing Connection :"+
e.getMessage());

}
}
}

public static void close(Statement stm) {
if (stm != null) {
try {

stm.close();

} catch(SQLException e) {
log.error("SQL Exception caught while closing Statement :"+ e.getMessage());
}
}
}

public static void close(ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch(SQLException e) {
log.error("SQL Exception caught while closing ResultSet :"+ e.getMessage());
}
}
}
}


>
> p
>
>

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