Package java.util.concurrent.locks

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


   }

   public void acquireProcessingLock(boolean exclusive, long timeout, TimeUnit timeUnit) throws TimeoutException {
      Lock lock = exclusive ? processingLock.writeLock() : processingLock.readLock();
      try {
         if (!lock.tryLock(timeout, timeUnit))
            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()));
//         log.info("Acquired processing lock xcl = %s.  Locks are %s and %s", exclusive, processingLock.readLock(), processingLock.writeLock());
      } catch (InterruptedException ie) {
         currentThread().interrupt();
      }
View Full Code Here


   public void acquireProcessingLock(boolean exclusive, long timeout, TimeUnit timeUnit) throws TimeoutException {
      while (true) {
         try {
            Lock lock = exclusive ? processingLock.writeLock() : processingLock.readLock();
            if (!lock.tryLock(timeout, timeUnit))
               throw new TimeoutException("Could not obtain " + (exclusive ? "exclusive" : "shared") + " processing lock");
            break;
         } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
         }
View Full Code Here

        }
        getExecutor().execute(new Runnable() {
            public void run() {
                String uri = file.toURI().relativize(aFile.toURI()).toString();
                Lock lock = lockManager.getLock(uri);
                if (lock.tryLock()) {
                    boolean unlock = true;
                    try {
                        unlock = processFileAndDelete(aFile);
                    } finally {
                        if (unlock) {
View Full Code Here

            logger.debug("Scheduling file " + file + " for processing");
        }
        getExecutor().execute(new Runnable() {
            public void run() {
                final Lock lock = lockManager.getLock(file);
                if (lock.tryLock()) {
                    boolean unlock = true;
                    try {
                        unlock = processFileAndDelete(file);
                    } finally {
                        if (unlock) {
View Full Code Here

        }
        getExecutor().execute(new Runnable() {
            public void run() {
                String uri = file.toURI().relativize(aFile.toURI()).toString();
                Lock lock = lockManager.getLock(uri);
                if (lock.tryLock()) {
                    try {
                        processFileAndDelete(aFile);
                    } finally {
                        lock.unlock();
                    }
View Full Code Here

                        }

                        // inform multi index
                        // if we cannot get the sync immediately we have to quit
                        Lock shared = indexReplacement.readLock();
                        if (!shared.tryLock()) {
                            log.debug("index merging canceled");
                            return;
                        }
                        try {
                            log.debug("replace indexes");
View Full Code Here

        // start at a random index, so different threads don't all start at index 0 and compete for the lock
        int starting_index=((int)(Math.random() * pool.length)) & (pool.length - 1);
        for(int i=0; i < locks.length; i++) {
            int index=(starting_index + i) & (pool.length -1);
            Lock lock=locks[index];
            if(lock.tryLock()) {
                if(pool[index] != null)
                    return new Element<T>(pool[index], lock);
                return new Element<T>(pool[index]=creator.create(), lock);
            }
        }
View Full Code Here

                for(String lock_name: lock_names) {
                    Lock lock=lock_service.getLock(lock_name);
                    boolean rc;
                    if(timeout < 0)
                        rc=lock.tryLock();
                    else
                        rc=lock.tryLock(timeout, TimeUnit.MILLISECONDS);
                    if(!rc)
                        System.err.println("Failed locking \"" + lock_name + "\"");
                }
View Full Code Here

                    Lock lock=lock_service.getLock(lock_name);
                    boolean rc;
                    if(timeout < 0)
                        rc=lock.tryLock();
                    else
                        rc=lock.tryLock(timeout, TimeUnit.MILLISECONDS);
                    if(!rc)
                        System.err.println("Failed locking \"" + lock_name + "\"");
                }
            }
            else if(line.startsWith("unlock")) {
View Full Code Here

  @Override
  public Boolean execute(LockCommandContext context)
  {
    Lock lock = context.getLock(this.descriptor);
   
    boolean locked = lock.tryLock();
   
    if (locked)
    {
      Map<LockDescriptor, Lock> lockMap = context.getRemoteLocks(this.descriptor);
     
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.