@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()); } }
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; }
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(); }
/** * 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(); }
/** * 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(); }
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()); }
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()); }