• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Record Locking design - any problems with following Monkhouse approach?

 
J Flew
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers

I have finished the basics of my record locking code and followed the design and approach set out by Andrew Monkhouse in his book. The approach seemed to make sense - first lock a record (or wait and eventually return false if already locked or time out), then read the record to double check it hasn't been booked, and if still unbooked update the record and then remove the lock. But reading some recent posts I am having some doubts, namely

1. In one thread Andrew himself said anyone who follows his locking method risks failing as he omitted a must requirement and also there is a bug in the locking code in his book.
2. Many experienced posters here seem to have used a different approach centred around using services

So I am interested in opinions does anyone see problems with following the locking approach used in the Monkhouse book or know about the missing must requirement and bug?

And any suggestions of alternative and better approaches to record locking?

Thank you




 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi J Flew,

My code to book a room has the same approach as you:
- lock record
- read record
- check if it's not already booked: throw exception if it is, update record otherwise
- unlock record

A thread goes to waiting state if the record is already locked (that's a must requirement as far as I know). In my instructions nothing is said about a time out requirement, so I didn't implement that one.
I didn't follow Andrew's approach at all, so I am not aware of the bug and the violation of a must requirement in his code (I have read the thread where he mentions these issues).
But it's about direct copying his locking code into your assignment, not following his approach. My code uses wait, notifyAll and synchronized to make my Data class be thread-safe and handle the locking and unlocking of records. So you know what you did: just following the approach he presents (and understanding what your code does and why it has to be coded like that: maybe you can skip some lines of code and still have same result,...) or just copied his code (without knowing what your code does).

Kind regards,
Roel
 
Matheus Mendes
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi J Flew,

As Far as I remember the andrew's lock approach broke one must requirement, and it is designed tottaly driven to the movie codes, you can't do this in your assigment ( at least in mine I couldn't ). About the bugs that he mentioned, he was referring to the fact that If you copy all code in that chapter and simply paste it on your project, you probably will fail. Because the book didn't fit the sun's real requirements, so the book have the Idea and the concepts to follow, but you have to adapt the code to your needs.

Best regards,
Matheus.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic