Package java.util.concurrent.locks

Examples of java.util.concurrent.locks.ReentrantLock


   */
  public void enterWhenUninterruptibly(Guard guard) {
    if (guard.monitor != this) {
      throw new IllegalMonitorStateException();
    }
    final ReentrantLock lock = this.lock;
    boolean reentrant = lock.isHeldByCurrentThread();
    lock.lock();
    try {
      waitUninterruptibly(guard, reentrant);
    } catch (Throwable throwable) {
      lock.unlock();
      throw Throwables.propagate(throwable);
    }
  }
View Full Code Here


   */
  public boolean enterWhen(Guard guard, long time, TimeUnit unit) throws InterruptedException {
    if (guard.monitor != this) {
      throw new IllegalMonitorStateException();
    }
    final ReentrantLock lock = this.lock;
    boolean reentrant = lock.isHeldByCurrentThread();
    long startNanos = System.nanoTime();
    if (!lock.tryLock(time, unit)) {
      return false;
    }
    boolean satisfied;
    try {
      long remainingNanos = unit.toNanos(time) - (System.nanoTime() - startNanos);
      satisfied = waitInterruptibly(guard, remainingNanos, reentrant);
    } catch (Throwable throwable) {
      lock.unlock();
      throw Throwables.propagate(throwable);
    }
    if (satisfied) {
      return true;
    } else {
      lock.unlock();
      return false;
    }
  }
View Full Code Here

   */
  public boolean enterWhenUninterruptibly(Guard guard, long time, TimeUnit unit) {
    if (guard.monitor != this) {
      throw new IllegalMonitorStateException();
    }
    final ReentrantLock lock = this.lock;
    boolean reentrant = lock.isHeldByCurrentThread();
    long startNanos = System.nanoTime();
    long timeoutNanos = unit.toNanos(time);
    long remainingNanos = timeoutNanos;
    boolean interruptIgnored = false;
    try {
      while (true) {
        try {
          if (lock.tryLock(remainingNanos, TimeUnit.NANOSECONDS)) {
            break;
          } else {
            return false;
          }
        } catch (InterruptedException ignored) {
          interruptIgnored = true;
        } finally {
          remainingNanos = (timeoutNanos - (System.nanoTime() - startNanos));
        }
      }
      boolean satisfied;
      try {
        satisfied = waitUninterruptibly(guard, remainingNanos, reentrant);
      } catch (Throwable throwable) {
        lock.unlock();
        throw Throwables.propagate(throwable);
      }
      if (satisfied) {
        return true;
      } else {
        lock.unlock();
        return false;
      }
    } finally {
      if (interruptIgnored) {
        Thread.currentThread().interrupt();
View Full Code Here

   */
  public boolean enterIf(Guard guard) {
    if (guard.monitor != this) {
      throw new IllegalMonitorStateException();
    }
    final ReentrantLock lock = this.lock;
    lock.lock();
    boolean satisfied;
    try {
      satisfied = guard.isSatisfied();
    } catch (Throwable throwable) {
      lock.unlock();
      throw Throwables.propagate(throwable);
    }
    if (satisfied) {
      return true;
    } else {
      lock.unlock();
      return false;
    }
  }
View Full Code Here

   */
  public boolean enterIfInterruptibly(Guard guard) throws InterruptedException {
    if (guard.monitor != this) {
      throw new IllegalMonitorStateException();
    }
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    boolean satisfied;
    try {
      satisfied = guard.isSatisfied();
    } catch (Throwable throwable) {
      lock.unlock();
      throw Throwables.propagate(throwable);
    }
    if (satisfied) {
      return true;
    } else {
      lock.unlock();
      return false;
    }
  }
View Full Code Here

   */
  public boolean enterIf(Guard guard, long time, TimeUnit unit) {
    if (guard.monitor != this) {
      throw new IllegalMonitorStateException();
    }
    final ReentrantLock lock = this.lock;
    if (!enter(time, unit)) {
      return false;
    }
    boolean satisfied;
    try {
      satisfied = guard.isSatisfied();
    } catch (Throwable throwable) {
      lock.unlock();
      throw Throwables.propagate(throwable);
    }
    if (satisfied) {
      return true;
    } else {
      lock.unlock();
      return false;
    }
  }
View Full Code Here

  public boolean enterIfInterruptibly(Guard guard, long time, TimeUnit unit)
      throws InterruptedException {
    if (guard.monitor != this) {
      throw new IllegalMonitorStateException();
    }
    final ReentrantLock lock = this.lock;
    if (!lock.tryLock(time, unit)) {
      return false;
    }
    boolean satisfied;
    try {
      satisfied = guard.isSatisfied();
    } catch (Throwable throwable) {
      lock.unlock();
      throw Throwables.propagate(throwable);
    }
    if (satisfied) {
      return true;
    } else {
      lock.unlock();
      return false;
    }
  }
View Full Code Here

   */
  public boolean tryEnterIf(Guard guard) {
    if (guard.monitor != this) {
      throw new IllegalMonitorStateException();
    }
    final ReentrantLock lock = this.lock;
    if (!lock.tryLock()) {
      return false;
    }
    boolean satisfied;
    try {
      satisfied = guard.isSatisfied();
    } catch (Throwable throwable) {
      lock.unlock();
      throw Throwables.propagate(throwable);
    }
    if (satisfied) {
      return true;
    } else {
      lock.unlock();
      return false;
    }
  }
View Full Code Here

  /**
   * Leaves this monitor. May be called only by a thread currently occupying this monitor.
   */
  @GuardedBy("lock")
  public void leave() {
    final ReentrantLock lock = this.lock;
    if (!lock.isHeldByCurrentThread()) {
      throw new IllegalMonitorStateException();
    }
    try {
      signalConditionsOfSatisfiedGuards(null);
    } finally {
      lock.unlock();
    }
  }
View Full Code Here

   *
   * <p>This never needs to be called by a thread occupying the monitor, because all other monitor
   * methods ensure that all guards are evaluated whenever necessary.
   */
  public void reevaluateGuards() {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
      signalConditionsOfSatisfiedGuards(null);
    } finally {
      lock.unlock();
    }
  }
View Full Code Here

TOP

Related Classes of java.util.concurrent.locks.ReentrantLock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.