java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock Java Examples

The following examples show how to use java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InMemoryCacheStatistics.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Map<OpType, OperationStats> allStats(String cacheName)
{
    ReadLock readLock = getReadLock(cacheName);
    readLock.lock();
    try
    {
        Map<OpType, OperationStats> cacheStats = cacheToStatsMap.get(cacheName);
        if (cacheStats == null)
        {
            throw new NoStatsForCache(cacheName);
        }
        return new HashMap<>(cacheStats);
    }
    finally
    {
        readLock.unlock();
    }
}
 
Example #2
Source File: InMemoryCacheStatistics.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public long count(String cacheName, OpType opType)
{
    ReadLock readLock = getReadLock(cacheName);
    readLock.lock();
    try
    {
        Map<OpType, OperationStats> cacheStats = cacheToStatsMap.get(cacheName);
        if (cacheStats == null)
        {
            throw new NoStatsForCache(cacheName);
        }
        OperationStats opStats = cacheStats.get(opType);
        return opStats.getCount();
    }
    finally
    {
        readLock.unlock();
    }
}
 
Example #3
Source File: InMemoryCacheStatistics.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public double meanTime(String cacheName, OpType opType)
{
    ReadLock readLock = getReadLock(cacheName);
    readLock.lock();
    try
    {
        Map<OpType, OperationStats> cacheStats = cacheToStatsMap.get(cacheName);
        if (cacheStats == null)
        {
            throw new NoStatsForCache(cacheName);
        }
        OperationStats opStats = cacheStats.get(opType);
        return opStats.meanTime();
    }
    finally
    {
        readLock.unlock();
    }
}
 
Example #4
Source File: InMemoryCacheStatistics.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public double hitMissRatio(String cacheName)
{
    ReadLock readLock = getReadLock(cacheName);
    readLock.lock();
    try
    {
        Map<OpType, OperationStats> cacheStats = cacheToStatsMap.get(cacheName);
        if (cacheStats == null)
        {
            throw new NoStatsForCache(cacheName);
        }
        long hits = cacheStats.get(OpType.GET_HIT).getCount();
        long misses = cacheStats.get(OpType.GET_MISS).getCount();
        return (double)hits / (hits+misses);
    }
    finally
    {
        readLock.unlock();
    }
}
 
Example #5
Source File: InMemoryCacheStatistics.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public long numGets(String cacheName)
{
    ReadLock readLock = getReadLock(cacheName);
    readLock.lock();
    try
    {
        Map<OpType, OperationStats> cacheStats = cacheToStatsMap.get(cacheName);
        if (cacheStats == null)
        {
            throw new NoStatsForCache(cacheName);
        }
        long hits = cacheStats.get(OpType.GET_HIT).getCount();
        long misses = cacheStats.get(OpType.GET_MISS).getCount();
        return hits+misses;
    }
    finally
    {
        readLock.unlock();
    }
}
 
Example #6
Source File: FlashPolicyServerStarter.java    From t-io with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

	while (true) {
		try {
			Thread.sleep(10 * 1000);
		} catch (InterruptedException e1) {
			log.error(e1.toString(), e1);
		}

		SetWithLock<ChannelContext> setWithLock = serverTioConfig.connections;
		Set<ChannelContext> set = null;
		ReadLock readLock = setWithLock.readLock();
		readLock.lock();
		try {
			long now = SystemTimer.currTime;
			set = setWithLock.getObj();
			for (ChannelContext channelContext : set) {
				long interval = (now - channelContext.stat.timeFirstConnected);
				if (interval > 5000) {
					Tio.remove(channelContext, "已经连上来有" + interval + "ms了,该断开啦");
				}
			}
		} catch (java.lang.Throwable e) {
			log.error("", e);
		} finally {
			readLock.unlock();
		}
	}
}
 
Example #7
Source File: PoolUtils.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumActive() {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return pool.getNumActive();
    } finally {
        readLock.unlock();
    }
}
 
Example #8
Source File: ConcurrentCountingMap.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
/** Gets the value of the counter associated with a given key.
 *
 * @param array a byte array.
 * @param offset the first valid byte in {@code array}.
 * @param length the number of valid elements in {@code array}.
 * @return the current value of the counter associated with the specified key.
 */
public int get(final byte[] array, final int offset, final int length) {
	final long hash = MurmurHash3.hash(array, offset, length);
	final ReadLock readLock = lock[(int)(hash >>> shift)].readLock();
	try {
		readLock.lock();
		return stripe[(int)(hash >>> shift)].get(array, offset, length, hash);
	}
	finally {
		readLock.unlock();
	}
}
 
Example #9
Source File: Document.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 5 votes vote down vote up
public IAutoCloseable lockForReading()
{
	// assume _lock is not null
	final ReadLock readLock = _lock.readLock();
	logger.debug("Acquiring read lock for {}: {}", this, readLock);
	readLock.lock();
	logger.debug("Acquired read lock for {}: {}", this, readLock);

	return () -> {
		readLock.unlock();
		logger.debug("Released read lock for {}: {}", this, readLock);
	};
}
 
Example #10
Source File: ADProcessInstanceController.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 5 votes vote down vote up
IAutoCloseable lockForReading()
{
	final ReadLock readLock = readwriteLock.readLock();
	logger.debug("Acquiring read lock for {}: {}", this, readLock);
	readLock.lock();
	logger.debug("Acquired read lock for {}: {}", this, readLock);

	return () -> {
		readLock.unlock();
		logger.debug("Released read lock for {}: {}", this, readLock);
	};
}
 
Example #11
Source File: ASIDocument.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 5 votes vote down vote up
IAutoCloseable lockForReading()
{
	// assume _lock is not null
	final ReadLock readLock = _lock.readLock();
	logger.debug("Acquiring read lock for {}: {}", this, readLock);
	readLock.lock();
	logger.debug("Acquired read lock for {}: {}", this, readLock);

	return () -> {
		readLock.unlock();
		logger.debug("Released read lock for {}: {}", this, readLock);
	};
}
 
Example #12
Source File: QuickInput.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 5 votes vote down vote up
public IAutoCloseable lockForReading()
{
	final ReadLock readLock = readwriteLock.readLock();
	logger.debug("Acquiring read lock for {}: {}", this, readLock);
	readLock.lock();
	logger.debug("Acquired read lock for {}: {}", this, readLock);

	return () -> {
		readLock.unlock();
		logger.debug("Released read lock for {}: {}", this, readLock);
	};
}
 
Example #13
Source File: Bug3019763.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@NoWarning("UL_UNRELEASED_LOCK")
public void doTestA() {
    ReadLock readLock = rwLock.readLock();
    readLock.lock();

    System.out.println("testing");

}
 
Example #14
Source File: Bug3019763.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@ExpectWarning("UL_UNRELEASED_LOCK_EXCEPTION_PATH")
public void doTest2A() {
    ReadLock readLock = rwLock.readLock();
    readLock.lock();

    System.out.println("testing");
    readLock.unlock();

}
 
Example #15
Source File: Bug3019763.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@ExpectWarning("UL_UNRELEASED_LOCK")
public void doTest2A(boolean b) {
    ReadLock readLock = rwLock.readLock();
    readLock.lock();

    if (b)
        return;
    System.out.println("testing");
    readLock.unlock();

}
 
Example #16
Source File: Bug3019763.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@ExpectWarning("UL_UNRELEASED_LOCK_EXCEPTION_PATH")
public void doTest2A(OutputStream o) throws IOException {
    ReadLock readLock = rwLock.readLock();
    readLock.lock();

    o.write(0);
    readLock.unlock();

}
 
Example #17
Source File: UsingExplicitReadWriteLocks.java    From banyan with MIT License 5 votes vote down vote up
/**
 * Simplest way to use the read mode
 *
 * @return
 */
public String showContent() {
    ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        System.out.println("Reading state while holding a lock.");
        return myContent;
    } finally {
        readLock.unlock();
    }
}
 
Example #18
Source File: PoolUtils.java    From commons-pool with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumIdle() {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return pool.getNumIdle();
    } finally {
        readLock.unlock();
    }
}
 
Example #19
Source File: PoolUtils.java    From commons-pool with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumActive() {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return pool.getNumActive();
    } finally {
        readLock.unlock();
    }
}
 
Example #20
Source File: PoolUtils.java    From commons-pool with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumIdle(final K key) {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return keyedPool.getNumIdle(key);
    } finally {
        readLock.unlock();
    }
}
 
Example #21
Source File: PoolUtils.java    From commons-pool with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumActive(final K key) {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return keyedPool.getNumActive(key);
    } finally {
        readLock.unlock();
    }
}
 
Example #22
Source File: PoolUtils.java    From commons-pool with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumIdle() {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return keyedPool.getNumIdle();
    } finally {
        readLock.unlock();
    }
}
 
Example #23
Source File: PoolUtils.java    From commons-pool with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumActive() {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return keyedPool.getNumActive();
    } finally {
        readLock.unlock();
    }
}
 
Example #24
Source File: ListWithLock.java    From t-io with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @return
 * @author tanyaowu
 */
public int size() {
	ReadLock readLock = this.readLock();
	readLock.lock();
	try {
		List<T> list = this.getObj();
		return list.size();
	} finally {
		readLock.unlock();
	}
}
 
Example #25
Source File: PoolUtils.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumIdle() {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return pool.getNumIdle();
    } finally {
        readLock.unlock();
    }
}
 
Example #26
Source File: PoolUtils.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumIdle(final K key) {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return keyedPool.getNumIdle(key);
    } finally {
        readLock.unlock();
    }
}
 
Example #27
Source File: PoolUtils.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumActive(final K key) {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return keyedPool.getNumActive(key);
    } finally {
        readLock.unlock();
    }
}
 
Example #28
Source File: PoolUtils.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumIdle() {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return keyedPool.getNumIdle();
    } finally {
        readLock.unlock();
    }
}
 
Example #29
Source File: PoolUtils.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getNumActive() {
    final ReadLock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        return keyedPool.getNumActive();
    } finally {
        readLock.unlock();
    }
}
 
Example #30
Source File: UsingExplicitReadWriteLocks.java    From java-concurrency-patterns with MIT License 5 votes vote down vote up
/**
 * Simplest way to use the read mode
 * 
 * @return
 */
public String showContent() {
	ReadLock readLock = readWriteLock.readLock();
	readLock.lock();
	try {
		System.out.println("Reading state while holding a lock.");
		return myContent;
	} finally {
		readLock.unlock();
	}
}