当前位置: 首页>>代码示例>>Java>>正文


Java ReadLock类代码示例

本文整理汇总了Java中java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock的典型用法代码示例。如果您正苦于以下问题:Java ReadLock类的具体用法?Java ReadLock怎么用?Java ReadLock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ReadLock类属于java.util.concurrent.locks.ReentrantReadWriteLock包,在下文中一共展示了ReadLock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getReader

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
@Override
public ContentReader getReader(String contentUrl) {
	if (logger.isDebugEnabled()) {
		logger.debug(String.format("Content Reader for %s", contentUrl));
	}

	// Use pool of locks - which one is determined by a hash of the URL.
	// This will stop the content from being read/cached multiple times from
	// the backing store
	// when it should only be read once - cached versions should be returned
	// after that.
	ReadLock readLock = readWriteLock(contentUrl).readLock();
	readLock.lock();
	try {
		return this.objectStorageService.getReader(contentUrl);
	} catch (IOException e) {
		logger.error(e.getMessage(), e);
	} finally {
		readLock.unlock();
	}

	return null;
}
 
开发者ID:jeci-sarl,项目名称:alfresco-object-storage-connectors,代码行数:24,代码来源:ObjectStorageContentStore.java

示例2: count

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:21,代码来源:InMemoryCacheStatistics.java

示例3: meanTime

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:21,代码来源:InMemoryCacheStatistics.java

示例4: hitMissRatio

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:22,代码来源:InMemoryCacheStatistics.java

示例5: numGets

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:22,代码来源:InMemoryCacheStatistics.java

示例6: allStats

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
@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();
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:20,代码来源:InMemoryCacheStatistics.java

示例7: getTokens

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
@RequestMapping("/get_token")
@ResponseBody
public TokenInfo getTokens(HttpServletRequest request, HttpServletResponse response)
        throws ClientProtocolException,
            IOException
{
    if (googleToken == null || googleToken.getIdToken() == null || googleToken.getRefreshToken() == null) {
        initialRedirect = request.getRequestURI().toString();
        response.sendRedirect(googleTokenRetriever.getAuthorizeUrl());
        return null;
    }

    ReadLock readLock = lock.readLock();
    try {
        readLock.lock();
        return new TokenInfo().withIdToken(googleToken.getIdToken())
                              .withRefreshToken(googleToken.getRefreshToken());
    } finally {
        readLock.unlock();
    }
}
 
开发者ID:coveo,项目名称:k8s-proxy,代码行数:22,代码来源:K8sReverseProxy.java

示例8: mutate

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
@Override
public void mutate(List<? extends Mutation> mutations) throws IOException {
  // Ensure that close() or flush() aren't current being called.
  ReadLock lock = mutationLock.readLock();
  lock.lock();
  try {
    if (closed) {
      throw new IllegalStateException("Cannot mutate when the BufferedMutator is closed.");
    }
    handleExceptions();
    for (Mutation mutation : mutations) {
      doMutation(mutation);
    }
  } finally {
    lock.unlock();
  }
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:18,代码来源:BigtableBufferedMutator.java

示例9: CacheScanner

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
/**
 * Instantiates a new scanner.
 *
 * @param cache the cache
 * @param scanNumber the scan number
 * @param totalScanners the total scanners
 */
public CacheScanner(OffHeapCache cache, int startIndex, int stopIndex, int dummy) {
	this.mCache = cache;

	this.mStride = OffHeapCache.getLockStripesCount();
	this.mLocks = mCache.getLocks();
	mInternalBuffer = new long[BUFFER_SIZE];
	this.mMemPointer = mCache.getMemPointer();

	this.mStartIndex = startIndex;
	this.mEndIndex = stopIndex;
	this.mCurrentIndex = mStartIndex;
	SpinReadWriteLock lock = mCache.getLock(mCurrentIndex);
	ReadLock readLock = lock.readLock();
	readLock.lock();
	try {
		// initialize current pointer
		mCurrentPtr = IOUtils.getLong(mMemPointer, mCurrentIndex * 8);
	} finally {
		readLock.unlock();
	}

}
 
开发者ID:VladRodionov,项目名称:bigbase,代码行数:30,代码来源:CacheScanner.java

示例10: execute

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
/**
 * Execute operation without in-memory data update.
 *
 * @param key the key
 * @param op the op
 * @return the for update
 * @throws NativeMemoryException the j emalloc exception
 * @throws IOException Signals that an I/O exception has occurred.
 */

public boolean execute(ByteBuffer key, Command<?> op) throws NativeMemoryException, IOException
{
	SpinReadWriteLock lock = getLockForKey(key);
	ReadLock readLock = null;
	if(lock != null){
		readLock = lock.readLock();
		readLock.lock();
	}
	try{
		return op.execute(key, this);
	}finally{
		if(readLock != null) readLock.unlock();
	}
	
}
 
开发者ID:VladRodionov,项目名称:bigbase,代码行数:26,代码来源:OffHeapCache.java

示例11: putIfAbsent

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
/**
 * Put if absent.
 *
 * @param key the key
 * @param value the value
 * @param expire the expire
 * @return the object
 * @throws NativeMemoryException the native memory exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private Object putIfAbsent(Object key, Object value, int expire) throws NativeMemoryException, IOException {
	SpinReadWriteLock lock = getLockForKey(key);
	ReadLock readLock = null;
	if(lock != null){
		readLock = lock.readLock();
		readLock.lock();
	}
	try{
		Object val = get(key);
		if(val != null){
			return val;
		} else{
			put(key, value, expire);
		}
	}finally{
		if(readLock != null) readLock.unlock();
	}
	return null;
}
 
开发者ID:VladRodionov,项目名称:bigbase,代码行数:30,代码来源:OffHeapCache.java

示例12: queryKeys

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
Set<Long> queryKeys(Filter filter) {
    if (closed) {
        throw new IllegalStateException("This db is closed.");
    }

    if (filter == null) {
        throw new NullPointerException("The filter parameter can not be null.");
    }

    ReadLock lock = readWriteLock.readLock();
    lock.lock();
    try {
        return rdb.queryKeys(filter);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:EagerLogic,项目名称:relational-entity-db,代码行数:18,代码来源:EntityDB.java

示例13: query

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
List<Entity> query(Filter filter) {
    if (closed) {
        throw new IllegalStateException("This db is closed.");
    }

    if (filter == null) {
        throw new NullPointerException("The filter parameter can not be null.");
    }

    ReadLock lock = readWriteLock.readLock();
    lock.lock();
    try {
        return rdb.query(filter);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:EagerLogic,项目名称:relational-entity-db,代码行数:18,代码来源:EntityDB.java

示例14: querySingleton

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
Entity querySingleton(Filter filter) {
    if (closed) {
        throw new IllegalStateException("This db is closed.");
    }

    if (filter == null) {
        throw new NullPointerException("The filter parameter can not be null.");
    }

    ReadLock lock = readWriteLock.readLock();
    lock.lock();
    try {
        return rdb.querySingleton(filter);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:EagerLogic,项目名称:relational-entity-db,代码行数:18,代码来源:EntityDB.java

示例15: queryFirst

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //导入依赖的package包/类
Entity queryFirst(Filter filter) {
    if (closed) {
        throw new IllegalStateException("This db is closed.");
    }

    if (filter == null) {
        throw new NullPointerException("The filter parameter can not be null.");
    }

    ReadLock lock = readWriteLock.readLock();
    lock.lock();
    try {
        return rdb.queryFirst(filter);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:EagerLogic,项目名称:relational-entity-db,代码行数:18,代码来源:EntityDB.java


注:本文中的java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。