Name: tb29552 Date: 11/09/98
/*
I reported this bug against 1.1.7 and 1.2beta4,
and it was assigned to bug 4120329 which was
supposed to be fixed in 1.2fcs. That bug did get
fixed, but the bug as I described it did not.
So here it is again...
Here's an RMI and/or garbage collection problem.
This test program program creates a registry. Then it
tries to remove it with garbage collection so it can
make another one. This exception is thrown:
java.rmi.server.ExportException: Object ID already in use
Why doesn't garbage collection take care of this?
And if it doesn't, why isn't their a method like
java.rmi.registry.LocateRegistry.removeRegistry()?
*/
/*
This problem also exists across JVMs. If program1
"creates" the registry, program2 can "get" the
registry. But if program1 disappears, program2
cannot "create" another registry. It says the object
ID is in use even though program1 that created it is
gone. Also, if program2 tries to "get" the registry
again after program1 is gone, it works with no
exception. But this is a bogus registry and it
fails when trying to use it (e.g. bind).
And yes, I really want to do this. I want to have
registries be created by whoever needs them if
their current registry goes away.
Here's the code:
*/
import java.rmi.registry.*;
class RegistryTest {
public static void main(java.lang.String[] args)
{
Registry reg = null;
try
{
System.out.println("creating registry");
reg = LocateRegistry.createRegistry(1099);
System.out.println("created registry");
}
catch(Exception e)
{
System.out.println("cannot create registry");
e.printStackTrace();
}
System.out.println("removing registry");
reg = null;
System.gc();
try
{
System.out.println("creating another registry");
reg = LocateRegistry.createRegistry(1099);
System.out.println("created another registry");
}
catch(Exception e)
{
System.out.println("cannot create another registry");
e.printStackTrace();
}
}
}
(Review ID: 42355)
======================================================================