-->
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.  [ 7 posts ] 
Author Message
 Post subject: SessionFactory.close() and Proxool shutdown
PostPosted: Sun Jan 25, 2004 5:41 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
As far as I understood the documentation, the proper way to shutdown Hibernate is to call SessionFactory.close(). This should destroy this SessionFactory and release all resources (caches, connection pools, etc).

But it seems that the ProxoolConnectionProvider doesn't shutdown Proxool properly: the connections to the database remain opens and the housekeeper threads keep running.

A quick look at the code reveals the following:
Code:
         // Kill all the connections (defaults gracefully) using
         // the ProxoolFacade
         ProxoolFacade.killAllConnections( proxoolAlias.substring( PROXOOL_JDBC_STEM.length() ) );


Unfortunately, the killAllConnections() is deprecated and doesn't do what should be done in this case: it just kills all connections currently open but doesn't shutdown the pool. Proxool will recreate the connections as soon as it can (immediately if your configuration requires a minimum number of open connections or at the first usage - which shouldn't occur since Hibernate is turned off).

According to me, ProxoolFacade.shutdown(0) should be called instead. This will shutdown Proxool immediately, closing all pools defined at the same time.

A more elegant approach even be to remove the pool used by Hibernate and shutdown proxool only if there is no other pool remaining (Proxool could then be shared by other applications - no idea if this situation is possible).

This would lead to the following code snippet:
Code:
          // Remove the connection pool associated with this Hibernate configuration
          String poolShortName = proxoolAlias.substring( PROXOOL_JDBC_STEM.length() );
          log.info("Remove Proxool connection pool " + poolShortName);
         
          ProxoolFacade.removeConnectionPool(poolShortName);
         
          // If there is no more connection pool - then shutdown proxool
          if( ProxoolFacade.getAliases().length==0 ) {
              log.info("No more Proxool connection pools - shutdown Proxool");
              ProxoolFacade.shutdown(0);
          }
          else {
              log.info("Some Proxool connection pools remain - do not shutdown Proxool");
          }


Any comments on this ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 5:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I'm not an expert on Proxool, so patches are welcome (JIRA).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 5:49 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
gavin wrote:
I'm not an expert on Proxool, so patches are welcome (JIRA).


I'm not an expert neither - just came to this conclusion by observing the behavior and reading the documentation.

Do you know if there is someone from the Proxool dev team listening ?
Or maybe I should post a mail to their dev mailing list ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 5:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I think Bill Horsman does follow our dev list, but pinging proxool mailing list is probably quicker.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 7:09 pm 
Newbie

Joined: Mon Dec 15, 2003 5:02 pm
Posts: 4
Location: Scotland
gavin wrote:
I think Bill Horsman does follow our dev list, but pinging proxool mailing list is probably quicker.


Consider me pinged :) For the record, I do follow the Hibernate dev-list but pinging proxool-dev is a good idea.

ProxoolFacade.killAllConnections() is, as you say, the wrong method to call. And, yes, removeConnectionPool() would be better. That would at least stop more connections being created and effectively stop Proxool apart from two threads: the house keeper and the prototyper. To stop Proxool completely you should call ProxoolFacade.shutdown(0).

But I'm intrigued by your problem of sharing a single instance of Proxool. This is possible if the class loader and your environment allows it. In a web container this could occur if the Proxool library is in a system classpath (as opposed to within WEB-INF/lib). The problem with your proposed solution is that it's not thread safe. Granted, it would be very unlikely for another component to register a pool during this code snippet but it is possible.

I propose a change to Proxool such that if you remove a connection pool then it automatically checks for any remaining pools (in a thread safe manner). If there are none then it shuts itself down. Note that there is nothing to stop Proxool restarting itself when a fresh pool is registered.

In the meantime, I recommend calling shutdown(0) and to make your life simpler by not sharing an instance of Proxool.

- Bill


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 7:01 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
billhorsman wrote:
But I'm intrigued by your problem of sharing a single instance of Proxool. This is possible if the class loader and your environment allows it. In a web container this could occur if the Proxool library is in a system classpath (as opposed to within WEB-INF/lib). The problem with your proposed solution is that it's not thread safe. Granted, it would be very unlikely for another component to register a pool during this code snippet but it is possible.


Currently, the ProxoolConnectionProvider can be configured so it borrows a Proxool pool configured from the outside. In this case, the Hibernate shutdown shouldn't do anything with the pool - leave it asis.

The second mode is where the ProxoolConnectionProvider is responsible to configure the Proxool pool itself - the pool will not be shared. In this case, the pool should be destroyed when Hibernate is shutted down.

Considering these two cases, I don't think we have any race conditions and the solution I made above should be ok (including ProxoolFacade.shutdown()).


billhorsman wrote:
I propose a change to Proxool such that if you remove a connection pool then it automatically checks for any remaining pools (in a thread safe manner). If there are none then it shuts itself down. Note that there is nothing to stop Proxool restarting itself when a fresh pool is registered.


Not sure it is needed - cfr. above.


billhorsman wrote:
In the meantime, I recommend calling shutdown(0) and to make your life simpler by not sharing an instance of Proxool.


Hibernate knows when the pool is shared. In this case nothing would be made on shutdown (cfr. above).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 3:14 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
An entry has been added to JIRA: http://opensource.atlassian.com/project ... key=HB-648


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.