I use the framework is struts2+hibernate3+spring, the project's background database is MySQL, recently moved to the official server, in the state of service has been open, there is a java.net.SocketException:Software Causedconnection Abort:socket Write Error this exception. Each day after the restart can be normal access, the evening after no one visited, the next morning visit to report this error.
Google on the Internet a bit, all say because the MySQL server default "Wait_timeout" is 8 hours, that is, a connection idle if more than 8 hours, MySQL will automatically disconnect the connection. This is where the problem arises.
There are several ways to solve the problem online:
The first: Add a time-out limit to the My.ini file found in the MySQL installation directory: Add a line at the end of the file: wait_timeout=2880000. This extends the previous timeout limit by 8 hours (28800) to 20 days (20*24*60*60=1728000). After restarting MySQL, enter the command:show global variables like "Wait_timeout" , and see if the timeout has been modified to: 1728000. In practice, I modified the My.ini in the C:\WINDOWS directory, which is the description file used by my MySQL database, and in the [mysqld] section of the file, added wait_timeout=1728000 . After restarting MySQL, execute the query above and return the following query results:
Mysql> Show global variables like "wait_timeout"; +---------------+-------------+| variable_name | Value |+---------------+-------------+| wait_timeout in Set (0.00 sec)
Finally, restart the Tomcat,ok, the server can be accessed normally.
The second, controlled by C3P0 's idleconnectiontestperiod: You can set its value to be smaller than the default MySQL wait_timeout.
<property name= "Idleconnectiontestperiod" value= "18000"/>
Use connection pooling to solve this problem, use C3P0 here:
Modify the Hibernate.cfg.xml file
<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>
Java.net.SocketException:Software caused connection Abort:socket write error