Tuesday, February 23, 2010

Facebook JAVA API

A Facebook API client implemented in Java, originally derived from the official Facebook client. Check it out here.

Friday, February 12, 2010

MySQL cries Time Out !!!

Problem: MySQL after being idle for some time like 180 seconds, experiences " Time Out" - Communications Link Failure, closes the connection and shuts itself off- No Entry !!

12:56:20,561 ERROR SchemaUpdate:188 - could not complete schema update com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Caused by: java.net.ConnectException: Connection timed out  at java.net.PlainSocketImpl.socketConnect(Native Method)  at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)  at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)  at java.net.Socket.connect(Socket.java:525)  at java.net.Socket.connect(Socket.java:475)  at java.net.Socket.(Socket.java:372)  at java.net.Socket.(Socket.java:215)  at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)  at com.mysql.jdbc.MysqlIO.(MysqlIO.java:280)  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2026)  ... 48 more

And these are the settings on the MySQL :
[root@db ~]# grep time /etc/my.cnf interactive_timeout=180 wait_timeout=180

meaning...The MySQL server will close connections that aren't doing anything after 180 seconds (3 minutes) 

So now the solution lies in importing the c3p0.jar and  programmatic-ally configuring the hibernate configuration file- as follows:

<property name="hibernate.connection.provider_class"> org.hibernate.connection.C3P0ConnectionProvider </property>

<property name="hibernate.c3p0.min_size">5</property>

<property name="hibernate.c3p0.max_size">30</property>

<property name="hibernate.c3p0.timeout">5000</property>

<property name="hibernate.c3p0.max_statements">100</property>

<property name="hibernate.c3p0.acquire_increment">5</property>

<property name="hibernate.c3p0.idle_test_period">100</property>

<property name="hibernate.c3p0.preferredTestQuery">SELECT 1</property>