I'm going for the RMI approach with my network design.
I'm going to have a session manager, which is a single remote object that all clients will connect to and request data access. This will return a new remote adapter to the actual database. The database has a singleton for file access and locking.
This brings me on to locking. I've seen some quite complex locking mechanisms described here, but my assignment says "any attempt to lock a resource that is already locked should cause the current thread to give up the cpu....". To me this sounds like "if someone is using the record you want, wait". So my lock manager is simply tracking locked records (and associated cookies) using a hashmap and sync'd access to lock and unlock. It doesnt actually care WHO has the resource locked, only that it IS locked.
Hi, I am also doing B&S...for the lock problem, I'm thinking now how to resolve the deadlock...because like you wrote, in the Sun assignment the thread has to wait...maybe I'll let the thread wait for some time and then leave if it didn't get the lock... How 'll you do? Arno
The man who makes no mistakes does not usually make anything<br /> <br />>>> SCJP 5.0 >> SCJD B&S <<< In progress
Joined: Mar 14, 2006
I did the same as you, an hashmap<key=recno,value=cookie>... in the lock method the thread has to wait until the key is removed from the map like while(map.contains(key))wait... Arno ps: i used java.util.concurrent.*;
Joined: Jan 19, 2005
I'm doing the 1.4 assignment so no java.util.concurrent for me.
Yes, my lock mechanism has a while loop exactly like yours.
Interesting about the timeout.
I was planning to have a watchdog process running for each lock that would remove it after a reasonable amount of time (either that or a single process that checks the length of time a lock has been active - this is probably better). That way the lock mechanism doesnt have to worry about timing out as the watchdog process will release excessive locks.
Thanks for the replies.
Joined: Mar 14, 2006
Nice idea...but do you have an idea how you'll implement that watchdog? You are using 1.4...oh? I thought we had to use the latest version of J2SE. When did you start the scjd? arno
Since my assignment also claims any attempt to lock a resource that is already locked should cause the current thread to give up the cpu I have the approach having a Map<recordNumber, cookie> and a waiting look, like:
My assignment did not asked for any deadlock solution, so I do not implement a watchdog as Rich mentioned above.