https://issues.apache.org/bugzilla/show_bug.cgi?id=53905
Priority: P2
Bug ID: 53905
Assignee: [email protected]
Summary: Connection pool not reusing connections.
Severity: normal
Classification: Unclassified
Reporter: [email protected]
Hardware: PC
Status: NEW
Version: unspecified
Component: jdbc-pool
Product: Tomcat Modules
I am trying the new jdbc connection pool with tomcat 6.0.35 and I am noticing
some strange behavior.
The info about what I am doing is below.
When the pool starts up I see 5 connections as I would expect, then after about
60 seconds 2 connections get dropped as there has been no activity. Up to this
point everything seems to be working properly.
My test program will do a http get over a fixed number of times for x number of
sessions
So I call all.bat like this
c:\temp> all.bat 2 200
which will create two session that will do a wget 200 times each of a random
number.
Now I run my test, this is just 2 clients calling the same url over and over
again in a loop. ( I would expect to see only 2 connections required but on the
first run I see a total of 8 connections. When the test completes in about 20
seconds I run the test again and I see the pool grow to a total of 17
connections.
Also, once I am done my tests I don't see idle connections being released from
the pool either. I have waited over an hour and I don't see the connections
being disconnected.
SQL> /
SYSDATE SID USERNAME LOGON_TIME
IDLE
-------------------- ---------- ------------------------------
-------------------- --------------------
19-SEP-2012 15:59:06 32 DBA_XXXX 19-SEP-2012
15:45:12 0:0:39
19-SEP-2012 15:59:06 34 DBA_XXXX 19-SEP-2012
15:58:31 0:0:34
19-SEP-2012 15:59:06 54 DBA_XXXX 19-SEP-2012
15:58:55 0:0:11
19-SEP-2012 15:59:06 55 DBA_XXXX 19-SEP-2012
15:58:54 0:0:4
19-SEP-2012 15:59:06 58 DBA_XXXX 19-SEP-2012
15:58:54 0:0:11
19-SEP-2012 15:59:06 69 DBA_XXXX 19-SEP-2012
15:58:57 0:0:8
19-SEP-2012 15:59:06 71 DBA_XXXX 19-SEP-2012
15:59:01 0:0:5
19-SEP-2012 15:59:06 79 DBA_XXXX 19-SEP-2012
15:58:29 0:0:36
19-SEP-2012 15:59:06 81 DBA_XXXX 19-SEP-2012
15:45:12 0:0:49
19-SEP-2012 15:59:06 87 DBA_XXXX 19-SEP-2012
15:59:02 0:0:4
19-SEP-2012 15:59:06 92 DBA_XXXX 19-SEP-2012
15:58:27 0:0:37
19-SEP-2012 15:59:06 94 DBA_XXXX 19-SEP-2012
15:58:29 0:0:37
19-SEP-2012 15:59:06 108 DBA_XXXX 19-SEP-2012
15:58:59 0:0:5
19-SEP-2012 15:59:06 117 DBA_XXXX 19-SEP-2012
15:58:56 0:0:10
19-SEP-2012 15:59:06 119 DBA_XXXX 19-SEP-2012
15:45:12 0:0:37
19-SEP-2012 15:59:06 132 DBA_XXXX 19-SEP-2012
15:58:53 0:0:12
19-SEP-2012 15:59:06 133 DBA_XXXX 19-SEP-2012
15:58:56 0:0:10
17 rows selected.
all.bat
~~~~~~~
echo off
set size=%2
for /L %%x in (1, 1, %1) do (call :sub %%x )
GOTO :eof
:sub
start cmd /k c:\temp\run.bat %1 %size%
GOTO :eof
:eof
run.bat
~~~~~~~~
echo off
set FILE=%1
set SIZE=%2
for /L %%x in (1, 1, %SIZE% ) do (call :sub %%x )
GOTO :eof
:sub
echo Run %1
wget -q --output-document=sess%FILE%.txt http://localhost:8080/test/db
GOTO :eof
:eof
context.xml
~~~~~~~~~~~~
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/test" docBase="test" debug="1" reloadable="true">
<!-- Specify a JDBC datasource -->
<Resource name="jdbc/testdb" auth="Container"
type="javax.sql.DataSource" username="dba_XXXX" password="XXXXXX"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@test1:1521/DB1"
initialSize="5" maxActive="20" maxIdle="4" minIdle="3"
maxWait="-1"
defaultAutoCommit="false"
testOnBorrow="false"
testWhileIdle="true"
validationQuery="select 1 from dual" />
</Context>
TestServlet.java
~~~~~~~~~~~~~~~~
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class TestServlet extends HttpServlet {
private DataSource dataSource;
private Connection connection;
private Statement statement;
public void init() throws ServletException {
try {
// Get DataSource
Context initContext = new InitialContext();
Context envContext =
(Context)initContext.lookup("java:/comp/env");
dataSource = (DataSource)envContext.lookup("jdbc/testdb");
} catch (NamingException e) {
e.printStackTrace();
}
}
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PrintWriter out = resp.getWriter();
ResultSet resultSet = null;
out.println("so far so good");
try {
// Get Connection and Statement
connection = dataSource.getConnection();
out.println("got connection");
statement = connection.createStatement();
out.println("create a statement");
String query = "select to_char(round(dbms_random.value(1,1000),4))
from dual";
out.println("Query is " + query);
resultSet = statement.executeQuery(query);
out.println("Got resultset");
while (resultSet.next()) {
out.println(resultSet.getString(1) );
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
out.println("Close resultset");
try { if (null!=resultSet) resultSet.close();
out.println("resultset closed");} catch (SQLException e)
{e.printStackTrace();}
out.println("Close statement");
try { if (null!=statement) statement.close();
out.println("Statement closed"); } catch (SQLException e)
{e.printStackTrace();}
out.println("Close connection");
try { if (null!=connection) connection.close();
out.println("Connection Closed"); } catch (SQLException e)
{e.printStackTrace();}
out.close();
}
}
}
Web.xml
~~~~~~~~
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>TomcatConnectionPooling</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/testdb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/db</url-pattern>
</servlet-mapping>
</web-app>
Oracle 11GR2 JDBC Driver Version : ojdbc6.jar
JDBC CONNECTION POOL Version : 1.1.0.1
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]