Package java.util.concurrent.locks

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


         public void run()
         {
            try
            {
               Lock wlock = lock_.writeLock();
               if (!wlock.tryLock(msecs, TimeUnit.MILLISECONDS))
               {
                  log(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))
         {
            log(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))
         {
            log(caseNum + "-" + name + " requesting write lock failed!\n");
            String str = caseNum + "-" + name + "-WL-0";
            postLockingResult(str);
            return;
View Full Code Here

      flushBlockGate.open();
   }

   public void acquireProcessingLock(boolean exclusive, long timeout, TimeUnit timeUnit) throws InterruptedException, TimeoutException {
      Lock lock = exclusive ? processingLock.writeLock() : processingLock.readLock();
      if (!lock.tryLock(timeout, timeUnit))
         throw new TimeoutException("Could not obtain " + (exclusive ? "exclusive" : "shared") + " processing lock");
   }

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

                time = accessTimeoutOnMethod.getValue();
                unit = accessTimeoutOnMethod.getTimeUnit();
            }
        }
        // try getting the lock
        boolean success = lock.tryLock(time, unit);
        if (!success) {
            throw MESSAGES.concurrentAccessTimeoutException(invocationContext,time + unit.name());
        }
        try {
            // lock obtained. now proceed!
View Full Code Here

        Thread.sleep(500);
        // now try and get a read lock, *shouldn't* be able to obtain the lock
        // before the 2 second timeout
        try {
            // try a read lock with 2 second timeout
            boolean readLockAquired = readLock.tryLock(2, TimeUnit.SECONDS);
            Assert.assertFalse("Unexpected obtained a read lock", readLockAquired);
        } catch (ConcurrentAccessTimeoutException cate) {
            // expected
        } finally {
            // let the latch know that this thread is done with its part
View Full Code Here

        Lock readLock = this.ejbReadWriteLock.readLock();
        // lock it! (should work, because we are going from a write to read and *not*
        // the other way round)
        try {
            boolean readLockAquired = readLock.tryLock(2, TimeUnit.SECONDS);
            // unlock the read lock, because we don't need it anymore
            if (readLockAquired) {
                readLock.unlock();
            }
            Assert.assertTrue("Could not obtain read lock when write lock was held by the same thread!", readLockAquired);
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.