db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven Richman <j...@shift9.com>
Subject odmg locking questions
Date Fri, 04 Jul 2003 16:46:55 GMT

I'm trying to understand some of the code in the odmg locking 

In all of the locking strategies, there is code like this:

    public boolean writeLock(TransactionImpl tx, Object obj)
        LockEntry writer = getWriter(obj);
        if (writer == null)
            if (setWriter(tx, obj))
                return true;
                return writeLock(tx, obj);

(and similar code for read locks). Here, setWriter is
AbstractLockStrategy.setWriter, which returns LockMap.setWriter. I'm using
the InMemoryLockMapImpl, and if you look at the code for
InMemoryLockMapImpl, setWriter *always* returns true.

So, my question is, if the "if (writer == null)" test succeeds, but
another thread acquires the lock before we call setWriter, isn't that bad?  
setWriter always returns true, so the call to writeLock will return true,
and there will be two threads that think they have the lock at the same
time. Or is there some higher level synchronization that I'm missing that
keeps this from happening?


View raw message