Java RMI - 理解 Oracle 教程 [英] Java RMI - Understanding the Oracle Tutorial
问题描述
我正在尝试了解 Oracle 的 Java 的 RMI 教程,但我有一些问题.作为参考,教程链接如下:
I am trying to understand Oracle's RMI Tutorial for java and I had some questions. For reference the tutorial is linked here:
- 服务器代码:http://docs.oracle.com/javase/tutorial/rmi/implementing.html
- 客户端代码:http://docs.oracle.com/javase/tutorial/rmi/client.html
1) 在服务器示例中,主函数的最后一行是:System.out.println("ComputeEngine bound");
.正常执行会说此时main函数退出,程序终止.但是,某些原因导致程序阻塞.有谁知道为什么在您运行服务器时程序会阻塞(而不是在打印计算引擎绑定后退出)?
1) In the server example, the last line of the main function is: System.out.println("ComputeEngine bound");
. Normal execution would say that at this point, the main function exits and the program terminates. However, something is causing the program to block. Does anyone know why the program blocks (rather than exiting after printing compute engine bound) when you run the server?
2) 关于上一个问题,服务器似乎正在阻塞和侦听某个端口.它在侦听哪个端口?RMIRegistry 如何知道服务器正在侦听哪个端口?
2) In relation to the previous question, it would seem the server is blocking and listening on a port. What port is it listening on? How does the RMIRegistry know what port the server is listening on?
3) 我的另一个问题是当客户端从 RMIRegistry 获取存根(使用 registry.lookup
)然后在这个存根上调用 executeTask
时,计算是否发生在运行 RMIRegistry 的机器上,还是在运行服务器代码的机器上?即存根是否告诉 RMIRegistry 在注册表中或服务器的 main
函数中的 computeEngine
实例上运行 executeTask
?
3) My other question is when the client gets the stub from the RMIRegistry (using registry.lookup
) and then calls executeTask
on this stub, does the computation happen on the machine running the RMIRegistry, or the machine running the server code? i.e. does the stub tell the RMIRegistry to run executeTask
on a computeEngine
instance living in the registry or within the server's main
function?
推荐答案
RMI 创建后台监听线程.直到这些线程死亡,程序才会终止.
RMI creates background listening threads. The program will not terminate until those threads die.
它指定 0 作为端口,这意味着它使用操作系统为其定义范围的随机端口.
It specifies 0 as the port, which means it uses a random port which the OS defines the range for.
存根封装了一个 TCP/IP 调用以通知服务器调用该方法.这样实际的实现就在托管代码的服务器上运行.如果您在服务器代码上放置一个 println ,您会在调用该函数时看到它打印出来.
The stub encapsulates a TCP/IP call to notify the server to call that method. So that actual implementation runs on the server hosting the code. If you put a println on the server code you will see it print out when that function is called.
这篇关于Java RMI - 理解 Oracle 教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!