Java RMI not closing socket after lease expiration

后端 未结 1 1807
后悔当初
后悔当初 2021-01-25 15:29

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

相关标签:
1条回答
  • 2021-01-25 15:29
    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 讨论(0)
提交回复
热议问题