Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S:Client connection using RMI & locking

 
Richard Levy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Arno Reper
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic