wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes (B&S)Question regarding locking()&unlock() 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 "(B&S)Question regarding locking()&unlock()" Watch "(B&S)Question regarding locking()&unlock()" New topic
Author

(B&S)Question regarding locking()&unlock()

Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Hi all
I have a funny question, might sound stupid but i have got to ask this question. Imagine that i have a Service Interface(Business Layer) where i place by book() and find() methods. Now this is the question:
If i am gonna have the Service Interface(Business Logic), would i have to place "sync" code within read(),update() or delete()? In my business logic i intend to have the client call lock(),update(),unlock() in that sequence in my Book() method. So i am assuming that i wouldnt have to "sync" within these methods? Please correct me if i am wrong, and i would also like a scenario where it could fail if i dont place "sync" code within the methods. Right now this is a scenario i am working with:

My read() "sync"s on the internal cache that holds all the records of contractors and allows only one thread gain access to the cache and return an array of strings. The pseudocode goes like thus:



Ok that is my read() pseudocode, my update() has something like this:



And my lock() method has the following pseudocode:

Well that is mostly what i have now in my Data.java.
My question is. If i am using the Services Interface and having Book() call lock(), update(),unlock() in that sequence, would i need to put "sync" within update()? Thanks all. I am sorry if this post is too long. Have a nice day all.


Saheed Adepoju<br />SCJP 1.4<br />SCJD (B&S..In progress)
Ed Tse
Ranch Hand

Joined: Sep 18, 2003
Posts: 183
This thread discuss the same question you brought up
link To summarize the thread, there are some business logic that do not require locking and unlocking while the sync is required to lock the access to the db file.

The fact that there is a given interface of the DB gives me a feeling that the examiner would mix his test classes with your sumbitted jar. In such case, he might test locking of your DB and your assumption would fail to meet requirement.

I am just guessing.

[ February 28, 2006: Message edited by: Ed Tse ]
[ February 28, 2006: Message edited by: Ed Tse ]

SCJP, Pre-SCJD (URLyBird 1.3.1), Teradata Cert'd Prof
Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Originally posted by Ed Tse:
This thread discuss the same question you brought up
link

The fact that there is a given interface of the DB gives me a feeling that the examiner would mix his test classes with your sumbitted jar. In such case, he might test locking of your DB and your assumption would fail to meet requirement.

I am just guessing.

[ February 28, 2006: Message edited by: Ed Tse ]

Thanks for such a fast reply, but I would like to ask some more. You are saying(guessing), that if the examiner tests with my submitted jar i might fail automatically, please clarify? I imagined that since i have a choices.txt file, i will document that i have a Business layer and that the methods in the Data.java would have to be called from this business layer. My take on your response to my question is that if I were to put a business layer, i could fail cause the examiner wouldnt be able to test my Data.java right? My question to you now is that, where exactly do u guess i could automatically fail if i submit my proposed solution? Thanks alot for your input.
Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Hi
I see that you updated your last post to give me a summary. Well the only method i would have in the Business layer would be Book() and Search(). In my Book() method, i would have a call to lock(),update() and unlock(), in that sequence which shoud make sure the record i want is locked before i update the datafile and updating my cache and then finally call unlock() to make the resource available. So all client wanting to book a record would have to call this method book() and not call lock(),update(),unlock(). I hope my scenario makes sense(or doesnt it ). Anyways i expect your impressive input. Thanks.
Ed Tse
Ranch Hand

Joined: Sep 18, 2003
Posts: 183
I didn't say fail automatically, I am just saying that he might penalize a bit on locking or OOD, who knows.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: (B&S)Question regarding locking()&unlock()