If u started the rmiregistry from the command prompt, i.e. DOS>start rmiregistry 1099
, just terminate the command prompt (i.e. press 'X' or press 'CTRL-C') could terminate the rmiregistry.
Or, write a tiny program to terminate it:
int PORT = 1099;
UnicastRemoteObject.unexportObject(LocateRegistry.getRegistry(PORT), true);
from the 1.5 API spec [ http://java.sun.com/j2se/1.5.0/docs/api/java/rmi/server/UnicastRemoteObject.html ]:
public static boolean unexportObject(Remote obj, boolean force) throws NoSuchObjectException
Removes the remote object, obj, from the RMI runtime. If successful, the object can no longer accept incoming RMI calls. If the force parameter is true, the object is forcibly unexported even if there are pending calls to the remote object or the remote object still has calls in progress. If the force parameter is false, the object is only unexported if there are no pending or in progress calls to the object.
Parameters:
obj - the remote object to be unexported
force - if true, unexports the object even if there are pending or in-progress calls; if false, only unexports the object if there are no pending or in-progress calls
Returns:
true if operation is successful, false otherwise
Throws:
NoSuchObjectException - if the remote object is not currently exported
Since:
1.2
> If u started the rmiregistry from the command prompt,
> i.e. DOS>start rmiregistry 1099
, just
> terminate the command prompt (i.e. press 'X' or press
> 'CTRL-C') could terminate the rmiregistry.
Obviously that won't have any effect on the started registry which is in a separate process. What you can do is CTRL/C the window containing the registry.
> Or, write a tiny program to terminate it:
> > int PORT = 1099;
> UnicastRemoteObject.unexportObject(LocateRegistry.getR
> egistry(PORT), true);
That won't work either. Obviously you haven't tried it.
Stopping a command window doesn't stop a process which has been started from it. Please explain how you tested this.
And please explain this exception generated by your sample program. (Registry is running.)
Exception in thread "main" java.rmi.NoSuchObjectException: object not exported
at sun.rmi.transport.ObjectTable.unexportObject(ObjectTable.java:136)
at java.rmi.server.UnicastRemoteObject.unexportObject(UnicastRemoteObject.java:280)
at UnexportRegistry.main(UnexportRegistry.java:26)
Please explain how you tested this too.
What you can do is unexport the Registry if it is
returned by LocateRegistry.createRegistry() and if you
haven't turned it into a stub somehow (the return value is
the actual remote object). You can't unexport a stub,
and that's what LocateRegistry.getRegistry() gives you.
ejb,
Your suggestion and discussion is good.
No matter the rmiregistry is started by command prompt as PROMPT>rmiregistry 1099
or PROMPT>start rmiregistry 1099
, I think the most important part is to locate which window contains the running process of rmiregistry. The former will use the current command prompt window to launch the process, and the latter will launch a new command prompt window to run the command process.
So, focus to the correct command prompt window (which contains the running rmiregistry process) and then press CTRL-C would terminate it.
Another striaghtforward way is to launch the Window Task Manager (CTRL-SHIFT-ESC) to kill the process "rmiregistry.exe".
The alternative way provided is to use for terminating any rmiregistry created at runtime.