java rmi server ExportException internal error ObjID already use


Sep 21, 2013 9:12:09 AM suncertify.main.URLyBirdMain main
INFO: Executing in server mode.
Sep 21, 2013 9:12:09 AM suncertify.server.RMIFactoryServerImpl
INFO: rmi://
java.rmi.server.ExportException: internal error: ObjID already in use
at sun.rmi.transport.ObjectTable.putTarget(
at sun.rmi.transport.Transport.exportObject(
at sun.rmi.transport.tcp.TCPTransport.exportObject(
at sun.rmi.transport.tcp.TCPEndpoint.exportObject(
at sun.rmi.transport.LiveRef.exportObject(
at sun.rmi.server.UnicastServerRef.exportObject(
at sun.rmi.registry.RegistryImpl.setup(
at sun.rmi.registry.RegistryImpl.(
at java.rmi.registry.LocateRegistry.createRegistry(
at suncertify.server.RMIFactoryServerImpl.(
at suncertify.server.RMIFactoryServerImpl.(
at suncertify.main.ServerModeMain.(
at suncertify.main.URLyBirdMain.main(

and the class:

public class RMIFactoryServerImpl extends UnicastRemoteObject implements RMIFactoryServer  {

    private static final long serialVersionUID = 2364209308189771862L;
    private static Logger logger = Logger.getLogger("ServerMain");

public RMIFactoryServerImpl() throws NumberFormatException, RemoteException, FileNotFoundException, IOException{
//TODO implement GUI for the initial parameters
//TODO, is the bellow assumption right?
//The server will run with the default parameters  
        //This starts up the registry at port 1099 on the local machine.
        java.rmi.registry.LocateRegistry.createRegistry(Integer.parseInt( Utils.readPropertiesFile("serverPort")));
        logger.fine("RMI registry created on port :" + Utils.readPropertiesFile("serverPort"));
        String name = "rmi://" + Utils.readPropertiesFile("serverAdress").trim() + ":" + Utils.readPropertiesFile("serverPort").trim() + "/URLyBirdRMIServer";;
Naming.rebind (name, new RMIFactoryServerImpl());


While trying to implement the Factory design pattern  for RMI the following line is generating the problem:

             Naming.rebind (name, new RMIFactoryServerImpl());

The error was caused by trying to rebind with a new instance of the class were it was running. It was solved by passing the class itself rather than a new instance:

       Naming.rebind (name, this);


Popular posts from this blog

Hibernate - HibernateException: createQuery is not valid without active transaction