This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
this is not supposed to be a discussion on what to do with client crashes. I have implemented a LockManager and in it i remove dead clients on certain occassions. Her is a piece of my code that shows how i do this :
I use eclipse to build debug etc. When i start multiple clients and kil one they have the same Thread, which means the thread is still alive. So i cannot test the removal of dead clients. Can someone help me with this one?!!
hi Ricardo: You need to start each client in different VM. For example, from the command prompet you can launch the server. Then, open a new command prompet window for each client, launch the client then test. I used this technique to test my server and locking.
SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Joined: Mar 29, 2004
Does anyone know hot to accomplish this in Eclipse? I tried to start Eclipse two times, this isnn't possible. Or else how can i debug when i start the application from the command line?
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.