Is it a Java RMI remote object (server) singleton?

I've been using Java RMI for some time, but I can't figure out whether RMI remote stubs (on the server side) is a singleton? The reason I asked is:

Suppose that one of the lower RMI implementation methods in the call chain has a synchronized method If, for some reason, the logic in the synchronization method is confused (or suspended), future RMI calls (from the client) will also be suspended when trying to access the synchronization method This is true only when the RMI stub will become a singleton If you create a new object on the server side at each remote call from the client, this will not be a problem, because calling methods from another object and synchronizing methods will no longer be a problem

cut a long story short. I try to understand how the JVM maintains RMI remote objects inside the server and whether they are singletons I tried many different Javadoc, but they didn't mention it explicitly anywhere

Any and all help is appreciated!

Based on some questions and comments, I'm refining this question: my real question is, does the server-side RMI happen to keep some kind of object pool according to the objects you export and register? You can bind multiple objects of the same type with the same name (some simulate an object pool, in which RMI can give me any object I register), or in order to have multiple instances of the same object, I will have to register them with different names

Solution

First, "stub" is a client concept. There is no stub on the server

For remote objects themselves, RMI system will not instantiate objects for you. You can create instances and export them You create an instance of an object, export the object, and bind it to the registry under a specific name All calls on client stubs obtained from the same name in the registry will eventually terminate on the same object on the server

No, you can only bind one object in the registry under the given name However, the bound object itself can be a proxy for your own object pool, for example, using the spring AOP commonspooltargetsource mechanism

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>