Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remotely shutdown a Java RMI Server
    text
    copied!<p>I have a very simple Java RMI Server that looks like the following:</p> <pre><code> import java.rmi.*; import java.rmi.server.*; public class CalculatorImpl extends UnicastRemoteObject implements Calculator { private String mServerName; public CalculatorImpl(String serverName) throws RemoteException { super(); mServerName = serverName; } public int calculate(int op1, int op2) throws RemoteException { return op1 + op2; } public void exit() throws RemoteException { try{ Naming.unbind(mServerName); System.out.println("CalculatorServer exiting."); } catch(Exception e){} System.exit(1); } public static void main(String args[]) throws Exception { System.out.println("Initializing CalculatorServer."); String serverObjName = "rmi://localhost/Calculator"; Calculator calc = new CalculatorImpl(serverObjName); Naming.rebind(serverObjName, calc); System.out.println("CalculatorServer running."); } } </code></pre> <p>When I call the exit method, System.exit(1) throws the following exception:</p> <pre><code>CalculatorServer exiting. java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is: java.io.EOFException at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:203) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126) at CalculatorImpl_Stub.exit(Unknown Source) at CalculatorClient.&lt;init&gt;(CalculatorClient.java:17) at CalculatorClient.main(CalculatorClient.java:29) Caused by: java.io.EOFException at java.io.DataInputStream.readByte(DataInputStream.java:243) at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:189) ... 4 more [2]+ Exit 1 java CalculatorImpl </code></pre> <p>What am I doing wrong in this method?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload