Package java.util.concurrent.locks

Examples of java.util.concurrent.locks.ReentrantLock.tryLock()


     * If lock is available, poll stale refs and remove them.
     * Called from ForkJoinPool when pools become quiescent.
     */
    static final void helpExpungeStaleExceptions() {
        final ReentrantLock lock = exceptionTableLock;
        if (lock.tryLock()) {
            try {
                expungeStaleExceptions();
            } finally {
                lock.unlock();
            }
View Full Code Here


     * If lock is available, poll stale refs and remove them.
     * Called from ForkJoinPool when pools become quiescent.
     */
    static final void helpExpungeStaleExceptions() {
        final ReentrantLock lock = exceptionTableLock;
        if (lock.tryLock()) {
            try {
                expungeStaleExceptions();
            } finally {
                lock.unlock();
            }
View Full Code Here

   *
   * @return whether the monitor was entered
   */
  public boolean enter(long time, TimeUnit unit) {
    final ReentrantLock lock = this.lock;
    if (!fair && lock.tryLock()) {
      return true;
    }
    long startNanos = System.nanoTime();
    long timeoutNanos = unit.toNanos(time);
    long remainingNanos = timeoutNanos;
View Full Code Here

    long remainingNanos = timeoutNanos;
    boolean interruptIgnored = false;
    try {
      while (true) {
        try {
          return lock.tryLock(remainingNanos, TimeUnit.NANOSECONDS);
        } catch (InterruptedException ignored) {
          interruptIgnored = true;
          remainingNanos = (timeoutNanos - (System.nanoTime() - startNanos));
        }
      }
View Full Code Here

      throw new IllegalMonitorStateException();
    }
    final ReentrantLock lock = this.lock;
    boolean reentrant = lock.isHeldByCurrentThread();
    long remainingNanos;
    if (!fair && lock.tryLock()) {
      remainingNanos = unit.toNanos(time);
    } else {
      long startNanos = System.nanoTime();
      if (!lock.tryLock(time, unit)) {
        return false;
View Full Code Here

    long remainingNanos;
    if (!fair && lock.tryLock()) {
      remainingNanos = unit.toNanos(time);
    } else {
      long startNanos = System.nanoTime();
      if (!lock.tryLock(time, unit)) {
        return false;
      }
      remainingNanos = unit.toNanos(time) - (System.nanoTime() - startNanos);
    }
    boolean satisfied = false;
View Full Code Here

    final ReentrantLock lock = this.lock;
    boolean reentrant = lock.isHeldByCurrentThread();
    boolean interruptIgnored = false;
    try {
      long remainingNanos;
      if (!fair && lock.tryLock()) {
        remainingNanos = unit.toNanos(time);
      } else {
        long startNanos = System.nanoTime();
        long timeoutNanos = unit.toNanos(time);
        remainingNanos = timeoutNanos;
View Full Code Here

        long startNanos = System.nanoTime();
        long timeoutNanos = unit.toNanos(time);
        remainingNanos = timeoutNanos;
        while (true) {
          try {
            if (lock.tryLock(remainingNanos, TimeUnit.NANOSECONDS)) {
              break;
            } else {
              return false;
            }
          } catch (InterruptedException ignored) {
View Full Code Here

      throws InterruptedException {
    if (guard.monitor != this) {
      throw new IllegalMonitorStateException();
    }
    final ReentrantLock lock = this.lock;
    if (!lock.tryLock(time, unit)) {
      return false;
    }
    boolean satisfied = false;
    try {
      satisfied = guard.isSatisfied();
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 = false;
    try {
      satisfied = guard.isSatisfied();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.