This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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 ]
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 ]
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 ]
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.