RMI Server 的哪一部分用多线程实现

Which Part of the RMI Server be implemented with multithreading

我最近才开始进行 RMI 编程,并且已经完成了作业要求的大部分部分。但是我脑子里有一个问题,其中一个要求是支持多线程。多线程基本上应该在哪个部分实现? 我应该使服务器 class 可运行还是使在服务器 class 中创建的对象可运行? 这是我的服务器代码 class:

public class Server {

public static void main(String args[]) {
    String portNum = "4444";
    try {
        Account_Server_Controller accountController = new Account_Server_Controller();

        BookCategory_Server_Controller categoryController = new BookCategory_Server_Controller();

        Book_Server_Controller bookController = new Book_Server_Controller();

        BookActivity_Server_Controller bookActivityController = new BookActivity_Server_Controller();

        startRegistry(Integer.parseInt(portNum));
        Naming.rebind(ServerLocater.getAccountRegistryURL(), accountController);
        Naming.rebind(ServerLocater.getBookRegistryURL(), bookController);
        Naming.rebind(ServerLocater.getCategoryRegistryURL(), categoryController);
        Naming.rebind(ServerLocater.getBookActivityRegistryURL(), bookActivityController);
        System.out.println("Server is Ready.");
    } catch (NumberFormatException | MalformedURLException | RemoteException e) {
        System.out.println("Exception in Server.main: " + e);
    }
}

private static void startRegistry(int rmiPortNum) throws RemoteException {
    try {
        Registry registry = LocateRegistry.getRegistry(rmiPortNum);
        registry.list();
    } catch (RemoteException ex) {
        System.out.println("RMI registry is not located at port " + rmiPortNum);
        Registry registry = LocateRegistry.createRegistry(rmiPortNum);
        System.out.println("RMI registry created at port " + rmiPortNum);
    }
}

}

没有。您不必启动任何线程或实施任何 Runnables.

您只需确保您的远程方法实现是线程安全的。