Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do we really need verify record number in lock() method

 
mark ken
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys:
I'm wondering do I need to verify a record to see if it's a valid record number or an undeleted record in lock() method, before doing lock process.

because I already verified each record in read, update and delete method, since lock method is only used before updating a record,
such as:
lock();
update();
unlock()

since update() method will verify record too, so I think maybe there is no necessay to verify record in lock() method.

Hoping get your advice. thank you very much.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You at the very least need to verify that the record isn't locked already...
 
mark ken
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so, in lock() method, I used while loop to detect is the record locked or not. why I need other method to verify the record isn't looked.

Originally posted by Jeroen T Wenting:
You at the very least need to verify that the record isn't locked already...
 
Jeremy Botha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you using a while loop to do the detection? Are you sure you don't run the risk of deadlocking your application?

Jeremy
 
mark ken
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jeremy:
did you read the book <SCJD Exam with J2SE 5 2nd edition>



Originally posted by Jeremy Botha:
How are you using a while loop to do the detection? Are you sure you don't run the risk of deadlocking your application?

Jeremy
 
mark ken
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone give me an answer. thanks
 
Jeremy Botha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark - no, I hadn't read that book.

Hmm. I'm not sure I'd use the method you've posted; it's far easier in my opinion to make use of wait() and notify()/notifyAll(). Each to his or her own though, I guess.

Jeremy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic