In a dialog (window) let suppose we have some buttons and when a button is pressed a remote method invocation take place.
How it is better:
-
create the remote object (registry.lookup()) one time and use this object every time we need a remote method invocation?
-
each time we need a remote method invocation we execute registry.lookup() and after this we call the remote method?
Just do your lookup once, and cache the reference to the remote object somewhere. The rmiregistry is just used for bootstrapping. Doing a lookup every time will cause lots of unnecessary network calls.
The ServiceLocator pattern talks about it: