Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Jay Lin

Greenhorn
+ Follow
since Apr 23, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jay Lin

Ah I missed a key point here, that the client may want to make logical queries on the database other than using only the methods provided by the Data interface (such as checking availability). I was going along with the (mistaken) notion that arbitrary Data queries (like update) can occur in arbitrary orders as long as individual queries are atomic, and everything would be okay. I didn't consider it bad to overbook, which of course should be avoided. Thanks for the answer, makes perfect sense now.
Hi all,

I'm following Habibi's book pretty closely, and admittedly synchronization is not my strongest point. My question has to do with the purpose of synchronizing the entire method (let's say the update method, for example) of the database class, and then having clients lock before calling update and unlocking afterwards.

The difference between my implementation and the book's is that my database is a singleton, whereas in the book there can be multiple database objects for the same DB. But I'm still not entirely clear why both the method is synchronized and lock/unlocks are placed around the method. It seems to me that only one of those is necessary.

If two update threads are hitting the DB, isn't it true that if update is synchronized, one thread will have to complete before the other one starts? Therefore, what is the purpose of locking a record before updating it?

I am guessing that there IS a purpose and I just don't see it, so hopefully someone can enlighten me =) Thanks!
Hi, I'm studying for the SCJD exam and looking through the code examples from Habibi's book, namely the DVDDbAdapter class. The modify DVD method goes something like this:


My question is, suppose the call to db.modifyDVD (fourth line) throws an exception. Does that mean the line which releases this DVD will not be called? My concern is that in the case of an exception (this method may also throw IOException), this DVD will never be released, and no threads from this point on can ever reserve it.

Would it be more correct to put the release code in a finally block at the end? Thanks for any info.