Forums Register Login

[URLyBird]Is my lock manager class right?

+Pie Number of slices to send: Send
Hi all,

Thanks for caring my problem. I have finished my LockManager, can you give me some advices on it. In Data' lock, I call lock in LockManager. And in Data's unlock, I call unlock in LockManager. Before showing the code, see following instructions:
1. I add a HashMap type var lockThreadMap to LockManager. If a record has never been locked, then the first locker thread will be put into lockThreadMap with the recNo as key.
2. In lock, if a record not yet locked, then nothing special. If a record already locked, then get the thread from lockThreadMap with the key recNo and wait on that thread.
3. In unlock, after lockMap remove the lockCookie via key recNo, I fetch recNo corresponded thread from lockThreadMap and call that thread's notify.

Appendix: the LockManager

<Big code portion removed - see below>

I am hoping your replies.
[ April 18, 2006: Message edited by: Barry Gaunt ]
+Pie Number of slices to send: Send
http://faq.javaranch.com/view?ScjdFaq
After more than 70 posts you should know the posting policy.
+Pie Number of slices to send: Send
Hallo Pan


use standard java code formating - the code is more easy to read/uderstand.


0.lockCookie = System.currentTimeMillis() -> not so nice I have a computer with a broken bios - the date is always the same.
1.you use nested synchronized blocks - this can lead you to a dangerous dead lock swamp. Maybe the currnet code works fine but if someone tries to imporve(change it can generate very easy a dead lock -> this methodology is not flexible enought.
2.By any exception your LM generate a cookie a valid one.
3.It seams that yout LM locks all the threads thats enter in the lock method - a nice feature - but I am not shore that you need that.
4.Consider scenario : a client I lock a record and I do Thread.currentThread().nitifyAll().
5.To many Integer instaces - think about(inboxing) it.


There are also others but now I must deep down in my own project(s).


Regards Mihai.
+Pie Number of slices to send: Send
Please do not post complete portions of your code. See this part of the SCJD forum FAQ.

For questions / discussions on the assignment, in general we will allow discussion where members are trying to:

* understand the assignment

* get a suggestion on how to work on a particular problem,

* are asking for feedback on small sections of code

* get suggestions about which tools to use.

But we will not allow posting major parts of a solution. For example, you may not post your entire code for locking and unlocking records - this is a major section (currently worth 20% of the assignment) and sections of such code will be removed from any post. Posting just one method (e.g. the lock() method is usually considered reasonable).



(Original in TC)
[ April 18, 2006: Message edited by: Barry Gaunt ]
+Pie Number of slices to send: Send
Oh, I am so sorry for my breaking the rule in this forum. I will be a legal rancher here after this mistake.

Regarding the lockManager problem, I am clear now.One simple way is let all clients thread waiting on lockMap. And in unlock after the remove the lockMap, it also call notify.
If you want to look young and thin, hang around old, fat people. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 875 times.
Similar Threads
3rd level of locking
My Locking Approach
a client could unlock a record that it has not locked?
(URLYBird 1.3.3] yet another guy disturbed with LOCK feature
Record locking on recNo
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:09:59.