You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by oz...@apache.org on 2005/01/08 00:33:24 UTC

cvs commit: jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking ReadWriteLockManager.java GenericLock.java ReadWriteLock.java

ozeigermann    2005/01/07 15:33:24

  Modified:    transaction/src/java/org/apache/commons/transaction/locking
                        ReadWriteLockManager.java GenericLock.java
                        ReadWriteLock.java
  Log:
  Made write lock preferred over read lock like one would expect from a read/write lock
  
  Revision  Changes    Path
  1.3       +8 -6      jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/ReadWriteLockManager.java
  
  Index: ReadWriteLockManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/ReadWriteLockManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ReadWriteLockManager.java	17 Dec 2004 00:21:15 -0000	1.2
  +++ ReadWriteLockManager.java	7 Jan 2005 23:33:24 -0000	1.3
  @@ -97,7 +97,8 @@
        *             will be thrown when the lock can not be acquired
        */
       public void readLock(Object ownerId, Object resourceId) throws LockException {
  -        lock(ownerId, resourceId, ReadWriteLock.READ_LOCK, true);
  +        lock(ownerId, resourceId, ReadWriteLock.READ_LOCK, GenericLock.COMPATIBILITY_REENTRANT,
  +                false, globalTimeoutMSecs);
       }
   
       /**
  @@ -116,7 +117,8 @@
        *             will be thrown when the lock can not be acquired
        */
       public void writeLock(Object ownerId, Object resourceId) throws LockException {
  -        lock(ownerId, resourceId, ReadWriteLock.WRITE_LOCK, true);
  +        lock(ownerId, resourceId, ReadWriteLock.WRITE_LOCK, GenericLock.COMPATIBILITY_REENTRANT,
  +                true, globalTimeoutMSecs);
       }
   
       protected GenericLock createLock(Object resourceId) {
  
  
  
  1.9       +15 -4     jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/GenericLock.java
  
  Index: GenericLock.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/GenericLock.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- GenericLock.java	7 Jan 2005 13:52:42 -0000	1.8
  +++ GenericLock.java	7 Jan 2005 23:33:24 -0000	1.9
  @@ -194,6 +194,17 @@
       }
       
       /**
  +     * Tries to blockingly acquire a lock which can be preferred.
  +     * 
  +     * @see #acquire(Object, int, boolean, int, boolean, long) 
  +     */
  +    public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean preferred,
  +            long timeoutMSecs) throws InterruptedException {
  +        return acquire(ownerId, targetLockLevel, true, COMPATIBILITY_REENTRANT, preferred,
  +                timeoutMSecs);
  +    }
  +    
  +    /**
        * Tries to acquire a certain lock level on this lock. Does the same as
        * {@link org.apache.commons.transaction.locking.MultiLevelLock#acquire(java.lang.Object, int, boolean, boolean, long)}
        * except that it allows for different compatibility settings. There is an
  
  
  
  1.3       +9 -7      jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/ReadWriteLock.java
  
  Index: ReadWriteLock.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/ReadWriteLock.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ReadWriteLock.java	13 Dec 2004 10:51:40 -0000	1.2
  +++ ReadWriteLock.java	7 Jan 2005 23:33:24 -0000	1.3
  @@ -32,7 +32,9 @@
    * Reads are shared which means there can be any number of concurrent read
    * accesses allowed by this lock. Writes are exclusive. This means when there is
    * a write access no other access neither read nor write are allowed by this
  - * lock. <br>
  + * lock. Additionally, writes are preferred over reads in order to avoid starvation. The idea
  + * is that there are many readers, but few writers and if things work out bad the writer would
  + * never be served at all. That's why it is preferred.<br>
    * <br>
    * Calls to both {@link #acquireRead(Object, long)}and
    * {@link #acquireWrite(Object, long)}are blocking and reentrant. Blocking
  @@ -80,7 +82,7 @@
        *             when the thread waiting on this method is interrupted
        */
       public boolean acquireRead(Object ownerId, long timeoutMSecs) throws InterruptedException {
  -        return acquire(ownerId, READ_LOCK, true, true, timeoutMSecs);
  +        return acquire(ownerId, READ_LOCK, false, timeoutMSecs);
       }
   
       /**
  @@ -98,6 +100,6 @@
        *             when the thread waiting on this method is interrupted
        */
       public boolean acquireWrite(Object ownerId, long timeoutMSecs) throws InterruptedException {
  -        return acquire(ownerId, WRITE_LOCK, true, true, timeoutMSecs);
  +        return acquire(ownerId, WRITE_LOCK, true, timeoutMSecs);
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org