java.net.SocketException: Software caused connection abort: socket write error
tomcat服务器隔一段时间不访问,就会与MySQL数据库断开连接,并报错:
DONE!
java.net.SocketException: Software caused connection abort: socket write error
原因是MySQL的连接超时时间是8小时。若空闲超过8小时,MySQL就会自动断开连接。
使用连接池可以解决这个问题,这里使用c3p0:
修改hibernate.cfg.xml文件
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">8</property>
<property name="hibernate.c3p0.max_size">200</property>
<property name="hibernate.c3p0.timeout">600</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.idle_test_period">60</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property>
<property name="hibernate.c3p0.max_size">200</property>
<property name="hibernate.c3p0.timeout">600</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.idle_test_period">60</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property>
DONE!