Hi Mark & George,
George is quite correct - the RMI Server will generally create new threads for you, and since these threads will be running on a single instance of your code by default, you have to concern yourself with thread safety.
One thing to be aware of is that you have no way of knowing which thread will be used when you call your methods. This is explicitly stated in the RMI specifications. It is completely up to the RMI Server to decide what threads it is going to create and how it is going to use them. To give you
one example of what is possible (there are many other possibilities as well):
Client A calls method1 and completes (it happens to use thread 1)Client A calls method1 and completes (it happens to use thread 1)Client A calls method1 and completes (it happens to use thread 2)Client B calls method1 and completes (it happens to use thread 1)Client A calls method1 (it happens to use thread 1)Client B calls method1 (it happens to use thread 2) As you can see in my example: client A used different threads even for subsequent calls to the same method.
And client B could use a thread that had previously been used by client A.
And (in the last two lines) client A and B were both calling the same method simultaneously - just using different threads.
I am considering moving to RMI as I think it will make the code alot simpler and quicker.
The code
may be simpler - but if you write your socket layer correctly then it is not that much simpler. And your junior programmer has to learn about RMI - so either way there would be a learning curve for the person taking over your code.
RMI is slower than the equivelent well written Sockets based solution - the difference is negligble, but there is always overhead when you abstract a communications layer. I did once do some
testing, and measured the size of messages going via RMI versus the equivalent Sockets code, however I don't remember where I posted the results - if anyone remembers that post, perhaps they could point us to it (Phil?). From memory there were a lot of RMI messages just at startup that were not necessary for Sockets, and each individual RMI message was about 10% larger than the equivalent Socket message.
Regards, Andrew