private void doStepLocked(int pass, FeatureOutcomePair next, StochasticCostFunction costFunction, boolean verbose) { Lock writeLock = lock.asWriteLock(); try { writeLock.lock(); doStep(pass, next, costFunction, verbose); } finally { writeLock.unlock(); } }
@Override public void lock(@Nonnull final DocumentReference document) { try { final Lock lock = this.locks.computeIfAbsent(document, k -> new StampedLock().asWriteLock()); final boolean cleanLock = lock.tryLock(10, TimeUnit.SECONDS); if (!cleanLock) { this.logger.debug("Timed out while waiting for lock on [{}], proceeding anyway", document); } } catch (InterruptedException ex) { // We don't expect any interruptions this.logger.error("Unexpected interruption while waiting for lock: {}", ex.getMessage(), ex); } }
/** * Attempts to release the write lock. * <p>If the current thread is the holder of this lock then * the {@code reentrantWriterCount} is decremented. If {@code * reentrantWriterCount} is now zero then the lock is released. * If the current thread is not the holder of this lock then {@link * IllegalMonitorStateException} is thrown. * * @throws IllegalMonitorStateException if the current thread does not * hold this lock. */ public void exclusiveUnlock() { if (!stampedLock.isWriteLocked()) { // ERROR: tried to unlock a non write-locked instance throw new IllegalMonitorStateException(); } stampedLock.asWriteLock().unlock(); }
protected AbstractRegistrationTree() { final StampedLock lock = new StampedLock(); readLock = lock.asReadLock(); writeLock = lock.asWriteLock(); }
if (readerState != null && readerState.get() == SRWL_STATE_READING) { stampedLock.asWriteLock().unlock(); return false;
} else { stampedLock.asWriteLock().unlock(); return false;
lockAcquired = checkpointLock.asWriteLock().tryLock(CHECKPOINT_LOCK_WRITE_TIMEOUT, TimeUnit.SECONDS); } catch (InterruptedException err) { throw new DataStorageManagerException("interrupted while waiting for checkpoint lock", err); checkpointLock.asWriteLock().unlock();