0
如果服務器未啓動,我想向用戶顯示錯誤消息。 當用戶啓動程序時。 下面我提到了我用來連接到服務器的應用程序的我的ServerConnector單例類。handeling java RMI連接拒絕主機異常
public class ServerConnector {
private static ServerConnector serverConnector;
private RemoteFactory remoteFactory;
private ServerConnector() throws NotBoundException, MalformedURLException,
RemoteException {
remoteFactory = (RemoteFactory) Naming
.lookup("rmi://localhost:5050/RoomReservation");
}
public static ServerConnector getServerConnector()
throws NotBoundException, MalformedURLException, RemoteException {
if (serverConnector == null) {
serverConnector = new ServerConnector();
}
return serverConnector;
}
public CustomerController getCustomerController() throws RemoteException {
return remoteFactory.getCustomerController();
}
}
有沒有什麼辦法在加載程序的GUI之前檢查服務器是否啓動?
謝謝。
使用try catch塊設置標誌。並使用它來更新您的GUI以顯示錯誤消息。 – shanmuga