• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Close idle TCP socket by system properties or JVM options

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
reply
    Bookmark Topic Watch Topic
  • New Topic