Hi Mark, Pls. explain locking process. 1. It is for record level locking. But when a process is syn. (syn. {read, modify, write}). Then how can multiple users perform same process for diff. records simultaneously? 2. How can I get lock on a particular record? A record is not an object.I have read, store the record no. and if someone request the same no. which is in list, asked the thread to wait().Is this the way to perform lock()? But 1st point is not clear to me, pls. give me your time. Thanks. Regards, Sanjeev. [ March 25, 2002: Message edited by: sanjeev mehra ]
Don't think of this locking schema as a record lock as you know in Oracle or DB2, or other DBMS. This is a self imposed "Lock", which is just that the record number is in a HashSet, and you should wait till that user removes it from the HashSet when it calls unlock() As to your first point, lock is synchronized, when a client calls lock it either locks the record but putting the record number into the HashSet. If another client has the lock, (That record number already exists in the HashSet), then you call wait(), by calling wait, you allow another thread to call lock() which might be requesting a lock on a different record, that is not in the HashSet, therefore that second client gets the lock for a different record. Mark
---------------------------------- As to your first point, lock is synchronized, when a client calls lock it either locks the record but putting the record number into the HashSet. If another client has the lock, (That record number already exists in the HashSet), then you call wait(), by calling wait,
you allow another thread to call lock() which might be requesting a lock on a different record, that is not in the HashSet, therefore that second client gets the lock for a different record. Mark. --------------------------------- Hi Mark, Thanks for you response. What I have learned is that lock() is nothing but (syn. {check the record_no in the HashSet + if not found, put record_no in Hashset + read record + modify record + write record}). If request by another thread for the same record comes, that thread will execute wait(). (is this for to save processor resources?). Hear is my problem, If request from another thread for diff. record comes, I think, same object can't execute request simultaneously. Because lock() process is syn. and it can't serve multiple thread. Even for diff. record no. But this is not record level locking, so I am not correct. Mark you patience can help me to pass the exam. Pls. correct me where I am wrong. Thanks. Regards, Sanjeev
sanjeev mehra
Ranch Hand
Joined: Feb 12, 2001
Posts: 93
posted
0
hi Mark, i am waiting for your response. pls. help me to clear my doubts. regards, sanjeev.
No, it is to allow other clients to call lock. When a thread has a lock on an object, it is exclusive, no other client can call or use it, until the thread is done with it, or until it is put into a wait state. That is why wait() notify(), and notifyAll() are all defined in the Object class. This way every single object ever created in Java will have those methods. And in all honesty I only synchronize on the HashSet. as in here is the beginning of my lock method
lockedRecords is my HashSet Hope that clarifies things for you. Mark
Laudney Ren
Ranch Hand
Joined: Jan 06, 2002
Posts: 111
posted
0
I have a question here: Since "record level lock" is required, it's ideal for different threads to access different records simultaneously at any time point. However, since when a thread tries to lock (or maybe also unlock), it synchronizes on the HashSet. During this period, other threads accessing other records are also blocked out!! So, maybe an ideal solution is to make "lock objects", which in Mark's case is the HashSet, completely isolated (or divided) for each record. For example: if you have 3 records in total, create 3 objects, each representing one record. Thereafter, lock on a record equals a lock on the corresponding object. Since 3 objects are completely isolated, ideal record-level access is realized. -- Laudney
" Veni, vidi, vici "<br />" I came, I saw, I conquered "
Laudney - When a client has a lock on the HashSet it does not stop another client from working on another record at all. All the HashSet has is record numbers that are currently locked, not the records themselves. And besides that the lock on the HashSet at anytime will be in milliseconds. Mark
Laudney Ren
Ranch Hand
Joined: Jan 06, 2002
Posts: 111
posted
0
Yes. I got it.
cpowell
Greenhorn
Joined: Mar 29, 2002
Posts: 2
posted
0
Hi Mark, I was reading the previous post and I have a question. How do you add the record 'number' to a HashSet? Do you use a wrapper class? To my knowledge you can't add a primitive to a HashSet using the HashSet.add() method.
Actually I didn't use a LockManager(although I should have), so I wouldn't be the best to ask. Try doing a search on this forum on LockManager, I am sure you will find some great posts on it. Mark
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.