I have a Java application running in WebLogic 11g on Windows, which after several days, becomes unresponsive. One suspicious symptom I\'ve noticed is that a large number of conn
I have been having the same issue and I have been studying sockets to get rid of this issue.
Let me say a few words, but before i must say I am not a Java programmer.
I will not explain what close_wait is, as Brian White already said everything that should be said.
To avoid close_wait, you need to make sure your server does not close the connection after it sends back the response because whomever disconnects first get stuck in close_wait and time_wait. So, if your server is getting stuck in close_wait it tells me that it is disconnecting after it sends the response.
You should avoid that by doing a few things.
1 - If your client application is not using the http 1.1 protocol you must set it to use that because of the 'keep-alive
http header option.
2 - If you client is running http 1.1 and that does not work, or, if you must use http 1.0, you should set the connection request header property:
connection: keep-alive
This tells the server that neither the client nor the server should disconnect after completing a request. By doing that your server will not disconnect after every request it receives.
3 - In your client, reuse your socket. If you are creating a lot of sockets clients in a loop for example, you should create a socket once and them use it every time you need to send a request. The approach I used in my app is to have a socket pool and get one socket available (which is already connected to the server and it has the keep-alive property). Then I use it and when i am done I put it back in the pool to be reusable.
4 - If you really need to disconnect after sending a request, make sure your client does that and keep the connection: keep-alive
.
And yes, you may have problems when you have a lot of close_waits or time_waits on the server side.
Check out this [link][1] which explain what keep-alive
is.
I hope this was helpful. With those things I managed to solve my problem.
[1]: http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Persistent Connections