Hi I have a class that is a remote object and I implemented methods.
Then I just wanted to test it in my local. So I added a main method on it.
Then in main, I called runtUtilApp method , that just executes notepad, after some sleep I finish the working of notepad and I called stop method. After the all execution I wait program to finish execution. But it is still working and not ending.
What is the reason of this ?
I am thinking wrong ?
import java.io.IOException;
import java.rmi.RemoteException;
import java.rmi.server.*;
public class ClientImp extends UnicastRemoteObject implements Remote{
private static final long serialVersionUID = 227L;
private Process proc;
/**
* constructor
*/
public ClientImp() throws RemoteException {
super();
}
public boolean runApp() throws RemoteException {
try {
Runtime rt = Runtime.getRuntime();
proc = rt.exec("notepad");
return true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
public boolean stopCurrentUtilApp() throws RemoteException {
proc.destroy();
return true;
}
public static void main(String[] args) {
client;
try {
ClientImp client = new ClientImp();
client.runUtilApp();
Thread.sleep(10000);
client.stopCurrentUtilApp();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Because your class extends
UnicastRemoteObject, which means that when you create a new instance of your class, theUnicastRemoteObjectconstructor is called, which exports this object as an RMI server object, which cause a non-daemon RMI thread to start.Call
System.exit()to exit from the JVM.