aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Locking confusion -- help 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 "Locking confusion -- help" Watch "Locking confusion -- help" New topic
Author

Locking confusion -- help

Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Hey, I got confused about the locking mechnism:

in the DBAccess, I implemented sync blocks in lock, unlock, update, and delete. all on one static map of cached records.

in the business logic (with thin client so the logic is on server), I have book and show, where book calls the sequence of DBAccess: lock -- read -- compare -- update -- unlock.

however, these operations on the business layer are not sync. So I think there is a hole between the sync operations, because even business layer called lock, it becomes unsync'ed after exiting its synchronized block. May I miss something here: should I put the book in the business to be synced?

Please help. Thanks.


--------<br />Andy Zhu<br />scjp 1.4<br />scjd 1.4<br />SAS Certified Programmer 9.0
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
Originally posted by Andy Zhu:
Hey, I got confused about the locking mechnism:

in the DBAccess, I implemented sync blocks in lock, unlock, update, and delete. all on one static map of cached records.

in the business logic (with thin client so the logic is on server), I have book and show, where book calls the sequence of DBAccess: lock -- read -- compare -- update -- unlock.

however, these operations on the business layer are not sync. So I think there is a hole between the sync operations, because even business layer called lock, it becomes unsync'ed after exiting its synchronized block. May I miss something here: should I put the book in the business to be synced?

Please help. Thanks.



No, because the record in question is locked and cannot be modified by any other thread.


Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Hey, Anton:

I am trying to clear my mind: in lockRecord, sync is on the map of locked record. It that recNo is already in the map, then that thread in book of business logic will go to wait for the locker. If it is not, then the thread will obtain that locker and other thread won't lock on it. Ooh, even though the lockRecord exits its sync block, the locked map already booked it and this is how it reaches atomic op in business layer. Thanks, Anton.

One more, how did you implement sync on modifiable operation at DB access: record level or database level, or simply the file pointer? I implemented on the database level, and would like to know if this will result deduction of marks.
Anton Golovin
Ranch Hand

Joined: Jul 02, 2004
Posts: 476
Originally posted by Andy Zhu:
Hey, Anton:

I am trying to clear my mind: in lockRecord, sync is on the map of locked record. It that recNo is already in the map, then that thread in book of business logic will go to wait for the locker. If it is not, then the thread will obtain that locker and other thread won't lock on it. Ooh, even though the lockRecord exits its sync block, the locked map already booked it and this is how it reaches atomic op in business layer. Thanks, Anton.

One more, how did you implement sync on modifiable operation at DB access: record level or database level, or simply the file pointer? I implemented on the database level, and would like to know if this will result deduction of marks.


Sync on modifiable operations in data logic was by synchronizing the method itself (find, delete.) Sync on business logic (findRoom, bookRoom) was achieved via some more interesting operations. I hope they do not delete this post, and hope it is useful for you:



Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Thanks, Anton, for your posting. No, my last question is about the access level, my implementation is lock on the cached map (I think you mentioned a cache for this performance in another thread, but I take it as an object for locking mechnism). so it coms to me, if sun will like it or not, since it seems that I locked whole db for modifiable operation. I guess I may did too much. But I am not certain and want input about this.

Thank u.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Locking confusion -- help