Server Implementation
Listing 10.5
MultiThreadImpl (Complete server code)
import java.rmi.*;
import java.rmi.server.*;
//server implementation
public class MultiThreadImpl extends
UnicastRemoteObject
implements MultiThreadInterface{
//constructor
public MultiThreadImpl()
throws RemoteException{
System.out.println("Creating server object");
}
//remote method implementation
public String dangerousLoop()
throws RemoteException{
//waste some time
for(int i=0;i<5000;i++){
System.out.println("value of i= " +i);
}
return "Dangerous loop";
}
//main method
public static void main(String args[]){
try{
//remote object
MultiThreadImpl obj = new MultiThreadImpl();
//bind the specified name to a new remote object.
Naming.rebind("Server",obj);
}catch(Exception ex){
System.out.println(ex.getMessage());
}
}
}
|