특별한 조치를 취할 필요가 전혀없는 RMI 프레임 워크는 새로운 스레드를 자동으로 돌려줍니다. 내가 그 골격은 각 클라이언트의 작업에 대한 스레드를 실행하려는
public interface Server extends java.rmi.Remote {
void doIt() throws java.rmi.RemoteException;
}
public class ServerImpl extends java.rmi.server.UnicastRemoteObject implements Server {
public ServerImpl() throws java.rmi.RemoteException {
super();
}
public void doIt() {
System.out.println ("Starting in " + Thread.currentThread().getName());
try { Thread.sleep(10000); } catch(InterruptedException t) {}
System.out.println ("Stopping in " + Thread.currentThread().getName());
}
public static void main (String[] argv) throws Exception {
java.rmi.registry.LocateRegistry.createRegistry(1099);
java.rmi.Naming.rebind ("//localhost/Server", new ServerImpl());
}
}
public class Client {
public static void main(String[] argv) throws Exception {
((Server) java.rmi.Naming.lookup("Server")).doIt();
}
}
출처
2013-06-26 20:14:15
rxg
확실히'run()'이 아닙니다. 스레드는'Thread # start()'로 시작합니다. –
네, 혼란 스럽습니다. – giozh
좋아요, 이제 쓰레드가 시작해서 거기에서 오버라이드 한'run' 메소드 나 생성자에서 전달한'Runnable'의 쓰레드 중 하나를 실행합니다. –