============服务器接口:Server.java ================
import java.rmi.*; public interface Server extends Remote { void register (Client cl) throws RemoteException; void broadcastCord () throws RemoteException; } =============Server Class:ServerImpl.java=============== import java.rmi.*; import java.rmi.server.*; import java.util.*; import java.net.*; public class ServerImpl extends UnicastRemoteObject implements Server { public ServerImpl() throws RemoteException { } public synchronized void register (Client cl) throws RemoteException { System.out.println("===>register Method of Process:"); cl.receiveInq(); } //=========Broadcast Inquiry================== public synchronized void broadcastCord () throws RemoteException { System.out.println("===>broadcastCord Method of Process:"); } //==============Main Function=================== public static void main (String[] args) { try { System.out.println(InetAddress.getLocalHost().toString()); Naming.rebind("Server", new ServerImpl()); } catch(Exception e) { System.err.println("Problem..."+e) ; } } } ============Client InterfaceClient.java:============= import java.rmi.*; public interface Client extends Remote { void receiveInq() throws RemoteException; void receiveGrt() throws RemoteException; } ==============Client Class:ClientImpl.java============== import java.rmi.*; import java.rmi.registry.*; import java.rmi.server.*; import java.net.*; import java.util.*; import javax.swing.*; import java.awt.event.*; import java.net.*; import java.io.*; import java.awt.*; import javax.swing.*; public class ClientImpl extends java.rmi.server.UnicastRemoteObject implements Client { private Server mycs; public ClientImpl(Server cs) throws RemoteException { mycs=cs; mycs.register(this); } //=====Greater List======== public synchronized void receiveGrt() throws RemoteException { System.out.println("===>recieveGRT Method of Process:"); } //=====RECIEVE INQUIRY======== public synchronized void receiveInq () throws RemoteException { System.out.println("===>receiveInq Method of Process:"); mycs.broadcastCord(); } public static void main(String args[]) { String url = "rmi://localhost:1099/Server"; try{ Server cs= (Server) Naming.lookup(url); new ClientImpl(cs); } catch(Exception e) { System.err.println("Problem..\n"+e) ; } } }
它不会完全执行.......如果我们关闭客户端程序执行 完成....但我不知道为什么它没有正确执行....它不会抛出任何 例外
答案 0 :(得分:1)
删除'synchronized'。你陷入僵局。 RMI回调在与原始调用不同的线程上执行。