Package java.util.concurrent.locks

Examples of java.util.concurrent.locks.ReentrantReadWriteLock


         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

      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

   @BeforeMethod(alwaysRun = true)
   public void setUp() throws Exception
   {
      // lock=new ReentrantWriterPreferenceReadWriteLock();
      lock = new ReentrantReadWriteLock();
      rl = lock.readLock();
      wl = lock.writeLock();
      thread_ex = null;
   }
View Full Code Here

         throw ex;
   }

   public void testMoreWriteReleasesThanAcquisitions() throws InterruptedException
   {
      lock = new ReentrantReadWriteLock();
      lock.writeLock().lock();
      lock.writeLock().unlock();
      try
      {
         lock.writeLock().unlock();
View Full Code Here

      }
   }

   public void testMoreReadReleasesThanAcquisitions() throws InterruptedException
   {
      lock = new ReentrantReadWriteLock();
      lock.readLock().lock();
      lock.readLock().unlock();
      try
      {
         lock.readLock().unlock();
View Full Code Here

      }
   }

   public void testSimple() throws InterruptedException
   {
      lock = new ReentrantReadWriteLock();
      lock.readLock().lock();
      // upgrades must be manual; involving giving up the RL first.  Sucks.
      // see http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/ReentrantReadWriteLock.html
      lock.readLock().unlock();
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.