Connection timeout
843854Jul 15 2003 — edited Jul 16 2003Hi,
I'm having a terrible problem: When I use a Connection by a long time (more than 35 seconds), The Application Server (Macromedia JRun 4) throws the following exception:
15/07 13:42:43 error Unhandled exception thrown from /testes/testeConnection.jsp:9
[1]java.sql.SQLException: This Connection has either timed out or been closed, and it has returned to its pool. You must
re-acquire the Connection.
at jrun.sql.JRunConnectionHandle.assertConnectionExists(JRunConnectionHandle.java:50)
...
This error is occurring in a real system, but I have generated it with this JSP:
--- JSP BEGIN ---
<%@page language="java"
import="java.sql.*,
java.util.*,
java.text.*,
javax.naming.*,
javax.sql.*"
%>
<%
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/pool0");
Connection con = ds.getConnection();
PreparedStatement pstmt = con.prepareStatement("Select * from tbrotvis,tbclirotvis");
int count = 1;
long now = 0;
ResultSet rs = null;
try {
now = System.currentTimeMillis();
rs = pstmt.executeQuery();
while ( rs.next() ) {
count++;
}
System.out.println("\n\n\n\n\nOK\n\n\n\n\n");
} catch (Exception e) {
System.out.println( "\n\n\n\n\n" );
System.out.println( "* ERROR" );
System.out.println( "* JSP testeConnection: " + count + " records, " + ((System.currentTimeMillis()-now)/1000) + " seconds." );
System.out.println( "\n\n\n\n\n" );
}
rs.close();
pstmt.close();
con.close();
%>
OK
--- JSP END ----
The exception doesn't have an exact place to be thown, it can be throw in the "executeQuery()" line or in the "while" line or in the "pstmt.close()" line.
My jrun-resources has the following configuration for the "pool0" DataSource:
<data-source>
<dbname>pool0</dbname>
<driver>macromedia.jdbc.MacromediaDriver</driver>
<url>jdbc:macromedia:oracle://192.168.0.4:1521;SID=tesla</url>
<username>saveweb</username>
<password>E0C50ECD24DB5F9401B1BDE7ACBAA158</password>
<encrypted>true</encrypted>
<encryption-class>jrun.security.JRunCrypterForTwofish</encryption-class>
<native-results>true</native-results>
<remove-on-exceptions>true</remove-on-exceptions>
<pool-statements>false</pool-statements>
<initial-connections>10</initial-connections>
<connection-timeout>60000000</connection-timeout>
<transaction-timeout>60000000</transaction-timeout>
<cache-enabled>false</cache-enabled>
<cache-size>5</cache-size>
<cache-refresh-interval>30</cache-refresh-interval>
<jndi-name>jdbc/pool0</jndi-name>
<poolname>Pool</poolname>
<minimum-size>10</minimum-size>
<maximum-size>2147483647</maximum-size>
<user-timeout>20</user-timeout>
<skimmer-frequency>420</skimmer-frequency>
<shrink-by>5</shrink-by>
<maximum-soft>true</maximum-soft>
<debugging>false</debugging>
<disable-pooling>false</disable-pooling>
<description />
<isolation-level>READ_COMMITTED</isolation-level>
</data-source>
I have put a large number in the timeout settings because I have thought that the problem was the dataSource timeout, but the Connection coninue being closed arround 35 seconds after opened.
Thanks for any help,
Sergio Stateri Jr
System Analyses
Sao Paulo (SP) - Brazil
sergio.jr@tesla.com.br