Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Tomcat DB connection hangs

Thread view: 
ricmar@gmail.com - 18 Oct 2007 15:17 GMT
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
Manish Pandit - 18 Oct 2007 19:41 GMT
On Oct 18, 7:17 am, ric...@gmail.com wrote:
> Hello,
>
[quoted text clipped - 18 lines]
> 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
ricmar@gmail.com - 24 Oct 2007 11:22 GMT
> On Oct 18, 7:17 am, ric...@gmail.com wrote:
>
[quoted text clipped - 38 lines]
> -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
Manish Pandit - 24 Oct 2007 20:03 GMT
On Oct 24, 3:22 am, ric...@gmail.com wrote:

> Hello,
>
[quoted text clipped - 13 lines]
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.