Hi, I am preparing for my submit and I want to be sure that I don't mess up the locking part so I need assurance does this locking method seem ok or not? Thanks [ February 26, 2007: Message edited by: Barry Gaunt ]
Joined: Feb 12, 2007
your unlock method musst be using notifyAll. This is not super cool, but it will work
Joined: Mar 01, 2007
just a question about autoboxing: why are you explicitly wrapping when getting / setting the values in locks? (i think currently every submission must at least be 5.0 or above)
one nice thing i observed is that you check for locked records not with locks.contains(), but with locks.get() == null. if it was my code, this probably would be worth a comment (e.g. "locks may contain null values"). [ March 02, 2007: Message edited by: Leo Himpth ]
Joined: Apr 07, 2005
In Dan's solution there is no notifyAll() in the method lock().
I checked several books for example where to put notify() and notifyAll().
I found both calls only in the code similar to our unlock(). So in methods that do not contain a waiting-loop.
Since I have not found any code snipplet that provides a notifyAll() in the waiting-loop, I also will not put it there. So the notifyAll() is just in my unlock() method.
What are your opinions on that issue?
Have you anything like a waiting-loop that has a notifyAll() at its end?
1.I presume that you don't have a separate class for locking - I base this presumption on the fact that you use methods like prepareFileForRead or validateInput in the lock method. Tip : use a separate class for the lock manager - is easy to maintain. 2.Don't use flag values (value to indicate an anormal method termination), I refere here on the "-1" Tip: try to use exceptions to signal this.
Regards M [ April 08, 2007: Message edited by: Mihai Radulescu ]
SCJP, SCJD, SCWCD
Joined: Apr 27, 2007
I think for each place you used wait(), you need to call notifyAll() at the end. Otherwise there is possible that waiting thread will not be waken up forever. For instance, you have 2 threads are waiting for a record becoming unlock. However, all the active threads (threads called lock method but not called unlock methods yet) are crashed before calling unlock() methods. Then your 2 waiting threads will be waiting forever.