Package java.util.concurrent.locks

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


            // 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) {
                throw (ConcurrentAccessTimeoutException) new ConcurrentAccessTimeoutException("Unable to get lock within specified time on: " + instance).initCause(e);
            }
        }
View Full Code Here


        // so not getting this lock within 60 seconds probably isn't detrimental.
        // But if there is a deadlock, blocking forever here would be detrimental,
        // so we do not do it. We'll just log a warning and let the thread keep going.
        Lock readLock = rwLock.readLock();
        try {
            if (!readLock.tryLock(60L, TimeUnit.SECONDS)) {
                String msg = "There may be a deadlock in the plugin container.";
                //noinspection ThrowableInstanceNeverThrown
                log.warn(msg, new Throwable(msg));
                readLock = null;
            }
View Full Code Here

        // so not getting this lock within 60 seconds probably isn't detrimental.
        // But if there is a deadlock, blocking forever here would be detrimental,
        // so we do not do it. We'll just log a warning and let the thread keep going.
        Lock writeLock = rwLock.writeLock();
        try {
            if (!writeLock.tryLock(60L, TimeUnit.SECONDS)) {
                String msg = "There may be a deadlock in the plugin container.";
                //noinspection ThrowableInstanceNeverThrown
                log.warn(msg, new Throwable(msg));
                writeLock = null;
            }
View Full Code Here

    final Lock readLock = rlocker.readLock();
    readLock.lock();
    final Lock readLock2 = rlocker.readLock();
    readLock2.lock();
    final Lock writeLock = wlocker.writeLock();
    if (writeLock.tryLock(100, TimeUnit.MILLISECONDS))
      throw new RuntimeException("Write lock achieved during read lock!");
    readLock.unlock();
    readLock2.unlock();
    writeLock.lock();
    if (readLock.tryLock(100, TimeUnit.MILLISECONDS))
View Full Code Here

         public void run()
         {
            Lock rlock = lock_.readLock();
            try
            {
               if (!rlock.tryLock(msecs, TimeUnit.MILLISECONDS))
               {
                  logX(caseNum + "-" + name + " requesting read lock failed!\n");
                  String str = caseNum + "-" + name + "-RL-0";
                  postLockingResult(str);
                  return;
View Full Code Here

         public void run()
         {
            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

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

                                  final String errMsg)
   {
      try
      {
         Lock rlock = lock_.readLock();
         if (!rlock.tryLock(0, TimeUnit.MILLISECONDS))
         {
            String str = caseNum + "-" + name + "-RL-0";
            postLockingResult(str);
            return;
         }
View Full Code Here

   protected void acquireWriteLock(final String caseNum, final String name, final String errMsg)
   {
      try
      {
         Lock wlock = lock_.writeLock();
         if (!wlock.tryLock(0, TimeUnit.MILLISECONDS))
         {
            String str = caseNum + "-" + name + "-WL-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.