Java 8 ReadWriteLock - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ReadWriteLock class.

This code example shows how to use the following methods:readLock, writeLock
 * @author Michael C. Han 
 */ 
public class LiferayLoggerFactory implements ILoggerFactory { 
 
	public LiferayLoggerFactory() { 
		ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
 
		_readLock = readWriteLock.readLock();
		_writeLock = readWriteLock.writeLock();
	} 
 
	@Override 
	public Logger getLogger(String name) {
		Logger logger = null; 
 
		_readLock.lock();
 
		try { 
			logger = _loggers.get(name);
		} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:readLock, writeLock
public class SynchronizedIndexAccessorImpl implements IndexAccessor { 
 
	public SynchronizedIndexAccessorImpl(IndexAccessor indexAccessor) {
		_indexAccessor = indexAccessor;
 
		ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
 
		_readLock = readWriteLock.readLock();
		_writeLock = readWriteLock.writeLock();
	} 
 
	@Override 
	public IndexSearcher acquireIndexSearcher() throws IOException {
		_readLock.lock();
 
		try { 
			return _indexAccessor.acquireIndexSearcher();
		} 
		finally { 
			_readLock.unlock();
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:readLock, writeLock
        public final Lock readLock;
 
        public final Lock writeLock;
 
        { 
            final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(true);
            readLock = readWriteLock.readLock();
            writeLock = readWriteLock.writeLock();
        } 
    } 
 
    /** 
     * The active storage providers. 
     */ 
    private final Map<String, StorageProvider> mProviders = new LinkedHashMap<String, StorageProvider>();
 
    /** 
     * Locking data for the active storage providers. 
     */ 
    private final Map<StorageProvider, SynchronizationAid> mProviderLocks = new IdentityHashMap<StorageProvider, SynchronizationAid>();
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:readLock, writeLock
        this.objectCache = cache;
    } 
     
    /** 
     * @return A read-only view of the underlying Map used to cache created objects 
     */ 
    public final Map<K, T> getCacheMap() {
        return Collections.unmodifiableMap(this.objectCache);
    } 
     
    /** 
     * Allows the object cache map to be cleared of entries 
     */ 
    public final void clear() { 
        this.writeLock.lock();
        try { 
            this.objectCache.clear();
        } 
        finally { 
            this.writeLock.unlock();
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:readLock, writeLock
public class Node1OnlyBalancingStrategy implements FailoverRequestBalancingStrategy { 
 
    private static final Log log = LogFactory.getLog(Node1OnlyBalancingStrategy.class);
 
    private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
    private final Lock readLock = readWriteLock.readLock();
    private final Lock writeLock = readWriteLock.writeLock();
 
    private volatile InetSocketAddress[] servers;
 
    private static String host;
    private static int port = 11322;
    private static InetSocketAddress server;
 
    static { 
        host = System.getProperty("node1.ip", "localhost");
        server = new InetSocketAddress(host, port);
        if (log.isDebugEnabled())
            log.trace("node1 server = " + server);
    } 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:readLock
 */ 
public abstract class OSharedResourceAbstract { 
	protected final ReadWriteLock	lock	= new ReentrantReadWriteLock();
 
	protected void acquireSharedLock() { 
		lock.readLock().lock();
	} 
 
	protected void releaseSharedLock() { 
		lock.readLock().unlock();
	} 
 
	protected void acquireExclusiveLock() { 
		lock.writeLock().lock();
	} 
 
	protected void releaseExclusiveLock() { 
		lock.writeLock().unlock();
	} 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:writeLock
            closingLock.readLock().unlock();
        } 
    } 
 
    public void closeAllConnections() { 
        closingLock.writeLock().lock();
        try { 
            closed = true;
        } finally { 
            closingLock.writeLock().unlock();
        } 
        openConnections.close();
    } 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:readLock, writeLock
    public DoubleCheckedCreator() { 
        this(new ReentrantReadWriteLock());
    } 
 
    public DoubleCheckedCreator(ReadWriteLock readWriteLock) {
        Validate.notNull(readWriteLock, "readWriteLock can not be null");
        this.readWriteLock = readWriteLock;
        this.readLock = this.readWriteLock.readLock();
        this.writeLock = this.readWriteLock.writeLock();
    } 
 
    /** 
     * @param args Arguments to use when creating the object 
     * @return A newly created object 
     */ 
    protected abstract T create(Object... args); 
 
    /** 
     * @param args Arguments to use when retrieving the object 
     * @return An existing object if available 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:readLock, writeLock
public class Node0OnlyBalancingStrategy implements FailoverRequestBalancingStrategy { 
 
    private static final Log log = LogFactory.getLog(Node0OnlyBalancingStrategy.class);
 
    private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
    private final Lock readLock = readWriteLock.readLock();
    private final Lock writeLock = readWriteLock.writeLock();
 
    private volatile InetSocketAddress[] servers;
 
    private static String host;
    private static int port = 11222;
    private static InetSocketAddress server;
 
    static { 
        host = System.getProperty("node0.ip", "localhost");
        server = new InetSocketAddress(host, port);
        if (log.isDebugEnabled())
            log.trace("node0 server = " + server);
    } 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:readLock
    } 
    throw new OTimeoutException("Timeout on acquiring shared lock against resource: " + this);
  } 
 
  protected void releaseSharedLock() { 
    lock.readLock().unlock();
  } 
 
  protected void acquireExclusiveLock() throws OTimeoutException { 
    try { 
      if (timeout == 0) {
        lock.writeLock().lock();
        return; 
      } else if (lock.writeLock().tryLock(timeout, TimeUnit.MILLISECONDS))
        // OK 
        return; 
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    } 
    throw new OTimeoutException("Timeout on acquiring exclusive lock against resource: " + this);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 ReadWriteLock Questions & Answers:

See Code Examples for Java 8 ReadWriteLock Methods: