Package java.util.concurrent.locks

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


            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.parseLong(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.parseLong(timeout);
                try {
                    println(lock.tryLock(time, TimeUnit.SECONDS));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
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

   public Lock acquireLock(Object key, long timeout, TimeUnit unit) throws InterruptedException {
      while (true) {
         Lock lock = getLock(key);
         boolean locked = false;
         try {
            locked = lock.tryLock(timeout, unit);
         } catch (InterruptedException ie) {
            safeRelease(lock);
            throw ie;
         } catch (Throwable th) {
            safeRelease(lock);
View Full Code Here

   public Lock acquireLock(Object key, long timeout, TimeUnit unit) throws InterruptedException {
      Lock lock = getLock(key);
      boolean locked = false;
      try {
         locked = lock.tryLock(timeout, unit);
      } catch (InterruptedException ie) {
         safeRelease(lock);
         throw ie;
      } catch (Throwable th) {
         safeRelease(lock);
View Full Code Here

   public Lock acquireLock(Object key, long timeout, TimeUnit unit) throws InterruptedException {
      while (true) {
         Lock lock = getLock(key);
         boolean locked = false;
         try {
            locked = lock.tryLock(timeout, unit);
         } catch (InterruptedException ie) {
            safeRelease(lock);
            throw ie;
         } catch (Throwable th) {
            safeRelease(lock);
View Full Code Here

   public Lock acquireLock(Object key, long timeout, TimeUnit unit) throws InterruptedException {
      Lock lock = getLock(key);
      boolean locked = false;
      try {
         locked = lock.tryLock(timeout, unit);
      } catch (InterruptedException ie) {
         safeRelease(lock);
         throw ie;
      } catch (Throwable th) {
         safeRelease(lock);
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

                                   final long msecs, final String errMsg)
   {
      try
      {
         Lock wlock = lock_.writeLock();
         if (!wlock.tryLock(msecs, TimeUnit.MILLISECONDS))
         {
            logX(caseNum + "-" + name + " requesting write lock failed!\n");
            String str = caseNum + "-" + name + "-WL-0";
            postLockingResult(str);
            return;
View Full Code Here

         public void run()
         {
            Lock rlock = lock_.readLock();
            try
            {
               if (!rlock.tryLock(msecs, TimeUnit.MILLISECONDS))
               {
                  log(caseNum + "-" + name + " requesting read lock failed!\n");
                  String str = caseNum + "-" + name + "-RL-0";
                  postLockingResult(str);
                  return;
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.