GeeCON Prague 2014*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Gettting read or write tokens in LockManager - any savings ? 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 "Gettting read or write tokens in LockManager - any savings ?" Watch "Gettting read or write tokens in LockManager - any savings ?" New topic
Author

Gettting read or write tokens in LockManager - any savings ?

HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Hi all,
I recall an alternative to having locking based around a HashMap (or some other Collection type) in LockManager. I think it was discussed here.
It was based on handing out tokens i.e read and write tokens on a first-come first-served basis and readers wait for writers but not for other readers. i.e. resources are shared for readers but not writers.
If anyone can recall this I'd be much obliged.
It may make my design much simpler as far as all those synchronised methods in the Data class are involved.

regards
[ February 05, 2003: Message edited by: HS Thomas ]
[ February 05, 2003: Message edited by: HS Thomas ]
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Found it. No, it wasn't on this forum.

You'd still need to keep track of Clients in a Map/HashMap/WeakHashMap that incorporates the above for each record and each Client could get a read lock or write lock token.
Advantages: You don't have to worry how synchronisation is achieved around blocks of subsequent code.For reading and writing to your resource, that is.
Disadvantages: Could create a bottleneck around this potentially large Map . I am not sure what the performance implications are ?
Please comment on the above.
[ February 05, 2003: Message edited by: HS Thomas ]
[ February 05, 2003: Message edited by: HS Thomas ]
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Actually the link to where I found it is http://www.asingh.net/technical/rwlocks.html. Also from Bruce Tate's - Bitter Java site.
The example used is for an Airline Ticketing station (scary).
I'd like someone on this forum to say ay or nay before I start changing my code with a view to saving myself many sleepless nights.
Peter,Mark,Eugene,Lasse?
[ February 05, 2003: Message edited by: HS Thomas ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Is it necessary and can you defend your choice? The answer to those two questions give you your answer. Unfortunately I can't say whether you should or shouldn't.
My opinion is that this is an assignment, not real life, so you don't have to add the complexity. Since all client requests would be lock-read-write-unlock pretty much right in a row, the time a record is locked isn't long, plus you can still read the data whether the record is locked or not. Well unless it is writing to the file, which really doesn't take long anyway.
But it is up to you.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Is it necessary and can you defend your choice?

Thinking about it, as far as the assignment goes,
er... no.
I think it'll save me worrying about ,perhaps, 2 sync calls i.e lock record related calls.
But in real life as a developer,I'd rather have the worry ( whether things are synched or not ) taken off my shoulders.
Thanks for your response, Mark.

Which leaves the question, in real-life where are the likely applications? Databases, almost certainly.
Networks ?
regards
P.S Threads are almost my pet-hate.
[ February 08, 2003: Message edited by: HS Thomas ]
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Having said that , I can see an advantage in savings on writing Unit tests. If a RWlock class takes the responsibility for synchronising on data, then there's that many fewer tests that I need to write.
It's also added protection against a , shall we say, easily distracted developer (like me sometimes ) .
"Gnothi se auton" ("Know Thyself") - Socrates
But still, all this is beyond the scope of this assignment.
[ February 05, 2003: Message edited by: HS Thomas ]
 
GeeCON Prague 2014
 
subject: Gettting read or write tokens in LockManager - any savings ?