0

You can create a registry at a given port as follows.

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
...
Registry reg;
...
reg = LocateRegistry.getRegistry(port);

That's fine. But how do I change the port number of the Registry (reg) when needed, after initializing it for the first time?.

I've tried to recreate, reg = LocateRegistry.getRegistry(port), but that gives some exceptions..

Roman C
  • 49,761
  • 33
  • 66
  • 176
Anubis
  • 6,995
  • 14
  • 56
  • 87

2 Answers2

0

If this port is already in use by rmi you can't close it:

It is a known limitation of the current RMI implementation that it never closes server (passive/listening) TCP port bindings for the lifetime of a virtual machine.> Blockquote

source: http://bugs.sun.com/view_bug.do?bug_id=4508962

Maybe this can help you:

But please post exception.

Community
  • 1
  • 1
ollo
  • 24,797
  • 14
  • 106
  • 155
  • Oh please. Read your source again. It *was* a known limitation, *in 2001.* That bug was fixed nearly ten years ago. – user207421 Jan 10 '13 at 20:14
0

You can create a Registry at a given port as follows

No you can't. That code just constructs a stub referencing a Registry at that port, which may not even be running. The way to do what you said is with LocateRegistry.createRegistry().

How do I change the port number of the Registry

Unexport the object returned by createRegistry() and call createRegistry() with a different port number.

Why you would want to do such a strange thing is another matter. What's the purpose?

I've tried to recreate

No you haven't, see above. All that does is create a stub pointing to another port. It doesn't create a Registry. If there isn't a Registry running on that port the stub will fail when used.

user207421
  • 305,947
  • 44
  • 307
  • 483