In my design a client can book tickets on one or more flight simultaneously by using multiple threads.
One RemoteData ( also implements the Unreferenced) object is associated with every client. The problem comes when a client tries to book 2 or more tickets ON THE SAME FLIGHT (using two different threads) at the same time and if the client crashes after first locking of the record. (here both threads will try to lock the same record). The unreferenced() method of the RemoteData get invoked at the right time.. and clears the stale lock... Now the problem is here, The second thread which was waiting for the same lock gets the lock :-( .. and since the client has already died and the client's unreferenced method has been invoked no one is going to unlock this staled lock...
I have just not been able find out the right solution... I think I�ll have change my booking design to restrict the client to book for only on flight at one time... otherwise any other solution will only probably increase the complexity of the design..
But why is the RemoteData object still alive after the unreferenced method and process the second request to lock the record ??
Now the problem is here, The second thread which was waiting for the same lock gets the lock
i don�t see very clear were comes that second thread from and how it can be 15 minutes waiting to adquire the lock, anyway it's clear in the asignment that if a client tries to lock a record already locked by him, the response should be 'do nothing', so that second request should not entry in wait state, but yes discarded. also, the dgc will work if you implement or not the unreferenced interface, but if you implement it, you have a chance to perform operations just when the dgc marks the remote object as candidate to be collected, so in the unreferenced method you should clean resources from that remote object in the server (remaining locks, etc) if you are creating in the server a new Thread for each order request ( i hope not!), it should be one of the resources to clean in unreferenced() different thoughtson what you are tlaking about, hope some of them are usefull for you.
I'm also thinking of removing the multi-threading booking system.. but Jaun, I couldn't find anything like this in my assignment, am I missing something ??
if a client tries to lock a record already locked by him, the response should be 'do nothing'
--- :here the dgc's lease value is 1 min.: What i was trying to do in a test case was to create an instance of ClientData (i called it the connection object).. then using this connection object I tried to book 2 tickets on a same flight by using two different thread.. both threads were started simeltaneously but only one thread can get the required lock at one time (and it should be).. so other was kept waiting... after this moment i Killed my client... Now my client has died... DGC worked at the server end... and cleared the staled lock... Everything was fine at that moment.. But once the DGC cleared the lock, the second thread (which was waiting to lock the recod at the server) got the lock.. ??? The problem is here, since the client has been died but the old request at the server to lock the record was still alive... and the request was completed successfully..( really strange ) But the record locked by the second request won't be getting unlocked.. because no one was there to remove the lock (neither the client is alive nor the DGC was capable of doing anything, I think the unreferenced() mthod for an object can only be invoked once by the DGC). with regards Manish
Joined: Jun 20, 2001
my apologies, Manish. the assignment just says
If an attempt is made to unlock a record that has not been locked by this connection, then no action is be taken.
so that is not part of the requeriments, but yes part of a 'logical' behaviour of a client(that's actually part of your problem). sorry also note your test case is not right as you are not simulating different clients asking for seats but yes an only multithreaded client take a look at this thread. Eugene exposes clear enough the right context to simulate http://www.coderanch.com/t/182181/java-developer-SCJD/certification/Remote-testing [ October 16, 2002: Message edited by: Jaun Katabasis ]