Lesson 24Remote Method Invocation
So far most of the Java programs in this tutorial have been running in a single Java virtual machine (JVM). There were two exceptions: In Lesson 16 in the section on “Socket Programming” you used two JVMs, and your JDBC programs from Chapter 21 communicated with another JVM running a database server. The application running on the user’s computer isn’t always allowed to access remote data directly—that’s one of the reasons distributed Java applications came into the picture. (The word distributed means having parts of the applications running on several computers.) The other reason was to provide a centralized server catering to multiple lightweight clients.
There are lots of ways to create Java distributed applications that run on more than one JVM, and Remote Method Invocation (RMI) is one of them even though it’s seldom used these days. For example, a client Java application (JVM1) connects to a server Java application (JVM2), which connects to the DBMS that runs on a third computer. The client application knows nothing about the DBMS; it gets the data, an ArrayList
(or other data collection) of Employee
objects, from the server’s application that runs in JVM2. RMI uses object serialization for the data exchange between JVM1 and JVM2.
But unlike with socket programming, where the client simply connects to a port on the server, with RMI one Java class can invoke methods on Java objects that live in another (remote) JVM. Although from a syntax ...
Get Java Programming 24-Hour Trainer, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.