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 ]
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).
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 ]