File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S:Client connection using RMI & locking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S:Client connection using RMI & locking" Watch "B&S:Client connection using RMI & locking" New topic
Author

B&S:Client connection using RMI & locking

Richard Levy
Greenhorn

Joined: Jan 19, 2005
Posts: 22
Hi all,

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.

Have I missed the point?!

Thanks
Rich
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
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
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
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.*;
Richard Levy
Greenhorn

Joined: Jan 19, 2005
Posts: 22
Hi

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.

Rich
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
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
Lucy Hummel
Ranch Hand

Joined: Apr 07, 2005
Posts: 232
Hi,

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.


----------------------------------<br />| SCJP, SCWCD, SCBCD, SCEA, SCJD |<br />----------------------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S:Client connection using RMI & locking
 
Similar Threads
re: compatibility with test harness -- lock(), unlock()
Design of lock and unlock
Networking : RMI
cann someone validate my locking approach?
Data Locking with a DB File.