當前位置: 首頁>>代碼示例>>Java>>正文


Java ReadLock.lock方法代碼示例

本文整理匯總了Java中java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock.lock方法的典型用法代碼示例。如果您正苦於以下問題:Java ReadLock.lock方法的具體用法?Java ReadLock.lock怎麽用?Java ReadLock.lock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock的用法示例。


在下文中一共展示了ReadLock.lock方法的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: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: notifyListeners

import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; //導入方法依賴的package包/類
/**
 * Notifies all block listeners about either blocking or not blocking.
 *
 * @param block
 *          Whether the event is blocking or not.
 */
private void notifyListeners(final boolean block) {
  ReadLock readLock = blockListenersRWLock.readLock();
  readLock.lock();
  if (blocking != block) {
    blocking = block;
    for (ShutdownBlockListener blockListener : blockListeners) {
      if (block) {
        blockListener.block();
      } else {
        blockListener.unblock();
      }
    }
  }
  readLock.unlock();
}
 
開發者ID:everit-org,項目名稱:osgi-testrunner,代碼行數:22,代碼來源:AbstractShutdownBlocker.java


注:本文中的java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock.lock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。