### Eclipse Workspace Patch 1.0 #P jackrabbit-core Index: src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java (revision 1516110) +++ src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java (working copy) @@ -94,6 +94,11 @@ private final XAReentrantLock lockMapLock = new XAReentrantLock(); /** + * XA/Thread aware lock for lock properties + */ + private XAReentrantLock lockPropertiesLock = new XAReentrantLock(); + + /** * The periodically invoked lock timeout handler. */ private final ScheduledFuture timeoutHandler; @@ -185,13 +190,11 @@ holder = sysSession; } try { - acquire(); // FIXME: This session access is not thread-safe! + log.debug("Try to unlock expired lock. NodeId {0}", id); unlock(holder.getNodeById(id)); } catch (RepositoryException e) { - log.warn("Unable to expire the lock " + id, e); - } finally { - release(); + log.warn("Unable to expire the lock. NodeId " + id, e); } } } @@ -838,6 +841,27 @@ } /** + * Acquire lock for modifying lock properties + */ + private void acquireLockPropertiesLock() { + for (;;) { + try { + lockPropertiesLock.acquire(); + break; + } catch (InterruptedException e) { + // ignore + } + } + } + + /** + * Release lock on the lockPropertiesLock. + */ + private void releaseLockPropertiesLock() { + lockPropertiesLock.release(); + } + + /** * Start an update operation. This will acquire the lock on the lock map * and disable saving the lock map file. */ @@ -878,7 +902,9 @@ WorkspaceImpl wsp = (WorkspaceImpl) editingSession.getWorkspace(); UpdatableItemStateManager stateMgr = wsp.getItemStateManager(); - synchronized (stateMgr) { + try { + acquireLockPropertiesLock(); + if (stateMgr.inEditMode()) { throw new RepositoryException("Unable to write lock properties."); } @@ -927,6 +953,8 @@ } } } + } finally { + releaseLockPropertiesLock(); } } @@ -942,7 +970,9 @@ WorkspaceImpl wsp = (WorkspaceImpl) editingSession.getWorkspace(); UpdatableItemStateManager stateMgr = wsp.getItemStateManager(); - synchronized (stateMgr) { + try { + acquireLockPropertiesLock(); + try { // add properties to content NodeId nodeId = node.getNodeId(); @@ -976,6 +1006,8 @@ stateMgr.cancel(); } } + } finally { + releaseLockPropertiesLock(); } }