Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Gettting read or write tokens in LockManager - any savings ?

 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic