This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Locking the record using the cookie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Locking the record using the cookie" Watch "Locking the record using the cookie" New topic
Author

Locking the record using the cookie

Aruneesh Salhotra
Ranch Hand

Joined: May 12, 2004
Posts: 167
Hi,

I am slightly confused, in terms of locking a record using a cookie. It also says only the owner of the cookie can unlock the record.

I am not sure how it is to be done.

Two questions.
1. Are we locking the records in the DB file.
2. If we are locking the record in the DB file, is the "marker" as the start of each record is to be used to store the cookie file.

Help would be much appreciated.

Regards
Aruneesh
B Chen
Ranch Hand

Joined: Dec 27, 2005
Posts: 89
I don't think record in the DB file itself is "locked".
The locking occurs in memory to allow a client exclusive access to view and update a record. This prevents another client from doing something to the record in between the first clients view and update. The cookie identifies which client owns the lock. The locks should not persist across server restarts.
[ January 27, 2006: Message edited by: B Chen ]

SCJD<br />SCJP 1.4
Aruneesh Salhotra
Ranch Hand

Joined: May 12, 2004
Posts: 167
This makes me assume that what you are saying is that there would be a array of vectors, containing information read from the DB file.

On any call, the rows are locked. I think the better design would be to locked the whole vector, and then proceeding.
B Chen
Ranch Hand

Joined: Dec 27, 2005
Posts: 89
You mean a vector of DB records?
If multiple threads (clients) can add/remove items from the vector (which is probably true for any of the assignments), yes then you should lock on the vector before proceeding. The thread-safety provided by the vector class is not sufficient.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Locking the record using the cookie
 
Similar Threads
nx:All of URLy Bird 1.1.3 about delete and update method
Status & Cookie
Data Locking with a DB File.
NX: My Locking Mechanism
Data access layer of Bodgitt and Scraper