These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Abandoned connection checking with c3p0?
PostPosted: Sun Feb 13, 2005 5:45 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Hibernate version: hibernate-3.0beta4

I'm using Hibernate with several applications. Some of the applications are Web applications which I'm running in Tomcat. Others are standalone console applications. In Tomcat, I've always used the built-in connection pooling that Tomcat provides (Apache Commons DBCP (http://jakarta.apache.org/commons/dbcp/ ... ation.html)). However, I'm considering switching to using C3P0 so that I can use a single hibernate.properties file for both Web and standalone applications (I'm thinking about not using JNDI).

One of the things that I like about DBCP is that it can check for abandoned connections. i.e. it can detect connection pool leaks (when you forget close a JDBC connection through the result of a programming error or exception).

I'm wondering if anyone knows if there is a way to do this with C3P0 or Proxool? In looking at the C3P0 documentation, as far as I can tell, it doesn't have this capability...

I wonder if there is a way to use DBCP with Hibernate in standalone mode?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 1:07 am 
C3P0 Developer
C3P0 Developer

Joined: Tue Jan 06, 2004 8:58 pm
Posts: 145
Hi,

c3p0 does not offer any means of detecting Connections that users have forgotten to close(). About the only way I can think of implementing this would be to permit users to set a timeout, after which a Connection would be automatically close()ed, or else purged from the pool and left in the hands of the client. I'll consider adding this kind of thing to c3p0, although the importance of using reliable code paths for cleaning up resources can't be emphasized enough, in any sort of java programming.

I also hope to add a debug mode that would give users access to the stack traces that checked out Connections, for Connections that have not been returned to the pool.

But for now, the answer to your question is "no". c3p0 does nothing to help you recover from sloppy clients that forget to close their Connections. The workaround is to be sure you don't forget.

Sorry!

Steve (c3p0 guy)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 1:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You have to close the Hibernate Session *anyway*, and Hibernate will tell you if you don't.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 8:48 am 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Thanks for the response.

I think what you described is exactly what DBCP provides. i.e. a timeout on the checked out connection. i.e. if the user doesn't close the connection within a specified timeout, an exception is throw and you can look at the stack trace to find out where you failed to close the connection.

Currently, I'm using a design pattern which is listed on this web site which uses a servlet filter for opening and closing my Sessions and this seems to be working problem free. IMHO, it doesn't hurt to have an added level of protection though. I guess if you use a design pattern such as the one listed above and you only open connections at one place and close them at one place, it's easier to make sure your code is correct. Otherwise, it's not hard to make a mistake and end up with a connection leak if your not careful.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 8:51 am 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
So, does Hibernate have a time out like DBCP then? I'm wondering how it would know if you didn't close the session?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 9:22 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
jemiller wrote:
So, does Hibernate have a time out like DBCP then? I'm wondering how it would know if you didn't close the session?

Forget it, I do not know something more evil than this kind of workarounds, it will produce more problems and it can produce a problem then there is no problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 9:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
jemiller wrote:
So, does Hibernate have a time out like DBCP then? I'm wondering how it would know if you didn't close the session?


Hibernate logs a WARN from SessionImpl.finalize()


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 12:34 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
OK, that makes sense, it does it when it's garbage collected. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 12:46 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
It looks like Proxool's maximum-active-time property is what I was looking for...

It looks like Proxool hasn't been updated for awhile. Anyone know if that project is still alive?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.