Java RMI中Remote对象、Server对象、rmiregistry及rmic含义咨询
Hey there, let's break down these core Java RMI terms clearly—they're foundational to getting how remote method invocation works:
Remote object: This is the heart of RMI's remote capabilities. It's an object that implements the
java.rmi.Remoteinterface (a marker interface that signals its methods can be called from other JVMs). Every method in this object must declarethrows RemoteExceptionto handle network/remote call errors. Clients never interact with the remote object directly; instead, they use a local stub (proxy) that forwards their method calls over the network to the actual remote object running on the server.Server object: This term is often used interchangeably with the remote object, but sometimes it refers to the concrete class instance that implements the
Remoteinterface (the actual object executing methods on the server side). In some contexts, it might also describe the server application that hosts and registers the remote object with the registry. Either way, it's the server-side component that does the heavy lifting when a client sends a remote request.rmiregistry: A lightweight JDK-provided naming service that acts like a centralized "directory" for remote objects. Servers register their remote objects with the registry using a unique logical name, and clients look up that name to retrieve the stub proxy they need to communicate with the remote object. It runs as a separate process (you start it with thermiregistrycommand) on a default port (1099), and only stores references to remote objects—not the objects themselves.rmic: Short for "RMI Compiler", this is a command-line tool included with the JDK. Its primary job is to generate stub and skeleton classes for remote objects. Stubs handle client-side communication (marshaling parameters, sending calls to the server), while skeletons handle server-side request processing (unmarshaling parameters, invoking the actual method on the remote object). While modern Java versions (Java 5+) use dynamic proxies that eliminate the need for explicit stub/skeleton generation,rmicis still useful for compatibility with older systems or when you need to generate these classes manually. You'd run it like this:rmic com.example.MyRemoteServiceImplto generate the necessary classes.
内容的提问来源于stack exchange,提问作者Xio Nipnang

