This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Issue for the time to lock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Issue for the time to lock " Watch "Issue for the time to lock " New topic
Author

Issue for the time to lock

Norbert Hasselberg
Greenhorn

Joined: Feb 26, 2004
Posts: 9
I am working on the Bodgit&Scarper Submission and almost finished my work. But i have still problems with the timepoint of locking. From the client's point of view, there are two (for me) possibilities for locking for Update and Delete :
1.) Lock
then create a dialog for Update / Delete
then call update
then unlock

2. Create a dialog for Update / Delete
then lock
then call update
then unlock

In the first solution , i have the problem, that the person on the client can go to lunch during the Dialog is open. So i have to define on the server side a timeout mechanismen.
In the second solution i don't understand completely , why do i have locking, because when define the update/delte (and the other) method synchonized, i can only be in one of the synchronized methods... ???

My questions are : Is the solution 1 or 2 the better solution ?
Is locking really a must ?
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Norbert,

Is the solution 1 or 2 the better solution ?


The best solution is 3.

3. When you're ready to update (your client won't call delete anyway):

3.1 lock
3.2 reread the record and check if it wasn't changed in the meantime
3.3a if OK in 3.2 then update
3.3b else throw some application exception ("Record changed" or "Record not available anymore" or the like)
3.4 finally unlock

Is locking really a must ?


Yes, and it becomes clearer with solution 3. Before 3.1, you've read the record and displayed it (possibly among many others) to the user. The latter chose one to book it and pressed some "Book" button.
What you must check, is that the record is still available for booking (because nothing prevented another user to book the same record in the meantime). That's typically what we call "optimistic locking", a locking scheme which avoids the low (and bad) concurrency offered by solution 1. You lock just before the update, *but* you check, within the lock, that the record is still available (step 3.2).

Regards,

Phil.
[ May 23, 2004: Message edited by: Philippe Maquet ]
Norbert Hasselberg
Greenhorn

Joined: Feb 26, 2004
Posts: 9
Many Thank Phillipe, what you wrote was very helpfull.
But :

.....
The best solution is 3.

3. When you're ready to update (your client won't call delete anyway):

......

Why the client should not call delete ? My understanding is, that the client is for a CSR , so a CSR can delete a record.

"The company's IT director has decided to migrate the existing application to a Java technology based system. Initially, the system will support only the CSRs, ... "
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Norbert,

Why the client should not call delete ? My understanding is, that the client is for a CSR , so a CSR can delete a record.


I've got a URLyBird asignment, not Bodgit&Scarper so please check your own instructions. But as far as URLyBird is concerned, create and delete are to be implemented in the Data layer (possibly to be used in another context), but are *not* used by the client application.

Regards,

Phil.
S Perreault
Ranch Hand

Joined: Oct 29, 2003
Posts: 37
Gah! Now I know why many people are designing it to take place outside of the Data class. :-/

Now I have to redo all of my locking mechanism! Of course, better now than fail the cert =)

Also I have realized that my Facade layer implements all of the Data methods which, as you have mentioned, is unnecessary.

Thanks again Phil,
Perogi.
Norbert Hasselberg
Greenhorn

Joined: Feb 26, 2004
Posts: 9
hmmmm.....
So at the amlost end of my work i am confused about what phillip was told.
Who should deletes and creates new contractors in the Bodgit&Scarper appl,
if not the CSR ??
My point of view is still, that this is also the job of the CSR and thats way it is part of my client.

OK , a question to all, is my point of view wrong ?
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
The server side(Data class) requirements and the client side(business use cases) requirement are different. We just implement them as they are mentioned in the specs and do not try to mix both of them.But we are free to make use of the server-side functionality(Data class) to implement the client-side functionality.

Originally posted by Norbert Hasselberg:
.Who should deletes and creates new contractors in the Bodgit&Scarper appl,if not the CSR ??
My point of view is still, that this is also the job of the CSR and thats way it is part of my client.


Maybe another automated application...We do not know from the specs.
Perhaps, future enhancements? :roll: . For the assignment, the client program is supposed to provide a limited functionality only(booking & searching).
[ May 26, 2004: Message edited by: Vishwa Kumba ]
S Perreault
Ranch Hand

Joined: Oct 29, 2003
Posts: 37
Norbert,

Actually many CSRs would NOT have the ability to perform those actions. Usually a level one CSR would only be able to book contractors. If someone needed to unbook an appointment, the client would be sent to a higher level CSR who may be using a different application (or the same one with more functionality 'unlocked') to perform an unbooking.

Furthermore, to add new Contractors or delete old ones would probably come under the domain of a Manager or Admin. In a real world scenario, a company wouldn't want to let the level one CSRs perform such tasks on their database.

I have actually worked on a project that created an application that performed these tasks and many more.

I hope this helps.

Perogi.
Norbert Hasselberg
Greenhorn

Joined: Feb 26, 2004
Posts: 9
Many thanks to all , i agree now your arguments. So i am thinking about removing create and delete from my appl. But when i let this functions in my appl, i think sun cannot deduct points for that....
 
wood burning stoves
 
subject: Issue for the time to lock
 
Similar Threads
pls validate my locking strategy - all inputs are g8ly appreciated. (URLyBird)
[B&S] - Delete & Unlock Questions
Locking strategy URLyBird 1.1.1 with ReentrantLock
NX: Client side lock vs Server side lock
RecordNotFoundException in locking