File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Close idle TCP socket by system properties or JVM options Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Close idle TCP socket by system properties or JVM options" Watch "Close idle TCP socket by system properties or JVM options" New topic
Author

Close idle TCP socket by system properties or JVM options

Kevin H Lee
Greenhorn

Joined: Feb 08, 2012
Posts: 3
Hi,

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

S.L.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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
Greenhorn

Joined: Feb 08, 2012
Posts: 3
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.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.

Have you tried googling for something like os level socket timeout?
Kevin H Lee
Greenhorn

Joined: Feb 08, 2012
Posts: 3
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!
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6


They are looking for changing some Java system properties or JVM options to do this.


There aren't any, unless the provider of this code that you can't change provided some, but for that, you'd have to contact them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Close idle TCP socket by system properties or JVM options