调用同一个远程对象时,客户端的 Java RMI 线程是顺序执行还是并发执行?

标签 java multithreading client-server rmi client-side

我无法理解 java RMI 的特定方面。

有一个客户端创建 N 个线程来在 RMIregistry 上进行查找:

    Registry rmiRegistry;
    try {
        rmiRegistry = LocateRegistry.getRegistry(8585);
    IGestoreSportello igs = (IGestoreSportello)rmiRegistry.lookup("gestoresportelli");
    ExecutorService s = Executors.newCachedThreadPool();
    for(int i = 0; i < T; i++){
        s.execute(new threadRunner(igs));
    }

“gestoresportelli”之前已在服务器中注册为服务。

因此,据我的理解,客户端都会获得对同一对象的所有相同引用。

我在这里想问的是,当我调用这个对象的方法时,是CLIENT执行服务器的代码吗?

或者是服务器顺序调用该对象的方法?

<小时/>

假设我们有:

线程1、线程2、线程3。它们都在服务器上注册的同一个远程对象上调用相同的方法。

他们是否按顺序调用它:

Thread1->RemoteObjectReference.doSomething();
wait thread 1 to finish...
Thread2->RemoteObjectReference.doSomething();
wait thread 2 to finish...
Thread3->RemoteObjectReference.doSomething();

或同时:

Thread1->RemoteObjectReference.doSomething();
Thread2->RemoteObjectReference.doSomething();
Thread3->RemoteObjectReference.doSomething();

所有这些都是同时进行的,即使这是同一个远程对象?

我希望我说得足够清楚。谢谢!

最佳答案

What I am asking here is, when I call a method on this object, is it the CLIENT executing the server's code?

没有。

Or is it the server that sequentially calls methods on that object?

它是服务器,但未定义顺序。

Do they call it sequentially

未定义。

OR concurrently:

未定义。

更强烈地说,RMI 规范明确指出,不保证客户端线程和服务器线程之间的关联。

您可以从中推断出您不能假设它是单线程的。

关于调用同一个远程对象时,客户端的 Java RMI 线程是顺序执行还是并发执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24775931/

相关文章:

java - 为什么 java.io.File.listFiles() 抛出 NPE 而不是正确的异常?

c - 线程: Increasing program execution time with respect to number of threads

javascript - 从 PHP 或 Javascript 加载 HTML?

ruby-on-rails - 具有远程 Rails 服务器的 BackBone 客户端

c - 用于补偿 TCP 流套接字的示例 C 代码?

Java数组同步

java - 试图在另一个类的方法中调用方法

java - 匹配给定前缀和后缀的正则表达式

node.js - Node : worker disconnect() not working as expected

java - 在单例中保留对线程的引用是否安全?