I know this is probably a question for another forum but I wanted to make sure I'm not missing something with my ActiveJdbc setup
I get the following SQL Exception when trying to open a DB Connection first thing every morning:
Could not close connection! MUST INVESTIGATE POTENTIAL CONNECTION LEAK! java.sql.SQLException: Already closed.
It throws this exception 3 times before working on the 4th attempt. After that it works fine the rest of the day. I'm using Mysql (Actually MariaDb 5.5) and tomcat 7 connection pooling.
From what I've looked at everything seems to be setup correctly for pooling and works except after what looks to be a period of inactivity. So for some reason I guess the connections are not getting cleaned up. I'm using the sample ActiveJdbcFileter with a couple modifications. Below is the stack trace:
2014-03-16 11:33:46 WARN [http-bio-8080-exec-5] (DB.java:224) - Could not close connection! MUST INVESTIGATE POTENTIAL CONNECTION LEAK!
java.sql.SQLException: Already closed.
at org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:114)
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:191)
at org.javalite.activejdbc.DB.close(DB.java:221)
at org.javalite.activejdbc.Base.close(Base.java:123)
at com.creditsys.filter.ActiveJdbcWebFilter.doFilter(ActiveJdbcWebFilter.java:75)
.....
And this is my context.xml with the jdbc configs:
<Context antiJARLocking="true" path="/">
<Resource name="jdbc/creditsys" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="xxxxx" password="xxxxxx" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/creditsys"/>
</Context>
And the relevant parts of ActiveJdbcWebFiler.java
@Override
public void init(FilterConfig filterConfig) throws ServletException {
jndiName = filterConfig.getInitParameter("jndiName");
.....
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
try{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup(jndiName);
Base.open(ds);
Base.openTransaction();
chain.doFilter(request, response);
Base.commitTransaction();
} ....
finally {
Base.close();
}