简体   繁体   English

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

[英]Java RMI threads on client-side are executing sequentially or concurrently when calling the same remote object?

I am having trouble understanding a specific aspect of java RMI. 我在理解Java RMI的特定方面时遇到麻烦。

There's a client that creates N threads that do a lookup on the RMIregistry: 有一个客户端创建了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));
    }

Where "gestoresportelli" was previously registered as a service in the Server. 先前在服务器中将“ gestoresportelli”注册为服务的位置。

So, as far as my understanding goes, the clients are given all the same reference to the SAME object. 因此,据我所知,客户端对SAME对象的引用都相同。

What I am asking here is, when I call a method on this object, is it the CLIENT executing the server's code? 我要问的是,当我在此对象上调用方法时,是CLIENT执行服务器代码吗?

Or is it the server that sequentially calls methods on that object? 还是服务器依次调用该对象上的方法?


So supposing we have: 因此,假设我们有:

thread1, thread2, thread3. 线程1,线程2,线程3。 They all call the same method on the same remote object which was registered on the server. 它们都在服务器上注册的同一远程对象上调用相同的方法。

Do they call it sequentially: 他们是否按顺序调用它:

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

OR concurrently: 或同时:

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

all at the same time, even tho that's the same remote object? 都在同一时间,即使是同一远程对象?

I hope I was clear enough. 我希望我足够清楚。 Thanks! 谢谢!

What I am asking here is, when I call a method on this object, is it the CLIENT executing the server's code? 我要问的是,当我在此对象上调用方法时,是CLIENT执行服务器代码吗?

No. 没有。

Or is it the server that sequentially calls methods on that object? 还是服务器依次调用该对象上的方法?

It is the server, but sequentiality isn't defined. 它是服务器,但是顺序没有定义。

Do they call it sequentially 他们会顺序调用吗

It isn't defined. 没有定义。

OR concurrently: 或同时:

It isn't defined. 没有定义。

To put that more strongly, the RMI specification states specifically that there are no guarantees about associations between client threads and server threads. 更明确地说,RMI规范特别声明不保证有关客户端线程和服务器线程之间的关联。

All you can deduce from that is that you cannot assume it is single-threaded. 您可以从中得出的所有结论是,您不能假定它是单线程的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导出客户端对象时出现“java.rmi.ConnectException:Connection拒绝托管” - “java.rmi.ConnectException: Connection refused to host” when exporting an object client-side Java RMI:用于不传递对象,仅将其方法公开给客户端实例的体系结构 - Java RMI: Architecture for NOT passing an object, just exposing its methods to a client-side instance ThreadPoolExecutorService顺序执行线程而不是并发执行吗? - ThreadPoolExecutorService executing threads sequentially instead of concurrently? 知道客户端何时调用远程对象RMI - Know when a client called a remote object RMI Java RMI客户端 - Java RMI client side 具有客户端异常的简单RMI应用程序 - Simple RMI application with client-side exception 并发运行时,多个Java线程访问同一数据库记录 - Multiple Java Threads access the same DB record when run concurrently 在 Java RMI 中的远程客户端上进行远程查找 - remote lookup on a remote client in Java RMI Java RMI-服务器自动调用远程方法 - java RMI - server automatically calling remote methods 当 JSON 对象通过 Java Socket 解析为字符串时,从客户端读取时将附加符号添加到开头 - When JSON object parse via Java Socket as a string additional symbols are added to the beginning when reading from client-side
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM