Tomcat DB connection hangs

R

ricmar

Hello,

After searching a lot through google I still cannot find the solution
for my problem. I hope someone could help me.

I have a tomcat 5.0 running on a solaris OS which connect via
oracle.jdbc.driver.OracleDriver to a Oracle database.

I have a web application that works OK and I also have a thread (which
uses the same tomcat context) running every 5 minutes querying the
database for some data.

After some days or sometimes hours the connection hangs. The only way
to "resume" the thread is restarting tomcat.

I think the connections are beeing closed since the web application is
still available.

Can anyone give some tips, so I can figure out this problem?

Thanks in advance,
Ricardo Marques
 
M

Manish Pandit

Hello,

After searching a lot through google I still cannot find the solution
for my problem. I hope someone could help me.

I have a tomcat 5.0 running on a solaris OS which connect via
oracle.jdbc.driver.OracleDriver to a Oracle database.

I have a web application that works OK and I also have a thread (which
uses the same tomcat context) running every 5 minutes querying the
database for some data.

After some days or sometimes hours the connection hangs. The only way
to "resume" the thread is restarting tomcat.

I think the connections are beeing closed since the web application is
still available.

Can anyone give some tips, so I can figure out this problem?

Thanks in advance,
Ricardo Marques

Can you verify from the Oracle Server end to ensure the connections
are actually closed?

It could be that the connection closing code is a part of a try{ }
instead of finally{ }, so if there is an error, the connection(s)
never get closed... commonly overlooked mistake.

Also, instead of opening up a new connection every time the thread
wakes up, keep the connection as a static class variable, initialize
it via a context listener (in contextInitialized method), and re-use
the same connection througout the lifecycle. You can close the
connection in the contextDestroyed method in the same listener. Google
around for listeners and their configuration if this suits as a good
solution.

-cheers,
Manish
 
R

ricmar

Can you verify from the Oracle Server end to ensure the connections
are actually closed?

It could be that the connection closing code is a part of a try{ }
instead of finally{ }, so if there is an error, the connection(s)
never get closed... commonly overlooked mistake.

Also, instead of opening up a new connection every time the thread
wakes up, keep the connection as a static class variable, initialize
it via a context listener (in contextInitialized method), and re-use
the same connection througout the lifecycle. You can close the
connection in the contextDestroyed method in the same listener. Google
around for listeners and their configuration if this suits as a good
solution.

-cheers,
Manish


Hello,

sorry for the late reply.

I have checked the connection and they are beeing closed. I also can
see tomcat creating/removing extra connections if needed (since I use
a pool connection).

Regarding the finally tip, every query I checked, the closes
statements are done in the finally { }.

I always get a connection from the existent DataSource and I use the
same DataSource. I think I should avoid the static variables when
concerning connections to DB.

thanks,
Ricardo
 
M

Manish Pandit

Hello,

sorry for the late reply.

I have checked the connection and they are beeing closed. I also can
see tomcat creating/removing extra connections if needed (since I use
a pool connection).

Regarding the finally tip, every query I checked, the closes
statements are done in the finally { }.

I always get a connection from the existent DataSource and I use the
same DataSource. I think I should avoid the static variables when
concerning connections to DB.

thanks,
Ricardo

In that case, you might want to download lambda-probe, a real time
monitoring/profiler application (http://www.lambdaprobe.org/d/
index.htm). This will give you and overview of memory usage,
unterminated threads..and anything that would seem unusual. I've found
it to be very useful in situations where I have unwarranted memory/CPU
issues.

-cheers,
Manish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top