This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Not sure if we have some system properties or JVM option to automatically shutdown IDLE/CLOSE_WAIT SOCKET. The problem is that the Java application open socket, but do not perform a close() function, instead leave it to garbage collection.
So I am wondering if there is any way to shutdown this CLOSE_WAIT socket without changing the code. Thanks
If you're using 1.6 or earlier, it is your responsibility to explicitly close each socket after you're done using it. This is not at all hard to do, and if you don't do it, it's a bug in your code.
If you're using Java 7 or later, there's a "with resources" construct that lets you specify things for which the compiler will insert close() calls for you.
Kevin H Lee
Joined: Feb 08, 2012
Thanks for the reply. The code was not done by me. I just took over somebody else's code and it is in production right now. I know where to change the code to close socket. However, they don't want to change code, they want to try some configuration or properties setting to do this. I tried google and other resources and cannot find any way to do this without changing code. That's why I am asking help here. Even I doubt that there is a way to do that since it is plain socket.
There might be an OS configuration you could fiddle with for shutting down idle sockets after some timeout, but I don't know, and that would be a question about your OS, not Java, so this site would not be the most effective place to get an answer.
It is Java related. They are looking for changing some Java system properties or JVM options to do this. I have tried 2 days and no luck. Maybe I just tell them the only way is changing the code. Thanks for your help!