wood burning stoves
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Trouble understanding the Data.java logic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Trouble understanding the Data.java logic" Watch "Trouble understanding the Data.java logic" New topic

Trouble understanding the Data.java logic

Derick Potgieter

Joined: Feb 19, 2004
Posts: 13
I`m having trouble with the whole logic of the file. I have implement the following class

now my problem, to for instance update a record i have to provide a cookie.
but i can only get a cookie if i execute lock(recno). so should i create another class, implement the exact same methods and then have something like the following code??

would this be right, or should i have the lock/unlock in my main data class. They way i`m doing it will work, but i does`nt look right.
using sun`s provided interface class then i create my own Data.java class
that implements that class, and now i`m creating a third class that looks they same as the sun interface class to actually lock,update,unlock.

Jon Entwistle
Ranch Hand

Joined: Feb 20, 2003
Posts: 118
Hi Derick,

OK... what you are describing is creating a proxy class on the server which has the same methods as Data but without the lock/unlock method - in other words you are hiding the need to lock/unlock from clients.

I know from reading other threads that people have passed the exam by following this strategy, although I personaly do not like it. My problems with it are twofold. First off, by hiding the lock/unlock from clients you are enforcing a locking strategy. This may be OK for the scenario we are given but who knows what locking strategy future clients will want/need to enforce? Secondly, I may be wrong but if Sun felt it important enough to include the cookies in the method signature, this says to me that they too important to hide at the first opportunity.

Your alternative is to pass the resposibilty for the locking through to the client, who must of course follow the (documented) need to follow the lock/update/unlock procedure.

These are just my thoughts on it, although I would say that you should go with whichever method you would be most comfortable justifying/defending.



Baruch Sadogursky
Ranch Hand

Joined: Apr 09, 2002
Posts: 62
The option of passing the locking responsibility to the client brings a lot of complexivity to the application. Once you follow that strategy, you should track inactive/disconnected clients, in other words, make your server stateful.
On the other hand, by using a proxy or a facade you make the locked operations atomic, which release you from the need of mantainig conversation state with the client, makes your life easier, the application simplier, and once you'll want to change the locking strategy, you can switch the facade, or get rid of it totally.

Regards,<br />Baruch.<p>SDFWOF<br />FGEHWS<br />FNEVGE
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11776

Hi Derrick,

I think you have missed the value of the lock methods: specifically they are there to stop two clients from booking the same record.

Consider the following scenario:
  • Client A requests a list of all records
  • Client B requests a list of all records
  • Client A can see that record 5 is not yet booked
  • Client B can see that record 5 is not yet booked
  • Client A updates record 5 to book it
  • Client B updates record 5 to book it

  • In this case, there was nothing to stop the two clients booking the same record.

    So how are you going to stop this? I am leaving this as an exercise for you - we will eventually get to a solution where locking works for you .

    By the way, could you please remove those ll's from your displayed name to meet the JavaRanch Official Policy On Displayed Names, which requires your displayed name to be a real name. You can change it here.

    Thanks and regards, Andrew

    The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
    I agree. Here's the link: http://aspose.com/file-tools
    subject: Trouble understanding the Data.java logic
    It's not a secret anymore!