• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reader / writer lock - is it universal enough to use in every scjd project?

 
Michael Wiezik
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've read the description of reder-writer lock pattern in

http://www.javaworld.com/javaworld/jw-07-2000/jw-0714-locks_p.html

It seems it solves many problems with locking. Does it fit to SCJD project or is it f.i. too sophisticated?
 
Liang Anmian
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the SCJD assignment, write lock is mandatory of course. DUH!

But, is it really necessary to have a read lock? I'm not sure. After searching the forum, I hardly find anyone implementing read locks.

It seems that whatever we have done has already satisfied the requirements. I'm not totally sure, though. I will try to explain my current incomplete implementation.

Whenever changes are required on the RandomAccessFile, I lock the ReentrantLock object to limit access to that RandomAccessFile object. Even when I only attempt to read data, I also lock the ReentrantLock object. So it seems that I have effectively prevent clients from updating the RandomAccessFile while reading is in progress. At the same time, I have also successfully prevent clients from reading the RandomAccessFile when updates are ongoing. Of course, I'm using Tiger, which explains my decision to use ReentrantLock objects. For JDK 1.4, the same thing can be achieved with synchronized blocks.

So it seems that read/write lock is not necessary for this assignment, unless I'm missing something. According to the article posted, lock lease is a nice feature to have, but probably an overkill for an SCJD assignment. After posting a few topics on this forum, I came to a conclusion that it's far better not to provide additional functions. Just implement enough to satisfy the requirements. Like what the others mentioned, if you implement something else, not only you don't get to earn additional marks, but you open the door to losing marks!
[ April 23, 2005: Message edited by: Liang Anmian ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic