Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Need help on connection pooling in tomcat

  Asked By: Phil    Date: Sep 25    Category: Java    Views: 1256
  

I am using tomcat 6.0.13 with oracle 10g and jdk 1.6.0_05. I am
using database connection pool and everything working well. Problem
is sometime i am getting "Connection
oracle.jdbc.driver.T4CConnection@xxxxx is
closed" error for few pages but at the same time other pages are
woking well. Please anybody help me to solve this issue. I also
pasted the server.xml, context.xml and servelet connection object
code.


server.xml
--------------
<Resource name="jdbc/myDb"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@devserver:1521:orcl"
username="scott"
password="tiger"
maxActive="100"
maxIdle="30"
maxWait="-1"
removeAbandoned="true" />
context.xml
----------------
<ResourceLink global="jdbc/myDb" name="jdbc/myDb"
type="oracle.jdbc.OracleDataSource"/>

java servlet
----------------
Context initContext = new InitialContext();
Context envContext =
(Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myDb");
conn = ds.getConnection();

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Phoebe Brown     Answered On: Sep 25

Make sure you are closing all opened connection  after using it. To find out the connection leak use the following parameters for connection pooling

<parameter> <name>removeAbandoned</name> <value>true</value> </parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>

 
Answer #2    Answered By: Latoya Murray     Answered On: Sep 25

I am closing the connection  immeidately with following code in each file

servlet
--------
public void destroy() {
try {if (conn != null) conn.close();} catch (SQLException e) {}
}

jsp
----
public void jspDestroy()
{
try {if (conn != null) conn.close();} catch (SQLException e) {}
}

Please suggest me if any mistake in above code

 
Answer #3    Answered By: Shobhana R.     Answered On: Sep 25

Can you message log trace to this, so that we can get some idea where the error  is?

 
Answer #4    Answered By: Carl Woods     Answered On: Sep 25


quick opinion here

1) I assume it would be a good practice to close the conn in finally part,
2) I assume you're opening and closing the conn in the right place, but I guess I've come across this problem when oracle  runs out of memory either on dynamic memory or physical(out of space) and it closes the connection  (hard to expect from oracle but it happens) it usually happens on expensive queries or those that return millions of rows which leads to revisiting the queries. check processes and run diagnostics on oracle itself to see what's the status of processes when this happens

does oracle log has anything more to say i.e. error  number? cause it would not close a conn without a legitimate error , check the log, it might give some guidance

 
Answer #5    Answered By: Sandeep Bhandari     Answered On: Dec 03

Check out a tutorial on tomcat jdbc connection pool

 
Didn't find what you were looking for? Find more on Need help on connection pooling in tomcat Or get search suggestion and latest updates.




Tagged: