/** * Returns whether this monitor is occupied by any thread. This method is designed for use in * monitoring of the system state, not for synchronization control. */ public boolean isOccupied() { return lock.isLocked(); }
/** * Returns whether this monitor is occupied by any thread. This method is designed for use in * monitoring of the system state, not for synchronization control. */ public boolean isOccupied() { return lock.isLocked(); }
/** * Returns whether this monitor is occupied by any thread. This method is designed for use in * monitoring of the system state, not for synchronization control. */ public boolean isOccupied() { return lock.isLocked(); }
public int getNumLocked() { int retval=0; for(Lock lock: locks) if(((ReentrantLock)lock).isLocked()) retval++; return retval; }
/** * Returns whether this monitor is occupied by any thread. This method is designed for use in * monitoring of the system state, not for synchronization control. */ public boolean isOccupied() { return lock.isLocked(); }
@Override public boolean inUse() { return super.isLocked() || super.hasQueuedThreads(); }
/** * A wrapper method that makes a call to {@code isLocked()} of * the underlying {@code ReentrantLock} object. * * Queries if this lock is held by any thread. This method is * designed for use in monitoring of the system state, * not for synchronization control. * * @return {@code true} if any thread holds this lock and * {@code false} otherwise */ @VisibleForTesting boolean isLocked() { if (lock instanceof ReentrantLock) { return ((ReentrantLock)lock).isLocked(); } throw new UnsupportedOperationException(); }
@Override public boolean inUse() { return super.isLocked() || super.hasQueuedThreads(); }
assert (stateChangeLock.isLocked()); waitForAsyncReadComplete(); if (isEndOfStream()) {
assert (stateChangeLock.isLocked()); waitForAsyncReadComplete(); if (isEndOfStream()) {
@After public final void interruptStuckThreads() throws Exception { server1.invoke(() -> { if (stuckThread != null) { stuckThread.interrupt(); } stuckThread = null; }); server2.invoke(() -> { if (stuckThread != null) { stuckThread.interrupt(); } stuckThread = null; }); // Wait to allow the locks to be released to avoid environment pollution for tests that follow server1.invoke(() -> { await().until(() -> !LOCK.isLocked()); }); server2.invoke(() -> { await().until(() -> !LOCK.isLocked()); }); }
@VisibleForTesting boolean rollWriter(long logId) throws IOException { assert logId > flushLogId : "logId=" + logId + " flushLogId=" + flushLogId; assert lock.isHeldByCurrentThread() : "expected to be the lock owner. " + lock.isLocked();
/** * @return whether this lock has been acquired */ public boolean isLocked() { return _lock.isLocked(); }
private boolean isLocked() { return lock.isLocked(); }
public boolean isLocked() { return lock.isLocked(); }
if (loadFromUriLock.isLocked()) { L.d(LOG_WAITING_FOR_IMAGE_LOADED, memoryCacheKey);
@After public void tearDownAfterTest() throws IOException { for (RegionInfo region : UTIL.getAdmin().getRegions(TABLE_NAME)) { RegionStateNode regionNode = AM.getRegionStates().getRegionStateNode(region); // confirm that we have released the lock assertFalse(((ReentrantLock) regionNode.lock).isLocked()); TransitRegionStateProcedure proc = regionNode.getProcedure(); if (proc != null) { regionNode.unsetProcedure(proc); } } }
public static void main(String[] args) { ExecutorService executor = Executors.newFixedThreadPool(2); ReentrantLock lock = new ReentrantLock(); executor.submit(() -> { lock.lock(); try { ConcurrentUtils.sleep(1); } finally { lock.unlock(); } }); executor.submit(() -> { System.out.println("Locked: " + lock.isLocked()); System.out.println("Held by me: " + lock.isHeldByCurrentThread()); boolean locked = lock.tryLock(); System.out.println("Lock acquired: " + locked); }); ConcurrentUtils.stop(executor); }
@Override public void syncClass(Class<?> cls) { s_logger.debug("syncClass: " + cls.getName()); try { s_logger.debug("sync start: " + DBSyncGeneric.getClassName(cls)); _lockSyncMode.lock(); _dbSync.setSyncMode(DBSyncGeneric.SYNC_MODE_UPDATE); _dbSync.sync(cls); _lockSyncMode.unlock(); s_logger.debug("sync finish: " + DBSyncGeneric.getClassName(cls)); } catch (Exception ex) { s_logger.warn("Sync error: " + cls.getName(), ex); if (_lockSyncMode.isLocked()) { _lockSyncMode.unlock(); } } }
s_logger.warn("DB Synchronization", ex); syncState = SYNC_STATE_UNKNOWN; if (_lockSyncMode.isLocked()) { _lockSyncMode.unlock();