Reputation: 856
I have Web application in Cent Os server created in JSP. After some time the connections to mysql execeeds the limit and application could not work without restarting the mysql service.
Even I restarts the mysql and tomcat service some connections are allready created by mysql.
[root@localhost ~]# service tomcat restart
Shutting down Tomcat: Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.27 Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.27 Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.27/temp Using JRE_HOME: /usr/java/jre1.6.0_10 Using CLASSPATH: /usr/local/apache-tomcat-7.0.27/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.27/bin/tomcat-juli.jar
Starting Tomcat: Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.27 Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.27 Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.27/temp Using JRE_HOME: /usr/java/jre1.6.0_10 Using CLASSPATH: /usr/local/apache-tomcat-7.0.27/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.27/bin/tomcat-juli.jar
[root@localhost ~]#
service mysql restart
Shutting down MySQL. [ OK ]
Starting MySQL...... [ OK ]
[root@localhost ~]# netstat | grep mysql | wc -l
180
As shown above it shows 180 connections all ready running and the connections are like
[root@localhost ~]# netstat | grep mysql
tcp 1 0 localhost.localdomain:49058 localhost.localdomain:mysql CLOSE_WAIT tcp 1 0 localhost.localdomain:49061 localhost.localdomain:mysql CLOSE_WAIT tcp 1 0 localhost.localdomain:49060 localhost.localdomain:mysql CLOSE_WAIT tcp 1 0 localhost.localdomain:49063 localhost.localdomain:mysql CLOSE_WAIT tcp 1 0 localhost.localdomain:49062 localhost.localdomain:mysql CLOSE_WAIT
I have checked my sql files three times and there is no connections remained unclosed
Please give me the solution...
Upvotes: 0
Views: 1626
Reputation: 4141
CLOSE_WAIT
tcp socket state means that connection is in process if being closed, waiting for application to execute close() method. You should always execute close() method after finishing the usage of some resource (connection to database, file IO, network connections, etc).
You can check this example how to correctly handle your database connection.
Upvotes: 3