Using ServerSocket.accept() method we can control the number of active socket clients, i.e. set a maximum limit on concurrent active client service threads, allow all currently active clients to terminate before gracefully stopping the server etc. Is there a way to exercise similar degree of control in an RMI server?

Shaun Childers

I don't think it's possible with the RMI classes provided with the JDK (if it is, someone will correct me), but you could design your system to control this. (I'm sure we could all come up with multiple ways for solving this design issue.) The first solution off the top of my head would be the following:

* Create an RMI server manager object whose job it is to keep up with how many concurrent connections are executing on the object. This could be done in such a way: (Assume we have the RMIServerManager running and it's a Singleton (one instance) class.)

public class RmiObjectImpl extends UnicastRemoteObject implements RmiObject {
  public void someMethod(Object[] o) throws RemoteException {
    //before we execute this method check to see if it's OK
    if (serverManager.proceed()) {
        //let the server manager we have another client
        //now perform the method functionality
        //now be sure to let the server manager know this client is done and leaving
       throw new TooManyUsersException("Please wait.");


I know this is bare bones, but you get the idea, just build it into the design of your system.