-->
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.  [ 3 posts ] 
Author Message
 Post subject: c3p0 conn pool does not re-init correctly after shutdown?
PostPosted: Tue Dec 21, 2004 3:52 pm 
Newbie

Joined: Thu Dec 09, 2004 1:57 pm
Posts: 2
hi folks, searched the forums and did not see this problem addressed. if it has a link would be appreciated.

i have a webapp instance, with multiple webapps being deployed and redeployed (it's a development environment). i have an application server-level (not web-app level) object ("manager") which has a reference to a singleton instance of a DAO object which is using hibernate. i was experiencing timeout problems with DBCP (well noted on these forums) and have switched to c3p0. each webapp is required to register/unregister with the manager (using a load-on-startup servlet's init/destroy methods). so,
Code:
    public synchronized static void registerClient(String name){
        if (instance == null){
            //calls private init() method, initializing hibernate dao object
            instance = new OfferCacheManager();
        }
        clientNum++;
    }

    public synchronized static void unregisterClient(String name){
        clientNum--;
        if (clientNum == 0){
         //calls sessionFactory.shutdown();   
         shutdown();
        }
    }


initially (jvm startup), the manager instance is initialized in a static block. the register/unregister stuff happens fine, and as expected, when there are no webapps left shutdown gets called correctly. however, if i then redeploy without restarting the server, and try to get a new instance (which calls the Hibernate initialization code as follows:

Code:
{
     net.sf.hibernate.cfg.Configuration config
            = new net.sf.hibernate.cfg.Configuration();
     Properties p = new Properties();
     //go get properties
     config.setProperties(props);
     config.configure();
     sessionFactory = config.buildSessionFactory(); 
     }


) in registerClient(), i get the below error. note that this all works fine using DBCP, so i'm guessing i have to do something to accomodate c3p0...but i'm not sure what that might be. or is the answer to just always restart the server with a deploy (kind of a pain in development)? any ideas?

thanks in advance,
peter


Hibernate version:
hibernate 2.1,
c3p0 version 0.8.4.5


Mapping documents:

using resin, and programmatically creating a hibernate properties file to pass to configure with (jdbc connection params taken out):

<system-property hibernate.c3p0.acquire_increment="1"/>
<system-property hibernate.c3p0.idle_test_period="180"/>
<system-property hibernate.c3p0.max_size="100"/>
<system-property hibernate.c3p0.max_statements="0"/>
<system-property hibernate.c3p0.min_size="10"/>
<system-property hibernate.c3p0.timeout="100"/>

Full stack trace of any exception that occurs:
net.sf.hibernate.exception.GenericJDBCException: Cannot open connection
at net.sf.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:81)
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.impl.BatcherImpl.convert(BatcherImpl.java:325)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:292)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3361)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3321)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:66)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1553)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.ch.qjOfferCache.DAO.hibernate.HibernateAppOfferDAO.doQuery(HibernateAppOfferDAO.java:461)
at com.ch.qjOfferCache.DAO.hibernate.HibernateAppOfferDAO.getAppDeptFromDeptClubCodes(HibernateAppOfferDAO.java:189)
at com.ch.qjOfferCache.offercache.OfferCacheManager.fetchJoinOffer(OfferCacheManager.java:459)
at com.ch.site.struts.actions.performers.ManageDBOfferCache.perform(ManageDBOfferCache.java:117)
at com.ch.site.struts.actions.LocaleAction.executePerformers(LocaleAction.java:134)
at com.ch.site.struts.actions.LocaleAction.perform(LocaleAction.java:92)
at org.apache.struts.action.Action.execute(Action.java:420)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at com.ch.site.struts.CustomActionServlet.process(CustomActionServlet.java:29)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:165)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:96)
at com.ch.site.filters.TrimLinesFilter.doFilter(TrimLinesFilter.java:48)
at com.caucho.server.http.FilterChainFilter.doFilter(FilterChainFilter.java:88)
at com.caucho.server.http.Invocation.service(Invocation.java:315)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.sql.SQLException: com.mchange.v2.c3p0.PoolBackedDataSource@4adb34 [ connectionPoolDataSource -> com.mchange.v
2.c3p0.WrapperConnectionPoolDataSource@1ccbdf7 [ acquireIncrement -> 1, autoCommitOnClose -> false, connectionTesterClassName
-> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> fals
e, idleConnectionTestPeriod -> 180, initialPoolSize -> 10, maxIdleTime -> 100, maxPoolSize -> 100, maxStatements -> 0, minPoo
lSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@7d4275 [ description -> null, driverClass -> nul
l, factoryClassLocation -> null, jdbcUrl -> jdbc:informix-sqli://10.xxx.x.xx:9999/customer:INFORMIXSERVER=dbname, proper
ties -> {user=xxxxxx, password=xxxxxx} ] , propertyCycle -> 300, testConnectionOnCheckout -> false ] , factoryClassLocation -
> null, numHelperThreads -> 3 ] has been closed() -- you can no longer use it.
at com.mchange.v2.c3p0.PoolBackedDataSource.assertCpds(PoolBackedDataSource.java:129)
at com.mchange.v2.c3p0.PoolBackedDataSource.getPoolManager(PoolBackedDataSource.java:141)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:58)
at net.sf.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:33)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289)
... 34 more

Name and version of the database you are using:
informix


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 10:37 pm 
C3P0 Developer
C3P0 Developer

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

I'm not positive, but I have a guess about your problem, and if I'm right, your problem should go away if you upgrade to a recent c3p0-0.8.5-preX release. Can you give that a try, and drop a note if that resolves the problem?

If my guess is right, the issue is this: JNDI-based resources can be looked up withing a single JVM, or across JVM boundaries, via deserialization or derefencing. To deal with this, c3p0 adopts a one connection-pool-manager per DataSource per JVM policy. When c3p0 deserializes or unreferences a datasource, it looks up the appropriate connection-pool-manager and uses it, rather than blindly creating a new set of threads and pools. Prior to c3p0-0.8.5, this lookup was insufficiently precise, and two unrelated DataSources of identical configuration would find the same set of pools. If the connection-pool-manager had already been closed, well... it's a problem. Newer c3p0s retain a token representing the identity of the original DataSource, and only "finds" a connection-pool-manager if in fact the new DataSource was deserialized/dereferenced from the same original.

Note that even if your app has no truck with JNDI whatsoever, this problem can bite you, because prior to c3p0-0.8.5, two identically configured pooled DataSources shared the same resources, regardless of the fact that they were unrelated. c3p0-0.8.5 resolves this issue.

I hope this helps!

Steve (c3p0-maintainer)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 22, 2004 4:34 pm 
Newbie

Joined: Thu Dec 09, 2004 1:57 pm
Posts: 2
steve,

thanks for the thoughtful reply. i did try c3p0-0.8.5-pre9.jar, but it did not seem to resolve the problem i was experiencing. since i really only needed to shutdown the connection pool when the jvm was shutdown, i wound up solving the problem by implementing a solution along the lines suggested here:

http://www.devx.com/getHelpOn/10MinuteSolution/20459

again thanks much for the suggestion and for c3p0!

cheers,
peter


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