Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 62553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:29:38+00:00 2026-05-10T18:29:38+00:00

My RMI enabled application seems to be leaking sockets. I have a Java application

  • 0

My RMI enabled application seems to be leaking sockets. I have a Java application providing a service over RMI. It is using the Java SE 1.6 RMI implementation running on Linux. The problem I am observing is that if a client obtains a reference to my Remote object, using the Registry, and then the connection is severed abruptly (power loss, cable unplugged, etc…), the server keeps the socket open. I would expect the RMI implementation to clean up after the client’s lease expires, but that is not happening. On the server, my Remote object’s unreferenced() method is called when the lease expires, but the socket remains visible in netstat in the ‘ESTABLISHED’ state indefinitely.

Since we are not able to force the clients into any specific behavior, after several days we are hitting the default limit, 1024 in our Linux distro, for open file descriptors, causing the server to become unable to open any new sockets or files. I thought about TCP keepalives, but since RMI is abstracting away the network layer, I don’t have access to the actual server socket after the connection has been established.

Is there any way to force the RMI layer to cleanup sockets tied to client connections with expired leases?

Update: The solution I used is similar to the chosen answer, but uses a different approach. I used a custom socket factory, and then wrapped the ServerSocket instance returned by createServerSocket() in a transparent wrapper that passed all methods through, except for accept(). In the accpet method, keepalives are enabled before the socket is returned.

public class KeepaliveSocketWrapper extends ServerSocket {     private ServerSocket _delegate = null;     public KeepaliveSocketWrapper(ServerSocket delegate)     {         this._delegate = delegate;     }      public Socket accept() throws IOException     {         Socket s = _delegate.accept();         s.setKeepAlive(true);         return s;     }     .     .     . } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:29:38+00:00Added an answer on May 10, 2026 at 6:29 pm
    public class MySocketFactorySettingKeepAlive ... {   // overwrite createSocket methods, call super.createSocket, add keepAlive }  Socket.setSocketImplFactory(youFactoryDemandingKeepAlive); 

    and then just use RMI.

    The trick, if I remember right, is to manage to set the factory before the system opens first socket — Java disallows to overwrite the factory; in worst case, use reflection to overwrite it :))) (kidding; would be a hack)

    Also, you may need to allow specific operation in SecurityManager.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 115k
  • Answers 115k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Something like this maybe? // custom :external selector $.expr[':'].external =… May 11, 2026 at 10:25 pm
  • Editorial Team
    Editorial Team added an answer If Jetty is not a high priority item you can… May 11, 2026 at 10:25 pm
  • Editorial Team
    Editorial Team added an answer Try this: File.listRoots(); May 11, 2026 at 10:25 pm

Related Questions

I have some code which I am making available via RMI. If my program
I need to access RMI methods from a client front end. For different reasons,
I am adapting a little rmi client-server application. I have written several things :
How can I use RMI with a applet client behind a firewall? How can

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.