Sorry for the numerous questions. Internet access is sparse here in Iraq, so my posts tend to be "batch-posted" when I get online.
I'm implementing database record-locking. I have a Map<Long, Long> where key=recNo, and value=cookie. If there's an entry in the Map for that recNo, then the record is locked. When I use the wait() and notifyAll() methods, I'm using them on the map itself. I don't see how I can do it elegantly on a record-by-record basis.
My assignment specifies that if a client needs to lock a record, and the record is already locked, then the
thread needs to go to sleep. In fact, it states that the thread must be "consuming no CPU cycles until the desired resource becomes available". By locking on the Map and not per record, I may be violating this. However it says that it "should", and not "must", so I guess I'm sort of safe?
Is there a way to wait() on a record instead of on the whole Map?
Obviously, I can set up something to do this, but every solution I come up with seems overkill and kludgey (like maintaining a HashSet or array of arbitrary objects to lock on). Locking on the Long objects seems a little flimsy. I like my simple Map<Long, Long>. Any ideas?