Package java.util.concurrent.locks

Examples of java.util.concurrent.locks.ReentrantReadWriteLock


         if (trace) log.tracef("RL acquired for '%s'", key);
      }
   }

   public boolean acquireLock(Object key, boolean exclusive, long millis) {
      ReentrantReadWriteLock lock = getLock(key);
      try {
         if (exclusive) {
            boolean success = lock.writeLock().tryLock(millis, TimeUnit.MILLISECONDS);
            if (success && trace) log.tracef("WL acquired for '%s'", key);
            return success;
         } else {
            boolean success = lock.readLock().tryLock(millis, TimeUnit.MILLISECONDS);
            if (success && trace) log.tracef("RL acquired for '%s'", key);
            return success;
         }
      } catch (InterruptedException e) {
         log.interruptedAcquiringLock(millis, e);
View Full Code Here


   /**
    * Releases a lock the caller may be holding. This method is idempotent.
    */
   public void releaseLock(Object key) {
      ReentrantReadWriteLock lock = getLock(key);
      if (lock.isWriteLockedByCurrentThread()) {
         lock.writeLock().unlock();
         if (trace) log.tracef("WL released for '%s'", key);
      } else {
         lock.readLock().unlock();
         if (trace) log.tracef("RL released for '%s'", key);
      }
   }
View Full Code Here

         if (trace) log.tracef("RL released for '%s'", key);
      }
   }

   public void upgradeLock(Object key) {
      ReentrantReadWriteLock lock = getLock(key);
      lock.readLock().unlock();
      // another thread could come here and take the RL or WL, forcing us to wait
      lock.writeLock().lock();
      if (trace) log.tracef("RL upgraded to WL for '%s'", key);
   }
View Full Code Here

      lockSegmentShift = 32 - tempLockSegShift;
      lockSegmentMask = numLocks - 1;

      sharedLocks = new ReentrantReadWriteLock[numLocks];

      for (int i = 0; i < numLocks; i++) sharedLocks[i] = new ReentrantReadWriteLock();
   }
View Full Code Here

    * Blocks until a lock is acquired.
    *
    * @param exclusive if true, a write (exclusive) lock is attempted, otherwise a read (shared) lock is used.
    */
   public void acquireLock(Object key, boolean exclusive) {
      ReentrantReadWriteLock lock = getLock(key);
      if (exclusive) {
         lock.writeLock().lock();
         if (log.isTraceEnabled()) log.trace("WL acquired for '" + key + "'");
      } else {
         lock.readLock().lock();
         if (log.isTraceEnabled()) log.trace("RL acquired for '" + key + "'");
      }
   }
View Full Code Here

         if (log.isTraceEnabled()) log.trace("RL acquired for '" + key + "'");
      }
   }

   public boolean acquireLock(String key, boolean exclusive, long millis) {
      ReentrantReadWriteLock lock = getLock(key);
      try {
         if (exclusive) {
            return lock.writeLock().tryLock(millis, TimeUnit.MILLISECONDS);
         } else {
            return lock.readLock().tryLock(millis, TimeUnit.MILLISECONDS);
         }
      } catch (InterruptedException e) {
         log.warn("Thread insterrupted while trying to acquire lock", e);
         return false;
      }
View Full Code Here

   /**
    * Releases a lock the caller may be holding. This method is idempotent.
    */
   public void releaseLock(Object key) {
      ReentrantReadWriteLock lock = getLock(key);
      if (lock.isWriteLockedByCurrentThread()) {
         lock.writeLock().unlock();
         if (log.isTraceEnabled()) log.trace("WL released for '" + key + "'");
      } else {
         lock.readLock().unlock();
         if (log.isTraceEnabled()) log.trace("RL released for '" + key + "'");
      }
   }
View Full Code Here

      Map<ReentrantReadWriteLock, Integer> distribution = new HashMap<ReentrantReadWriteLock, Integer>();

      for (Fqn f : fqns)
      {
         ReentrantReadWriteLock lock = stripedLock.getLock(f);
         if (distribution.containsKey(lock))
         {
            int count = distribution.get(lock) + 1;
            distribution.put(lock, count);
         }
View Full Code Here

      lockSegmentShift = 32 - tempLockSegShift;
      lockSegmentMask = numLocks - 1;

      sharedLocks = new ReentrantReadWriteLock[numLocks];

      for (int i = 0; i < numLocks; i++) sharedLocks[i] = new ReentrantReadWriteLock();
   }
View Full Code Here

    * Blocks until a lock is acquired.
    *
    * @param exclusive if true, a write (exclusive) lock is attempted, otherwise a read (shared) lock is used.
    */
   public void acquireLock(Object key, boolean exclusive) {
      ReentrantReadWriteLock lock = getLock(key);
      if (exclusive) {
         lock.writeLock().lock();
         if (log.isTraceEnabled()) log.trace("WL acquired for '" + key + "'");
      } else {
         lock.readLock().lock();
         if (log.isTraceEnabled()) log.trace("RL acquired for '" + key + "'");
      }
   }
View Full Code Here

TOP

Related Classes of java.util.concurrent.locks.ReentrantReadWriteLock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.