java.util.concurrent.locks.ReentrantReadWriteLock.readLock()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中java.util.concurrent.locks.ReentrantReadWriteLock.readLock方法的一些代码示例,展示了ReentrantReadWriteLock.readLock的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReentrantReadWriteLock.readLock方法的具体详情如下:
包路径:java.util.concurrent.locks.ReentrantReadWriteLock
类名称:ReentrantReadWriteLock
方法名:readLock

ReentrantReadWriteLock.readLock介绍

暂无

代码示例

代码示例来源:origin: alibaba/druid

public JdbcSqlStat getSqlStat(String sql) {
  lock.readLock().lock();
  try {
    return sqlStatMap.get(sql);
  } finally {
    lock.readLock().unlock();
  }
}

代码示例来源:origin: apache/hbase

public FileArchiverNotifierImpl(
  Connection conn, Configuration conf, FileSystem fs, TableName tn) {
 this.conn = conn;
 this.conf = conf;
 this.fs = fs;
 this.tn = tn;
 ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
 readLock = lock.readLock();
 writeLock = lock.writeLock();
}

代码示例来源:origin: apache/ignite

/**
 * Release table lock.
 *
 * @param exclusive Exclusive flag.
 */
private void unlock(boolean exclusive) {
  Lock l = exclusive ? lock.writeLock() : lock.readLock();
  l.unlock();
}

代码示例来源:origin: apache/incubator-druid

public String getMaxValue()
{
 lock.readLock().lock();
 try {
  return maxValue;
 }
 finally {
  lock.readLock().unlock();
 }
}

代码示例来源:origin: apache/incubator-pinot

public RealtimeInvertedIndexReader() {
 ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
 _readLock = readWriteLock.readLock();
 _writeLock = readWriteLock.writeLock();
}

代码示例来源:origin: apache/incubator-druid

public String getMinValue()
{
 lock.readLock().lock();
 try {
  return minValue;
 }
 finally {
  lock.readLock().unlock();
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Returns the Input/Output metadata for this step. By default, each step produces and accepts optional input.
 */
public StepIOMetaInterface getStepIOMeta( boolean createIfAbsent ) {
 StepIOMetaInterface ioMeta = null;
 lock.readLock().lock();
 try {
  if ( ( ioMetaVar == null ) && ( createIfAbsent ) ) {
   ioMeta = new StepIOMeta( true, true, true, false, false, false );
   lock.readLock().unlock();
   lock.writeLock().lock();
   try {
    ioMetaVar = ioMeta;
    lock.readLock().lock(); // downgrade to read lock before releasing write lock
   } finally {
    lock.writeLock().unlock();
   }
  } else {
   ioMeta = ioMetaVar;
  }
  return ioMeta;
 } finally {
  lock.readLock().unlock();
 }
}

代码示例来源:origin: alibaba/druid

public Map<String, JdbcSqlStat> getSqlStatMap() {
  Map<String, JdbcSqlStat> map = new LinkedHashMap<String, JdbcSqlStat>(sqlStatMap.size());
  lock.readLock().lock();
  try {
    map.putAll(sqlStatMap);
  } finally {
    lock.readLock().unlock();
  }
  return map;
}

代码示例来源:origin: apache/hbase

/**
 * Closes the lock. This needs to be called in the finally block corresponding
 * to the try block of #startRegionOperation
 */
private void closeBulkRegionOperation(){
 if (lock.writeLock().isHeldByCurrentThread()) lock.writeLock().unlock();
 else lock.readLock().unlock();
}

代码示例来源:origin: apache/incubator-druid

public boolean isEmpty()
{
 try {
  lock.readLock().lock();
  return completePartitionsTimeline.isEmpty();
 }
 finally {
  lock.readLock().unlock();
 }
}

代码示例来源:origin: oracle/helidon

void subscribe() {
  try {
    subscriberLock.readLock().lock();
    if (subscriber == null) {
      subscriberLock.readLock().unlock();
      subscriberLock.writeLock().lock();
      try {
        try {
          if (subscriber == null) {
            waitForSubscription(1, TimeUnit.SECONDS);
          }
        } finally {
          subscriberLock.readLock().lock();
        }
      } finally {
        subscriberLock.writeLock().unlock();
      }
    }
  } finally {
    subscriberLock.readLock().unlock();
  }
}

代码示例来源:origin: apache/incubator-druid

public int size()
{
 lock.readLock().lock();
 try {
  // using idToValue rather than valueToId because the valueToId doesn't account null value, if it is present.
  return idToValue.size();
 }
 finally {
  lock.readLock().unlock();
 }
}

代码示例来源:origin: deeplearning4j/nd4j

protected static boolean isEligible(String message) {
  try {
    lock.readLock().lock();
    if (hashSet.contains(message))
      return false;
  } finally {
    lock.readLock().unlock();
  }
  try {
    lock.writeLock().lock();
    if (buffer.size() >= 100) {
      String rem = buffer.remove();
      hashSet.remove(rem);
    }
    buffer.add(message);
    hashSet.add(message);
    return true;
  } finally {
    lock.writeLock().unlock();
  }
}

代码示例来源:origin: neo4j/neo4j

private LockingIndexUpdater( IndexUpdater delegate )
{
  super( delegate );
  lock.readLock().lock();
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Creates a new instance of {@link MountTable}.
 *
 * @param ufsManager the UFS manager
 * @param rootMountInfo root mount info
 */
public MountTable(UfsManager ufsManager, MountInfo rootMountInfo) {
 mState = new State(rootMountInfo);
 ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
 mReadLock = lock.readLock();
 mWriteLock = lock.writeLock();
 mUfsManager = ufsManager;
}

代码示例来源:origin: alibaba/druid

public WallSqlStat getBlackSql(String sql) {
  lock.readLock().lock();
  try {
    if (blackList == null) {
      return null;
    }
    return blackList.get(sql);
  } finally {
    lock.readLock().unlock();
  }
}

代码示例来源:origin: apache/activemq

usageLock.readLock().lock();
try {
  if (percentUsage >= 100) {
    usageLock.readLock().unlock();
    usageLock.writeLock().lock();
    try {
      while (percentUsage >= 100 ) {
        waitForSpaceCondition.await(timeout, TimeUnit.MILLISECONDS);
      usageLock.readLock().lock();
    } finally {
      usageLock.writeLock().unlock();
  usageLock.readLock().unlock();

代码示例来源:origin: prestodb/presto

private SpilledLookupSourceHandle getSpilledLookupSourceHandle(int partitionNumber)
{
  lock.readLock().lock();
  try {
    return requireNonNull(spilledPartitions.get(partitionNumber), "spilledPartitions.get(partitionNumber) is null");
  }
  finally {
    lock.readLock().unlock();
  }
}

代码示例来源:origin: apache/shiro

public DefaultEventBus() {
  this.registry = new LinkedHashMap<Object, Subscription>(); //not thread safe, so we need locks:
  ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
  this.registryReadLock = rwl.readLock();
  this.registryWriteLock = rwl.writeLock();
  this.eventListenerResolver = new AnnotationEventListenerResolver();
}

代码示例来源:origin: apache/incubator-druid

public String getValue(int id)
{
 lock.readLock().lock();
 try {
  if (id == idForNull) {
   return null;
  }
  return idToValue.get(id);
 }
 finally {
  lock.readLock().unlock();
 }
}

相关文章