Hi Ricardo,
I assume you are using RMI (since if you were using sockets, you would be creating the threads yourself, and this issue wouldn't even arise).
However you
cannot use the thread number within RMI as a client identifier. According to the Sun
RMI Specification:
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 thread-safe.
The behaviour you described is allowable under the specification, even if each of your clients was working on a separate computer (so 3 computers / 3 JVMs).
It is also quite possible that with
only one client connected, it's call to lock() could be handled by one thread, it's call to update() could be handled by a different thread, and it's call to unlock() could be handled by a third thread!
This is why we generally recommend using a connection factory on your server
if you want to handle client death scenarios. It is one of the simpler ways to handle this.
Regards, Andrew