Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Spring + Hibernate/C3P0 leaving behind threads and pools

  1. #11
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Normally you don't need to close the context OR you aren't in control and the closing is done for you.

    Only at closing the application context the destroy methods are called. Which, I agree, isn't that clearly mentioned in the documentation. However it is mentioned that on destruction of the applicationcontext (chapter 3.6) the destroy-method is called, and destruction is something else as getting garbage collection.

    The close method is part of the AbstractApplicationContext and should be called to invoke proper context shutdown.

    Quote Originally Posted by alex314
    Well, as I suspected, it turns out that even after using Spring Transaction Management and Hibernate integration according to the "canon", it is still leaking threads...
    You are stating that you know things better and everything is as you expected and you are calling the resources which are trying to help you "canon", which basically means IMHO you aren't showing respect either... Hence my sighing...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  2. #12
    Join Date
    Aug 2010
    Posts
    9

    Default

    You are stating that you know things better and everything is as you expected
    What I'm stating is only what I've written: That after following the official way of doing things and your advice, it still exhibited the same problem, and that this was in line with my belief (as per the OP) that the problem had to do with resource disposal rather than the other things you suggested. This has nothing to do with respect. If I didn't respect your opinion, I wouldn't have followed your suggestion in the first place, don't you think?

    Please take a step back and look at the frequency with which you sigh at people in your posts.


    Regarding the issue at hand, IMHO if there are situations in which an ApplicationContext needs special shutdown operations then the close() method should belong to that interface and not to some subinterface, and it should be mentioned explicitly in the documentation, especially considering that ApplicationContext is "THE" Spring Interface.

    Cheers

    Alex

  3. #13
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Regarding the issue at hand, IMHO if there are situations in which an ApplicationContext needs special shutdown operations then the close() method should belong to that interface and not to some subinterface, and it should be mentioned explicitly in the documentation, especially considering that ApplicationContext is "THE" Spring Interface.
    Then create a [url=jira.springsource.orgJIRA issue[/url] for that so that the spring people can improve the documentation.

    What I don't understand is that you know that you need to clean-up after yourself when using plain hibernate (closing the sessionfactory). But you expect spring to magically close everything for you even if you don't trigger/tell it to or you expect hibernate to cleanup resources that it doesn't manage (the external connection pool).

    Maybe I should sign of here, leave to forum, spring and the community. I'm not sure, well see what the future holds...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  4. #14
    Join Date
    Jul 2009
    Posts
    5

    Default What can i do ? please

    hi dear friends.
    i have some exceptions such as The connection is closed or Can not checkout connection like :
    Code:
    =org.hibernate.jdbc.AbstractBatcher 2011-03-09 12:31:12,187 -- WARN -- exception clearing maxRows/queryTimeout
    com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
    	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
    	at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(SQLServerConnection.java:319)
    	at com.microsoft.sqlserver.jdbc.SQLServerStatement.checkClosed(SQLServerStatement.java:956)
    	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getMaxRows(SQLServerStatement.java:989)
    	at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.getMaxRows(NewProxyPreparedStatement.java:1200)
    	at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:298)
    	at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:234)
    	at org.hibernate.loader.Loader.getResultSet(Loader.java:1967)
    	at org.hibernate.loader.Loader.doQuery(Loader.java:802)
    	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    	at org.hibernate.loader.Loader.loadCollection(Loader.java:2166)
    	at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:62)
    	at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:627)
    	at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
    	at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1863)
    	at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:479)
    	at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:900)
    	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:279)
    	at org.hibernate.loader.Loader.doList(Loader.java:2533)
    	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    	at org.hibernate.loader.Loader.list(Loader.java:2271)
    	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
    	at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
    	at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    	at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:859)
    ... DA layer of my application (simple query to load an object)
    	at sun.reflect.GeneratedMethodAccessor381.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:55)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
    	at sun.reflect.GeneratedMethodAccessor145.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
    	at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy10. MYMETHODNAME (Unknown Source)
    	at sun.reflect.GeneratedMethodAccessor381.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    	at org.springframework.remoting.support.RemoteInvocationTraceInterceptor.invoke(RemoteInvocationTraceInterceptor.java:77)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy10. MYMETHODNAME (Unknown Source)
    	at sun.reflect.GeneratedMethodAccessor680.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.remoting.support.RemoteInvocation.invoke(RemoteInvocation.java:205)
    	at org.springframework.security.remoting.rmi.ContextPropagatingRemoteInvocation.invoke(ContextPropagatingRemoteInvocation.java:103)
    	at org.springframework.remoting.support.DefaultRemoteInvocationExecutor.invoke(DefaultRemoteInvocationExecutor.java:38)
    	at org.springframework.remoting.support.RemoteInvocationBasedExporter.invoke(RemoteInvocationBasedExporter.java:78)
    	at org.springframework.remoting.rmi.RmiBasedExporter.invoke(RmiBasedExporter.java:73)
    	at org.springframework.remoting.rmi.RmiInvocationWrapper.invoke(RmiInvocationWrapper.java:72)
    	at sun.reflect.GeneratedMethodAccessor144.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
    	at sun.rmi.transport.Transport$1.run(Transport.java:159)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
    	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:662)

  5. #15
    Join Date
    Jul 2009
    Posts
    5

    Default ... What can i do ? Please

    I use spring 3.0.5, hibernate 3.6.0, c3p0 0.9.1
    my configuration :

    Code:
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass"                            value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
            <property name="jdbcUrl"                                value="jdbc:sqlserver://127.0.0.1:1433;databaseName=MYDB"/>
            <property name="user"                                   value="sa"/>
            <property name="password"                               value="pass"/>
    
            <property name="acquireIncrement"                       value="10"/>
            <property name="acquireRetryAttempts"                   value="30"/>
            <property name="acquireRetryDelay"                      value="1000"/>
            <property name="autoCommitOnClose"                      value="false"/>
            <property name="debugUnreturnedConnectionStackTraces"   value="true"/>
            <property name="idleConnectionTestPeriod"               value="100"/>
            <property name="initialPoolSize"                        value="10"/>
            <property name="maxConnectionAge"                       value="1000"/>
            <property name="maxIdleTime"                            value="200"/>
            <property name="maxIdleTimeExcessConnections"           value="3600"/>
            <property name="maxPoolSize"                            value="300"/>
            <property name="minPoolSize"                            value="10"/>
            <property name="preferredTestQuery"                     value="select 1"/>
            <property name="testConnectionOnCheckin"                value="false"/>
            <property name="unreturnedConnectionTimeout"            value="1000"/>
        </bean>
    
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource"     ref="dataSource"/>
            <property name="schemaUpdate"   value="false"/>
            <property name="mappingResources">
                <list>
                     ...
                </list>
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
                    <prop key="hibernate.show_sql">false</prop>
                    <prop key="hibernate.hbm2ddl.auto">update</prop>
                    <prop key="hibernate.generate_statistics">false</prop>
                    <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
                    <prop key="hibernate.cache.use_query_cache">true</prop>
                    <prop key="hibernate.cache.use_second_level_cache">true</prop>
                    <prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
                </props>
            </property>
            <property name="eventListeners">
                <map>
                    <entry key="merge">
                        <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
                    </entry>
                </map>
            </property>
    </bean>

  6. #16
    Join Date
    Jul 2009
    Posts
    5

    Default ... What can i do ? Please

    or this Exception :

    Code:
    =org.hibernate.exception.GenericJDBCException: could not inspect JDBC autocommit mode
    	at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
    	at org.hibernate.jdbc.JDBCContext.afterNontransactionalQuery(JDBCContext.java:296)
    	at org.hibernate.impl.SessionImpl.afterOperation(SessionImpl.java:595)
    	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1010)
    	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
    My Application layer (simple query for get an object)
    	at sun.reflect.GeneratedMethodAccessor666.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:55)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
    	at sun.reflect.GeneratedMethodAccessor145.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
    	at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy10. MYMETHODNAME (Unknown Source)
    	at sun.reflect.GeneratedMethodAccessor666.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    	at org.springframework.remoting.support.RemoteInvocationTraceInterceptor.invoke(RemoteInvocationTraceInterceptor.java:77)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy10. MYMETHODNAME (Unknown Source)
    	at sun.reflect.GeneratedMethodAccessor806.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.remoting.support.RemoteInvocation.invoke(RemoteInvocation.java:205)
    	at org.springframework.security.remoting.rmi.ContextPropagatingRemoteInvocation.invoke(ContextPropagatingRemoteInvocation.java:103)
    	at org.springframework.remoting.support.DefaultRemoteInvocationExecutor.invoke(DefaultRemoteInvocationExecutor.java:38)
    	at org.springframework.remoting.support.RemoteInvocationBasedExporter.invoke(RemoteInvocationBasedExporter.java:78)
    	at org.springframework.remoting.rmi.RmiBasedExporter.invoke(RmiBasedExporter.java:73)
    	at org.springframework.remoting.rmi.RmiInvocationWrapper.invoke(RmiInvocationWrapper.java:72)
    	at sun.reflect.GeneratedMethodAccessor144.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
    	at sun.rmi.transport.Transport$1.run(Transport.java:159)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
    	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:662)
    Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
    	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
    	at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(SQLServerConnection.java:319)
    	at com.microsoft.sqlserver.jdbc.SQLServerConnection.getAutoCommit(SQLServerConnection.java:1602)
    	at com.mchange.v2.c3p0.impl.NewProxyConnection.getAutoCommit(NewProxyConnection.java:985)
    	at org.hibernate.jdbc.ConnectionManager.isAutoCommit(ConnectionManager.java:212)
    	at org.hibernate.jdbc.JDBCContext.afterNontransactionalQuery(JDBCContext.java:287)
    	... 68 more

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •