Search code examples
javamultithreadingrmi

java RMI threading system


Assuming a simple java RMI system(Hello World), my question is, if I run 10 threads in client side to call the remote(server) object for something, does the target server will create 10 threads too? or they will be proceed through a queue or something?
The problem: there might be some concurrent call to remote object that it's possible one of them needs a notable time to process, so now should I take care about threading at server side or maybe there are some implementations available for this case.
Thanks in advance.


Solution

  • It isn't specified. All that the RMI Specification says is that there is no guaranteed association between client threads and server threads.

    The occult meaning of this is that you can't assume it is single threaded.

    How specific implementations behave is up to them. For example, Oracle's RMI/JRMP uses a new thread per accepted connection, no queuing, but this is alleviated by connection-pooling at the client. Last time I looked, IBM's used a thread pool, which implies a queue. There are other implementations.

    In general the answer to your last question is that you don't have to do anything except ensure minimal but adequate synchronization.

    EDIT Some comments on the links in @CyberneticTwerkGuruOrc's deleted answer, which refer to an obscure and obsolete framework built over RMI dated 2002:

    1. He keeps saying 'autonomous' where he means 'asynchronous'.
    2. He is wrong in saying that a connection thread 'hangs forever' if the client 'goes home'.
    3. You would need an amazing number of clients competing for a resource for one of them to 'go home' because of the waiting.
    4. You can already get a client-side timeout in RMI via a system property.
    5. Using Object.wait() and a notifying thread to implement a timeout is crude in the extreme.
    6. Clients should not in general be able to shutdown the server. The server should shut itself down in its own sweet time. The inclusion of a shutdown() method in the remote interface is a prima facie security breach.
    7. He misuses the term 'persistent'. A persistent server survives restarts, like an Activatable for example.
    8. The term 'thread memory' does not appear in Chapter 17 of the Java Language Specification. He is conflating the formal memory model with what actually happens at runtime.