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

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

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

ReentrantReadWriteLock.isWriteLockedByCurrentThread介绍

[英]Queries if the write lock is held by the current thread.
[中]查询写锁是否由当前线程持有。

代码示例

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

/**
 * Queries if the write lock is held by the current thread.
 *
 * @return {@code true} if the current thread holds the write lock and
 *         {@code false} otherwise
 */
public boolean isWriteLockedByCurrentThread() {
  return locks[locks.length - 1].isWriteLockedByCurrentThread();
}

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

private void assertCurrentThreadIsNotBlockingNewTransactions()
{
  if ( newTransactionsLock.isWriteLockedByCurrentThread() )
  {
    throw new IllegalStateException(
        "Thread that is blocking new transactions from starting can't start new transaction" );
  }
}

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

/** {@inheritDoc} */
@Override public boolean checkpointLockIsHeldByThread() {
  return !ASSERTION_ENABLED ||
    checkpointLock.isWriteLockedByCurrentThread() ||
    CHECKPOINT_LOCK_HOLD_COUNT.get() > 0 ||
    Thread.currentThread().getName().startsWith(CHECKPOINT_RUNNER_THREAD_PREFIX);
}

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

/**
 * Increment modification counter to force recompilation of existing prepared statements.
 */
private void incrementModificationCounter() {
  assert lock.isWriteLockedByCurrentThread();
  setModified();
}

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

/** {@inheritDoc} */
@Override public boolean holdsLock() {
  return lock.isWriteLockedByCurrentThread() || lock.getReadHoldCount() > 0;
}

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

private void supplyLookupSources()
  checkState(!lock.isWriteLockedByCurrentThread());

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

/**
 * @param stopError Error to shutdown resources.
 */
private void stopProcessor(IgniteCheckedException stopError) {
  assert opsLock.isWriteLockedByCurrentThread();
  depMgr.stopProcessing(stopError);
  cancelDeployedServices();
  registeredServices.clear();
  // If user requests sent to network but not received back to handle in deployment manager.
  Stream.concat(depFuts.values().stream(), undepFuts.values().stream()).forEach(fut -> {
    try {
      fut.onDone(stopError);
    }
    catch (Exception ignore) {
      // No-op.
    }
  });
  depFuts.clear();
  undepFuts.clear();
  if (log.isDebugEnabled())
    log.debug("Stopped service processor.");
}

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

/**
 * Cancels deployed services.
 */
private void cancelDeployedServices() {
  assert opsLock.isWriteLockedByCurrentThread();
  deployedServices.clear();
  locServices.values().stream().flatMap(Collection::stream).forEach(srvcCtx -> {
    cancel(srvcCtx);
    if (ctx.isStopping()) {
      try {
        if (log.isInfoEnabled()) {
          log.info("Shutting down distributed service [name=" + srvcCtx.name() + ", execId8=" +
            U.id8(srvcCtx.executionId()) + ']');
        }
        srvcCtx.executor().awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
      }
      catch (InterruptedException ignore) {
        Thread.currentThread().interrupt();
        U.error(log, "Got interrupted while waiting for service to shutdown (will continue " +
          "stopping node): " + srvcCtx.name());
      }
    }
  });
  locServices.clear();
}

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

/** {@inheritDoc} */
@Override public void onEvicted(GridDhtLocalPartition part, boolean updateSeq) {
  assert updateSeq || lock.isWriteLockedByCurrentThread();
  lock.writeLock().lock();
  try {
    if (stopping)
      return;
    assert part.state() == EVICTED;
    long seq = updateSeq ? this.updateSeq.incrementAndGet() : this.updateSeq.get();
    updateLocal(part.id(), cctx.localNodeId(), part.state(), seq);
    consistencyCheck();
  }
  finally {
    lock.writeLock().unlock();
  }
}

代码示例来源:origin: internetarchive/heritrix3

case RUN:
        while(outboundLock.isWriteLockedByCurrentThread()) {
          outboundLock.writeLock().unlock();
while(outboundLock.isWriteLockedByCurrentThread()) {
  outboundLock.writeLock().unlock();

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

assert lock.isWriteLockedByCurrentThread();
assert nodeId.equals(cctx.localNodeId());

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

/**
  * Tests {@link LockResource} with {@link ReentrantReadWriteLock}.
  */
 @Test
 public void reentrantReadWriteLock() {
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

  try (LockResource r1 = new LockResource(lock.readLock())) {
   try (LockResource r2 = new LockResource(lock.readLock())) {
    assertEquals(lock.getReadHoldCount(), 2);
    assertTrue(lock.readLock().tryLock());
    lock.readLock().unlock();
   }
  }
  assertEquals(lock.getReadHoldCount(), 0);

  try (LockResource r1 = new LockResource(lock.writeLock())) {
   try (LockResource r2 = new LockResource(lock.readLock())) {
    assertTrue(lock.isWriteLockedByCurrentThread());
    assertEquals(lock.getReadHoldCount(), 1);
   }
  }
  assertFalse(lock.isWriteLockedByCurrentThread());
  assertEquals(lock.getReadHoldCount(), 0);

  try (LockResource r = new LockResource(lock.readLock())) {
   assertFalse(lock.writeLock().tryLock());
  }
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

boolean hasWriteLock() {
 return this.dirLock.isWriteLockedByCurrentThread();
}

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

public boolean isWriteLockedByCurrentThread() {
 return coarseLock.isWriteLockedByCurrentThread();
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
public boolean isHeldByCurrentThread(LockType type) {
  switch (type) {
  case READ:
    throw new UnsupportedOperationException("Querying of read lock is not supported.");
  case WRITE:
    return lock.isWriteLockedByCurrentThread();
  default:
    throw new IllegalArgumentException("We don't support any other lock type than READ or WRITE!");
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
   * {@inheritDoc}
   */
  public boolean isHeldByCurrentThread(LockType type) {
    switch (type) {
      case READ:
        throw new UnsupportedOperationException("Querying of read lock is not supported.");
      case WRITE:
        return rrwl.isWriteLockedByCurrentThread();
      default:
        throw new IllegalArgumentException("We don't support any other lock type than READ or WRITE!");
    }
  }
}

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

private synchronized void close() throws IOException {
 if (!logIdLock.isWriteLockedByCurrentThread()) {
  throw new IllegalStateException("close should be called with write lock held!");
 }
 try {
  if (currentLog != null) {
   try {
    currentLog.close();
   } catch (DfsLogger.LogClosedException ex) {
    // ignore
   } catch (Throwable ex) {
    log.error("Unable to cleanly close log " + currentLog.getFileName() + ": " + ex, ex);
   } finally {
    this.tserver.walogClosed(currentLog);
   }
   currentLog = null;
   logSizeEstimate.set(0);
  }
 } catch (Throwable t) {
  throw new IOException(t);
 }
}

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

return;
final boolean writeLockHeld = rwLock.isWriteLockedByCurrentThread();
try {
 if (!writeLockHeld) {

代码示例来源:origin: org.elasticsearch/elasticsearch

protected final void closeNoLock(String reason, CountDownLatch closedLatch) {
  if (isClosed.compareAndSet(false, true)) {
    assert rwl.isWriteLockedByCurrentThread() || failEngineLock.isHeldByCurrentThread() :
      "Either the write lock must be held or the engine must be currently be failing itself";
    try {

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

.getWriteHoldCount() == 1 && coarseLock.isWriteLockedByCurrentThread();
final long currentTimeNanos = timer.monotonicNowNanos();
final long writeLockIntervalNanos =

相关文章