After starting a JNDI provider:
start rmiregistry
I used the following test application to play with the JNDI API:
public static void main(String[] args) throws NamingException, MalformedURLException {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.rmi.registry.RegistryContextFactory");
env.put(Context.PROVIDER_URL, "rmi://localhost:1099");
InitialContext jndiContext = new InitialContext(env);
String objName = "myObj";
Reference obj = new Reference("Object");
jndiContext.bind(objName, obj);
System.out.println("Object from registry: "
+ jndiContext.lookup(objName));
jndiContext.unbind(objName);
jndiContext.close();
}
The problem is that the program never exits. The culprit is the "RMI Reaper" non-daemon thread which prevents this JNDI client application from properly shutting down.
Does anyone know how to make this program exit without using System.exit()?