You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by the_biswa <bi...@gmail.com> on 2011/08/01 11:19:39 UTC

servicemix can not gain db connection after a long idle time

Hi

I've noticed an interesting thing with my servicemix application
I'm using smx4
my application uses hibernate 3 for db interactions

I noticed that I deploy my sa (servicemix-assembly) and run the application
and the application is running fine. However, after a long idle time (2
days), if I put a request I see that the application is not able to connect
to the db and returns a "Connection refused" exception though the database
is up that time and I can access the db using toad etc. However, if I
redeploy the sa, the application seems to be running fine again.

Can anybody know the potential reason of this error?

I've reproduced the same scenario using the following steps:
Note: servicemix is running in my local setup. db server is in a remote m/c
1. deploy the sa in servicemix
2. test if the application is running or not (it's running now)
3. un-plug the n/w cable to make sure that the servicemix is disconnected
from db server.
4. plug the cable back in.
5. test if the application is running or not (it's not running this time and
giving "Connection refused" exception.

Below is the content of my hibernate.cfg.xml
======================================
<?xml version="1.0" encoding="UTF-8"?>
&lt;!DOCTYPE hibernate-configuration PUBLIC 
	&quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;      

&quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;
<hibernate-configuration>
	<session-factory>
		<property
name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
		<property
name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
		
		<property
name="hibernate.connection.url">jdbc:oracle:thin:@1.2.3.4:1521:DBUser</property>
		<property name="hibernate.default_schema">DBUser</property>
		<property name="hibernate.connection.username">DBUser</property>
		<property name="hibernate.connection.password">*******</property>
		<property name="connection.pool_size">10</property>
		<property name="show_sql">true</property>
		<property name="current_session_context_class">thread</property>
		
		
		<mapping class="com.abacus.amh.dbaccess.hibernate.model.AWSSession" />

</session-factory>
</hibernate-configuration>




--
View this message in context: http://servicemix.396122.n5.nabble.com/servicemix-can-not-gain-db-connection-after-a-long-idle-time-tp4654426p4654426.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: servicemix can not gain db connection after a long idle time

Posted by Christian Müller <ch...@gmail.com>.
We had a similar problem in our application. We figured out, the reason was
our firewall. It dropped the connection from our application to the database
after one hour of inactivity instead to close the connection. Therefore our
application didn't realized that the connection was dead. It run the query
to the database to check the connection when borrowing it from the
connection pool and read from the response stream. But the response stream
didn't return any data. After a long time (30 minutes or so) we received an
exception because the OS terminates the connection.

The solution for us was to run the validation query (SELECT 1 FROM DUAL)
also for idle connections in the pool (after each 5 minutes). This makes
sure the firewall doesn't drop the connections to the database. We are using
the Apache Commons database pool (commons-dbcp).

Hope this helps.

Best,
Christian