When does RMI make TCP connections?

醉酒当歌 提交于 2019-12-06 05:37:00

问题


I have a test program T which:

  • Acquires a stub for a Remote object O from an RMI registry on server S
  • In hundreds of parallel threads, invokes methods on this object O.

I can see that server S has many "RMI TCP Connection" threads. I had expected there to be only one, since there is only one stub of O on T. How does this work?


回答1:


RMI needs a connection per end-point per thread. It pools them at the client end, which in turn causes pooling at the server end as well, so it isn't actually as bad as that, but if you have 1000 threads performing RMI calls at the same instant there will certainly be 1000 connections. They are not multiplexed.




回答2:


RMI is supposed to try-to reuse server sockets and client sockets if possible.

Your case happens when the server socket factories are not equivalent (when equals is performed, the result is false and the connection is established again). Perhaps the stub haven't implemented hashCode and equals, so there's no certain way to know if the socket is available to be used.



来源:https://stackoverflow.com/questions/11416710/when-does-rmi-make-tcp-connections

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!