Package java.util.concurrent.locks

Examples of java.util.concurrent.locks.ReentrantReadWriteLock.writeLock()


        rootResources = new LinkedList<ResourceRecord>();
        dirty = false;
        resourceRecordsFactory = new ResourceRecordFactory(factoryRegistry);
        ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
        readersLock = readWriteLock.readLock();
        writersLock = readWriteLock.writeLock();
    }

    /**
     * Add a resource as an object to the registry
     *
 
View Full Code Here


        this.applicationValidator = applicationValidator;
        rootResources = new LinkedList<ResourceRecord>();
        resourceRecordsFactory = new ResourceRecordFactory(factoryRegistry);
        ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
        readersLock = readWriteLock.readLock();
        writersLock = readWriteLock.writeLock();
        uriToResourceCache.put(Boolean.TRUE,
                               new SoftConcurrentMap<String, ArrayList<ResourceRecord>>());
        uriToResourceCache.put(Boolean.FALSE,
                               new SoftConcurrentMap<String, ArrayList<ResourceRecord>>());
    }
View Full Code Here

        }
        this.lifecycleManagerRegistry = lifecycleManagerRegistry;
        this.cacheByClass = new HashMap<Class<?>, ResourceRecord>();
        ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
        readersLock = readWriteLock.readLock();
        writersLock = readWriteLock.writeLock();
    }

    /**
     * Gets a resource record from a cache of records for the specified resource
     * class. If there is no record in the cache, then a new record is created
View Full Code Here

    * @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 (trace) log.tracef("WL acquired for '%s'", key);
      } else {
         lock.readLock().lock();
         if (trace) log.tracef("RL acquired for '%s'", key);
      }
View Full Code Here

   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);
View Full Code Here

   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);
   }

   public void downgradeLock(Object key) {
      ReentrantReadWriteLock lock = getLock(key);
View Full Code Here

   }

   public void downgradeLock(Object key) {
      ReentrantReadWriteLock lock = getLock(key);
      lock.readLock().lock();
      lock.writeLock().unlock();
      if (trace) log.tracef("WL downgraded to RL for '%s'", key);
   }

   final ReentrantReadWriteLock getLock(Object o) {
      return sharedLocks[hashToIndex(o)];
View Full Code Here

    * @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

   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);
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

TOP
Copyright © 2018 www.massapi.com. 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.