Package java.util.concurrent.locks

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


   {
      EJBContainer container = EJBContainer.getEJBContainer(invocation.getAdvisor());
     
      Lock lock = container.getInvocationLock();
     
      if (!lock.tryLock())
      {
         throw new DispatcherConnectException("EJB container is not completely started, or is stopped.");
      }
     
      try
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

   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 boolean acquireLock(Object key, long timeout, TimeUnit unit) throws InterruptedException {
      while (true) {
         Lock lock = getLock(key);
         if (lock.tryLock(timeout, unit)) {
            // lock acquired.  Now check if it is the *correct* lock!
            Lock existingLock = locks.putIfAbsent(key, lock);
            if (existingLock != null && existingLock != lock) {
               // we have the wrong lock!  Unlock and retry.
               lock.unlock();
View Full Code Here

                {
                    return null ;
                }
                readLock = serviceInfo.getReadLock() ;
               
                if (readLock.tryLock())
                {
                    if (traceEnabled)
                    {
                        LOGGER.trace("Obtained read lock, returning EPRs") ;
                    }
View Full Code Here

                {
                    return null ;
                }
                writeLock = serviceInfo.getWriteLock() ;
               
                if (writeLock.tryLock())
                {
                    if (traceEnabled)
                    {
                        LOGGER.trace("Obtained write lock, returning locked serviceInfo") ;
                    }
View Full Code Here

                {
                    LOGGER.trace("Retrieved service information for service " + service + ", serviceInfo: " + serviceInfo) ;
                }
                writeLock = serviceInfo.getWriteLock() ;
               
                if (writeLock.tryLock())
                {
                    if (traceEnabled)
                    {
                        LOGGER.trace("Obtained write lock, returning locked serviceInfo") ;
                    }
View Full Code Here

            // wait indefinitely for a lock
            currLock.lock();
            lockAcquired = true;
        } else if (accessTimeout.getTime() == 0) {
            // concurrent calls are not allowed, lock only once
        lockAcquired = currLock.tryLock();
      } else {
        // try to get a lock within the specified period.
        try {
        lockAcquired = currLock.tryLock(accessTimeout.getTime(), accessTimeout.getUnit());
      } catch (InterruptedException e) {
View Full Code Here

            // concurrent calls are not allowed, lock only once
        lockAcquired = currLock.tryLock();
      } else {
        // try to get a lock within the specified period.
        try {
        lockAcquired = currLock.tryLock(accessTimeout.getTime(), accessTimeout.getUnit());
      } catch (InterruptedException e) {
        throw new ApplicationException("Unable to get lock.", e);
      }
      }
        // Did we acquire the lock to the current execution?
View Full Code Here

            // wait indefinitely for a lock
            lock.lock();
            lockAcquired = true;
        } else if (accessTimeout.getTime() == 0) {
            // concurrent calls are not allowed, lock only once
            lockAcquired = lock.tryLock();
        } else {
            // try to get a lock within the specified period.
            try {
                lockAcquired = lock.tryLock(accessTimeout.getTime(), accessTimeout.getUnit());
            } catch (InterruptedException e) {
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.