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

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

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

ReentrantLock.toString介绍

[英]Returns a string identifying this lock, as well as its lock state. The state, in brackets, includes either the String "Unlocked"or the String "Locked by" followed by the Thread#getName of the owning thread.
[中]返回标识此锁及其锁状态的字符串。括号中的状态包括字符串“Unlocked”或字符串“Locked by”,后跟所属线程的线程#getName。

代码示例

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

@Override
public void onApplicationEvent(HttpSessionDestroyedEvent event) {
  ReentrantLock lock = SESSION_LOCKS.remove(event.getSession().getId());
  if (lock != null && LOG.isDebugEnabled()) {
    LOG.debug("Destroyed lock due to session invalidation: " + lock.toString());
  }
}

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

protected ReentrantLock getSessionLock() {
  if (!isActive()) {
    throw new IllegalStateException("This is currently a sessionless environment and session cannot be used " +
        "to obtain a lock. Consider using a different implementation of OrderLockManager.");
  }
  HttpSession session = getRequest().getSession();
  ReentrantLock lock = SESSION_LOCKS.get(session.getId());
  if (lock == null) {
    // There was no session lock object. We'll need to create one. To do this, we have to synchronize the
    // creation globally, so that two threads don't create the session lock at the same time.
    synchronized (LOCK) {
      lock = SESSION_LOCKS.get(session.getId());
      if (lock == null) {
        lock = new ReentrantLock();
        SESSION_LOCKS.put(session.getId(), lock);
      }
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug("Created new lock object: " + lock.toString());
    }
  } else {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Returning previously created lock object: " + lock.toString());
    }
  }
  return lock;
}

代码示例来源:origin: ben-manes/caffeine

private void status() {
 int drainStatus;
 int pendingWrites;
 local.evictionLock.lock();
 try {
  pendingWrites = local.writeBuffer().size();
  drainStatus = local.drainStatus();
 } finally {
  local.evictionLock.unlock();
 }
 LocalTime elapsedTime = LocalTime.ofSecondOfDay(stopwatch.elapsed(TimeUnit.SECONDS));
 System.out.printf("---------- %s ----------%n", elapsedTime);
 System.out.printf("Pending reads: %,d; writes: %,d%n", local.readBuffer.size(), pendingWrites);
 System.out.printf("Drain status = %s (%s)%n", STATUS[drainStatus], drainStatus);
 System.out.printf("Evictions = %,d%n", cache.stats().evictionCount());
 System.out.printf("Size = %,d (max: %,d)%n", local.data.mappingCount(), operation.maxEntries);
 System.out.printf("Lock = [%s%n", StringUtils.substringAfter(
   local.evictionLock.toString(), "["));
 System.out.printf("Pending tasks = %,d%n",
   ForkJoinPool.commonPool().getQueuedSubmissionCount());
 long maxMemory = Runtime.getRuntime().maxMemory();
 long freeMemory = Runtime.getRuntime().freeMemory();
 long allocatedMemory = Runtime.getRuntime().totalMemory();
 System.out.printf("Max Memory = %,d bytes%n", maxMemory);
 System.out.printf("Free Memory = %,d bytes%n", freeMemory);
 System.out.printf("Allocated Memory = %,d bytes%n", allocatedMemory);
 System.out.println();
}

代码示例来源:origin: OpenHFT/Chronicle-Core

/**
 * Log the stack trace of the thread holding a lock.
 *
 * @param lock to log
 * @return the lock.toString plus a stack trace.
 */
public static String lockWithStack(@NotNull ReentrantLock lock) {
  @Nullable Thread t = getValue(lock, "sync/exclusiveOwnerThread");
  if (t == null) {
    return lock.toString();
  }
  @NotNull StringBuilder ret = new StringBuilder();
  ret.append(lock).append(" running at");
  trimStackTrace(ret, t.getStackTrace());
  return ret.toString();
}

代码示例来源:origin: net.openhft/chronicle-core

/**
 * Log the stack trace of the thread holding a lock.
 *
 * @param lock to log
 * @return the lock.toString plus a stack trace.
 */
public static String lockWithStack(@NotNull ReentrantLock lock) {
  @Nullable Thread t = getValue(lock, "sync/exclusiveOwnerThread");
  if (t == null) {
    return lock.toString();
  }
  @NotNull StringBuilder ret = new StringBuilder();
  ret.append(lock).append(" running at");
  trimStackTrace(ret, t.getStackTrace());
  return ret.toString();
}

代码示例来源:origin: com.hubspot/BaragonCore

public LockTimeoutException(String message, ReentrantLock agentLock) {
 super(message);
 this.lockInfo = String.format("LockState: %s, Queue Length: %s, Hold Count: %s", agentLock.toString(), agentLock.getQueueLength(), agentLock.getHoldCount());
}

代码示例来源:origin: HubSpot/Baragon

public LockTimeoutException(String message, ReentrantLock agentLock) {
 super(message);
 this.lockInfo = String.format("LockState: %s, Queue Length: %s, Hold Count: %s", agentLock.toString(), agentLock.getQueueLength(), agentLock.getHoldCount());
}

相关文章