Package java.util.concurrent.locks

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


      log.tracef("About to acquire global lock. Exclusive? %s", exclusive);
      boolean success = true;
      for (int i = 0; i < sharedLocks.length; i++) {
         Lock toAcquire = exclusive ? sharedLocks[i].writeLock() : sharedLocks[i].readLock();
         try {
            success = toAcquire.tryLock(timeout, TimeUnit.MILLISECONDS);
            if (!success) {
               if (trace) log.tracef("Could not acquire lock on %s. Exclusive? %b", toAcquire, exclusive);
               break;
            }
         } catch (InterruptedException e) {
View Full Code Here


        for (final Session session : current) {

            final Lock l = session.lock;

            if (l.tryLock()) {
                try {
                    if (now - session.lastRequest.get() > this.timeout) {

                        backlog--;
View Full Code Here

        for (final Session session : current) {

            final Lock l = session.lock;

            if (l.tryLock()) {
                try {
                    session.close();
                } catch (Throwable e) {
                    //Ignore
                } finally {
View Full Code Here

   }

   public void acquireProcessingLock(boolean exclusive, long timeout, TimeUnit timeUnit) throws TimeoutException {
      Lock lock = exclusive ? processingLock.writeLock() : processingLock.readLock();
      try {
         if (!lock.tryLock(timeout, timeUnit)) {
            if (exclusive) log.debugf("Failed to acquire exclusive processing lock. Read lock holders are %s", debugReadLockHolders);
            throw new TimeoutException(format("%s could not obtain %s processing lock after %s.  Locks in question are %s and %s",
                  currentThread().getName(), exclusive ? "exclusive" : "shared", prettyPrintTime(timeout, timeUnit),
                  processingLock.readLock(), processingLock.writeLock()));
         }
View Full Code Here

   public boolean aquireGlobalLock(boolean exclusive, long timeout) {
      boolean success = true;
      for (int i = 0; i < sharedLocks.length; i++) {
         Lock toAcquire = exclusive ? sharedLocks[i].writeLock() : sharedLocks[i].readLock();
         try {
            success = toAcquire.tryLock(timeout, TimeUnit.MILLISECONDS);
            if (!success) {
               if (log.isTraceEnabled())
                  log.trace("Could not aquire lock on " + toAcquire + ". Exclusive?" + exclusive);
               break;
            }
View Full Code Here

   {
      if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion

      if (trace) log.trace("Attempting to lock " + fqn);
      Lock lock = lockContainer.getLock(fqn);
      return lock.tryLock(lockAcquisitionTimeout, MILLISECONDS);
   }

   public boolean lock(Fqn fqn, LockType lockType, Object owner, long timeoutMillis) throws InterruptedException
   {
      if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion
View Full Code Here

   {
      if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion

      if (trace) log.trace("Attempting to lock " + fqn);
      Lock lock = lockContainer.getLock(fqn);
      return lock.tryLock(timeoutMillis, MILLISECONDS);
   }

   public boolean lockAndRecord(Fqn fqn, LockType lockType, InvocationContext ctx) throws InterruptedException
   {
      if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion
View Full Code Here

   {
      if (lockType == READ) return true; // we don't support read locks. TODO: enforce this with an assertion

      if (trace) log.trace("Attempting to lock " + fqn);
      Lock lock = lockContainer.getLock(fqn);
      if (lock.tryLock(ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout), MILLISECONDS))
      {
         ctx.addLock(fqn);
         return true;
      }
View Full Code Here

            lock.unlock();
            println("true");
        } else if (lockStr.equalsIgnoreCase("trylock")) {
            String timeout = args.length > 2 ? args[2] : null;
            if (timeout == null) {
                println(lock.tryLock());
            } else {
                long time = Long.valueOf(timeout);
                try {
                    println(lock.tryLock(time, TimeUnit.SECONDS));
                } catch (InterruptedException e) {
View Full Code Here

            if (timeout == null) {
                println(lock.tryLock());
            } else {
                long time = Long.valueOf(timeout);
                try {
                    println(lock.tryLock(time, TimeUnit.SECONDS));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
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.