Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't start RMI server after stopping it

Tags:

java

rmi

I'm having a problem restarting my RMI registry after it has been stopped:

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.UnicastRemoteObject;
import javax.swing.JOptionPane;

public class CinemaServer
{
    private Registry registry;
    ClientImpl clientImple; //remote interface implemented class
    private static String title="Cinema Pvt Ltd";

    public CinemaServer() {
        try {
            clientImple = new ClientImpl();
            registry=LocateRegistry.createRegistry(3311);
            registry.rebind("RMI_INSTANCE", clientImple);
    } catch (RemoteException e) {
            JOptionPane.showMessageDialog(null, "Can't Start RMI Server",title,JOptionPane.ERROR_MESSAGE);
        }
    }

    public void stopServer()
    {
        try {
            registry.unbind("RMI_INSTANCE");
            UnicastRemoteObject.unexportObject(clientImple, true);
        } catch (NotBoundException e) {
            JOptionPane.showMessageDialog(null, "Can't Stop Server",title,JOptionPane.ERROR_MESSAGE);
        }
    }
}
  1. I start the server with: CinemaServer ser=new CinemaServer();

  2. And when I call ser.stopServer(); it stops.

  3. But I cannot restart it

I'm getting:

java.rmi.server.ExportException: internal error: ObjID already in use
at sun.rmi.transport.ObjectTable.putTarget(Unknown Source)
at sun.rmi.transport.Transport.exportObject(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.exportObject(Unknown Source)
at sun.rmi.transport.tcp.TCPEndpoint.exportObject(Unknown Source)
at sun.rmi.transport.LiveRef.exportObject(Unknown Source)
...
like image 770
sAaNu Avatar asked Jun 13 '11 14:06

sAaNu


People also ask

How do I stop RMI?

Softly typing keys prevents you from placing so much pressure on your hands and fingers which can, in turn, hurt your wrist and arm. Don't bend your wrists when typing. Keep your feet flat on the floor to improve posture. Sit up in your seat and make sure your chair supports your spine.

Are RMI server is responsible for?

RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing in one system (JVM) to access/invoke an object running on another JVM. RMI is used to build distributed applications; it provides remote communication between Java programs. It is provided in the package java.


1 Answers

the call is failing on createRegistry(), not on re-exporting your object. don't create the registry twice.

like image 119
jtahlborn Avatar answered Sep 19 '22 17:09

jtahlborn