Multithreaded Server with Java RMI

Cole Crescas
2 min readJun 27, 2022

Remote procedure calls are a foundation of client server architecture and utilized across the world. Remote method invocation is a subset of RPC and well established in Java. Shown here is the overview of RMI as well as a link to Github for the code base used to create a server that stores key-value pairs in a concurrent hash-map, accessible from multiple threads and clients.

RMI image for a Hello World Client Server communication

Information from Oracle Docs about RMI:

  • Remote Method Invocation (RMI) allows us to get a reference
    to an object on a remote host and use it as if it were on our
    virtual machine. We can invoke methods on the remote
    objects, passing real objects as arguments and getting real
    objects as returned values. (Similar to Remote Procedure Call
    (RPC) in C).
  • RMI uses object serialization, dynamic class loading and
    security manager to transport Java classes safely. Thus we can
    ship both code and data around the network.
  • In addition, RMI is multithreaded already but is not thread-safe. A method dispatched by the RMI runtime to a remote object implementation may or may not execute in a separate thread. The RMI runtime makes no guarantees with respect to mapping remote object invocations to threads. Since remote method invocation on the same remote object may execute concurrently, a remote object implementation needs to make sure its implementation is…

--

--