首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java Rmi中的多线程

Java Rmi中的多线程
EN

Stack Overflow用户
提问于 2014-04-28 10:08:29
回答 1查看 974关注 0票数 2

我想知道如何在RMI中使用线程。例如,如何使以下Java简单代码变成多线程?

接口:

代码语言:javascript
复制
public interface NntpServerInterface extends Remote
{
    String Hello() throws  RemoteException;
}

接口实现:

代码语言:javascript
复制
public class NntpServerImpl  extends UnicastRemoteObject implements NntpServerInterface
{
  public   NntpServerImpl() throws RemoteException
  {
  }

  public String Hello()
  {
      return "Hello" ;
  }
}

以及我可以运行主服务器的地方:

代码语言:javascript
复制
public class NntpServerRun {
    static Registry reg;

    public static void main(String args []) throws RemoteException, AlreadyBoundException
    {
        reg=LocateRegistry.createRegistry(1111);
        reg.bind("NntpServer", new NntpServerImpl());
        System.out.println("Nntp Server  Started........");
    }
}

最后是客户端:

代码语言:javascript
复制
public class Client 
{
    static Registry reg;
    static NntpServerInterface ci;

    public static void main(String args )
    {
        reg=LocateRegistry.getRegistry(jTextField1.getText(), 1111);
        ci=(NntpServerInterface)(reg.lookup("NntpServer"));
        System.out.print(ci.Hello());
    }
}

是否可以将上述代码更改为多线程?我听说RMI已经多线程了。

EN

回答 1

Stack Overflow用户

发布于 2014-04-28 10:22:25

我听说RMI已经多线程了。

你是对的。不需要对此代码进行更改。一般来说,您需要确保远程对象的线程安全,但是这个特定的对象已经是线程安全的了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23338233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档