-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to close connections when using Spring managed sessions?
PostPosted: Thu Aug 27, 2009 9:50 am 
Regular
Regular

Joined: Fri May 22, 2009 4:50 am
Posts: 59
hi,

I'm using Spring managed Hibernate session in my application. Under load testing, often I the java.net.SocketException: Connection reset exception as shown below.
Exception in not very consistent. Sometimes I get it after 50 orders and sometimes I get it after 500 orders.
Also from stacktrace I don't see any other reason which might lead to this exception.

I googled lot about the following exception. One of the concerns raised was, if the connections opened were closed as leaving many open connectios will also lead to such an exception.
but since I am using Spring managed Hibernate session, I dont open or close any connection explicitly. So i am unaware of the status of connections.
Does any one know the answer for this?

------------------------------------------------
11:37:20.358 [QFJ Message Processor] WARN o.h.util.JDBCExceptionReporter SQL Error: 0, SQLState: 08001
11:37:20.358 [QFJ Message Processor] ERROR o.h.util.JDBCExceptionReporter The connection attempt failed.
11:37:20.360 [QFJ Message Processor] WARN o.h.util.JDBCExceptionReporter SQL Error: 0, SQLState: 08001
11:37:20.360 [QFJ Message Processor] ERROR o.h.util.JDBCExceptionReporter The connection attempt failed.
11:37:20.366 [QFJ Message Processor] ERROR o.h.e.d.AbstractFlushingEventListener Could not synchronize database state with session
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:97) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2252) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2688) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) [hibernate-3.3.1.GA.jar:na]
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027) [hibernate-3.3.1.GA.jar:na]
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390) [spring-2.5.4.jar:2.5.4]
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:420) [spring-2.5.4.jar:2.5.4]
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) [spring-2.5.4.jar:2.5.4]
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:744) [spring-2.5.4.jar:2.5.4]
at com.tsdevelopment.fmk.persist.hibernate.dao.impl.ExecutionReportDaoImpl.storeExecutionReport(ExecutionReportDaoImpl.java:18) [fi-link-fix-1.0.jar:na]
at com.tsdevelopment.fmk.fix.ExecutionReportHandler.persistExecutionReport(ExecutionReportHandler.java:23) [fi-link-fix-1.0.jar:na]
at com.tsdevelopment.fmk.fix42.ExecutionReportHandler.processExecutionReportMessage(ExecutionReportHandler.java:63) [fi-link-fix-1.0.jar:na]
at com.tsdevelopment.fmk.fix42.ExecutionReportHandler.access$0(ExecutionReportHandler.java:41) [fi-link-fix-1.0.jar:na]
at com.tsdevelopment.fmk.fix42.ExecutionReportHandler$MessageHandler.onMessage(ExecutionReportHandler.java:122) [fi-link-fix-1.0.jar:na]
at quickfix.fix42.MessageCracker.crack42(MessageCracker.java:326) [quickfixj-1.4.0.jar:1.4.0]
at quickfix.fix42.MessageCracker.crack(MessageCracker.java:259) [quickfixj-1.4.0.jar:1.4.0]
at com.tsdevelopment.fmk.fix42.ExecutionReportHandler.$(ExecutionReportHandler.java:104) [fi-link-fix-1.0.jar:na]
at sun.reflect.GeneratedMethodAccessor41.invoke(Unknown Source) [na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [na:1.6.0_13]
at java.lang.reflect.Method.invoke(Method.java:597) [na:1.6.0_13]
at com.miriamlaurel.pms.listeners.dispatch.DispatchListener.invoke(DispatchListener.java:171) [miriamlaurel-pms-1.0.jar:na]
at com.miriamlaurel.pms.listeners.dispatch.DispatchListener.processMessage(DispatchListener.java:111) [miriamlaurel-pms-1.0.jar:na]
at com.tsdevelopment.fmk.fix42.ExecutionReportHandler.processMessage(ExecutionReportHandler.java:36) [fi-link-fix-1.0.jar:na]
at com.miriamlaurel.pms.listeners.MessageListenerDelegate.processMessage(MessageListenerDelegate.java:40) [miriamlaurel-pms-1.0.jar:na]
at com.tsdevelopment.fmk.fix42.SessionManager.fromApp(SessionManager.java:164) [fi-link-fix-1.0.jar:na]
at quickfix.Session.fromCallback(Session.java:1361) [quickfixj-1.4.0.jar:1.4.0]
at quickfix.Session.verify(Session.java:1314) [quickfixj-1.4.0.jar:1.4.0]
at quickfix.Session.verify(Session.java:1390) [quickfixj-1.4.0.jar:1.4.0]
at quickfix.Session.next(Session.java:796) [quickfixj-1.4.0.jar:1.4.0]
at quickfix.mina.SingleThreadedEventHandlingStrategy$SessionMessageEvent.processMessage(SingleThreadedEventHandlingStrategy.java:107) [quickfixj-1.4.0.jar:1.4.0]
at quickfix.mina.SingleThreadedEventHandlingStrategy.block(SingleThreadedEventHandlingStrategy.java:70) [quickfixj-1.4.0.jar:1.4.0]
at quickfix.mina.SingleThreadedEventHandlingStrategy$1.run(SingleThreadedEventHandlingStrategy.java:87) [quickfixj-1.4.0.jar:1.4.0]
at java.lang.Thread.run(Thread.java:619) [na:1.6.0_13]
Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:137) [postgresql-8.3-603.jdbc3.jar:na]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66) [postgresql-8.3-603.jdbc3.jar:na]
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:124) [postgresql-8.3-603.jdbc3.jar:na]
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30) [postgresql-8.3-603.jdbc3.jar:na]
at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24) [postgresql-8.3-603.jdbc3.jar:na]
at org.postgresql.Driver.makeConnection(Driver.java:386) [postgresql-8.3-603.jdbc3.jar:na]
at org.postgresql.Driver.connect(Driver.java:260) [postgresql-8.3-603.jdbc3.jar:na]
at java.sql.DriverManager.getConnection(DriverManager.java:582) [na:1.6.0_13]
at java.sql.DriverManager.getConnection(DriverManager.java:154) [na:1.6.0_13]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:281) [spring-2.5.4.jar:2.5.4]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:269) [spring-2.5.4.jar:2.5.4]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:253) [spring-2.5.4.jar:2.5.4]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:234) [spring-2.5.4.jar:2.5.4]
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:82) [spring-2.5.4.jar:2.5.4]
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) [hibernate-3.3.1.GA.jar:na]
... 41 common frames omitted
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168) [na:1.6.0_13]
at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:135) [postgresql-8.3-603.jdbc3.jar:na]
at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:104) [postgresql-8.3-603.jdbc3.jar:na]
at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:73) [postgresql-8.3-603.jdbc3.jar:na]
at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:259) [postgresql-8.3-603.jdbc3.jar:na]
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:254) [postgresql-8.3-603.jdbc3.jar:na]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:95) [postgresql-8.3-603.jdbc3.jar:na]
... 55 common frames omitted

Any comments are welcomed..

Cheers!


Top
 Profile  
 
 Post subject: Re: How to close connections when using Spring managed sessions?
PostPosted: Tue Sep 01, 2009 4:45 am 
Regular
Regular

Joined: Fri May 22, 2009 4:50 am
Posts: 59
Hi everyone,

I have also tried increasing the number of open socket connections with postgres db. but that helps just to an extent and I am still stuck with above problem.
Any suggestions or comments are welcome.

Thanks.
shaguf


Top
 Profile  
 
 Post subject: Re: How to close connections when using Spring managed sessions?
PostPosted: Tue Sep 01, 2009 11:23 am 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
Hi,
I'm not sure if this helps.. We use SQLServer 2000 database, Hibernate, net.sourceforge.jtds driver AND commons-dbcp for managing the connection pool. My guess is that your problem is more with managing the connection pool. Let me know if this resolves.
so config looks something like this:-
Code:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName"><value>${hibernate.connection.driver_class}</value></property>
    <property name="url"><value>${hibernate.connection.url}</value></property>
    <property name="username"><value>${hibernate.connection.username}</value></property>
    <property name="password"><value>${hibernate.connection.password}</value></property>
    <property name="maxActive"><value>100</value></property>
    <property name="maxWait"><value>120000</value></property>
    <property name="maxIdle"><value>50</value></property>
    <!-- OTHER org.apache.commons.dbcp.BasicDataSource CONFIGURATION SETTERS CAN BE CONFIGURED HERE, SEE http://jakarta.apache.org/commons/dbcp/apidocs/org/apache/commons/dbcp/BasicDataSource.html-->
  </bean>

  <!-- BEAN DEFINITIONS BELOW THIS POINT SHOULD NOT NEED TO BE EVER MODIFIED FOR AN IMPLEMENTATION -->

  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="mappingResources">
      <list>
    <!--hibernate mapping entries -->
      </list>
    </property>

    <property name="hibernateProperties">
      <props>
        <prop key="hibernate.dialect">${hibernate.dialect}</prop>
        <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<!--
        <prop key="hibernate.format_sql">true</prop>
        <prop key="hibernate.use_sql_comments">true</prop>
-->
        <prop key="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</prop>
        <prop key="hibernate.jdbc.batch_size">0</prop>
        <prop key="hibernate.jdbc.use_streams_for_binary">true</prop>
        <prop key="hibernate.max_fetch_depth">1</prop>
        <prop key="hibernate.cache.use_query_cache">false</prop>
        <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
      </props>
    </property>
    <property name="dataSource"><ref bean="dataSource"/></property>
    <property name="entityInterceptor"><ref bean="entityInterceptor"/></property>
  </bean>
 
  <bean id="entityInterceptor" class="xx.EntityInterceptor" />

  <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource"><ref bean="dataSource"/></property>
  </bean>


-Srilatha.


Top
 Profile  
 
 Post subject: Re: How to close connections when using Spring managed sessions?
PostPosted: Tue Sep 08, 2009 8:42 am 
Regular
Regular

Joined: Fri May 22, 2009 4:50 am
Posts: 59
thanks Srilatha.
Using apache datasource, org.apache.commons.dbcp.BasicDataSource, did solved my problem indeed.

The datasource class that I was using was org.springframework.jdbc.datasource.DriverManagerDataSource. Can you kindly tell me why was it giving socket exception with this one? Is it still possible to use Spring datasource class by configuring it rightly?

My previous datasource bean:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
<property name="driverClassName"><value>${hibernate.connection.driver_class}</value></property>
<property name="url"><value>${hibernate.connection.url}</value></property>
<property name="username"><value>${hibernate.connection.username}</value></property>
<property name="password"><value>${hibernate.connection.password}</value></property>
<property name="maxActive"><value>100</value></property>
<property name="maxWait"><value>120000</value></property>
<property name="maxIdle"><value>50</value></property>
</bean>


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