Package EDU.oswego.cs.dl.util.concurrent

Examples of EDU.oswego.cs.dl.util.concurrent.Sync


     *
     * @param key the key object
     */
    public void remove(Object key)
    {
        Sync sync = this.lock.writeLock();
        try
        {
            sync.acquire();
            try
            {
                this.doRemove(key);
                m_sizeInstrument.setValue( doGetSize() );
            }
            finally
            {
                sync.release();
            }
        }
        catch (InterruptedException ignore)
        {
        }
View Full Code Here


     * @param key the key object
     * @return true if Key exists and false if not
     */
    public boolean containsKey(Object key)
    {
        Sync sync = this.lock.readLock();
        try
        {
            sync.acquire();
            try
            {
                return this.doContainsKey(key);
            }
            finally
            {
                sync.release();
            }
        }
        catch (InterruptedException ignore)
        {
            return false;
View Full Code Here

     *
     * @return  Enumeration Object with all existing keys
     */
    public Enumeration keys()
    {
        Sync sync = this.lock.readLock();
        try
        {
            sync.acquire();
            try
            {
                return this.doGetKeys();
            }
            finally
            {
                sync.release();
            }
        }
        catch (InterruptedException ignore)
        {
            return Collections.enumeration(Collections.EMPTY_LIST);
View Full Code Here

        }
    }

    public int size()
    {
        Sync sync = this.lock.readLock();
        try
        {
            sync.acquire();
            try
            {
                return this.doGetSize();
            }
            finally
            {
                sync.release();
            }
        }
        catch (InterruptedException ignore)
        {
            return 0;
View Full Code Here

    }

    public synchronized Object getObject(final Object key)
    throws IOException, ClassNotFoundException
    {
        Sync sync = this.lock.writeLock();
        try
        {
            sync.acquire();
            try
            {
                final File file = this.fileFromKey(key);
                if (file != null) {
                    return this.deserializeObject(file);
                }
            }
            finally
            {
                sync.release();
            }
        }
        catch (InterruptedException ignore)
        {
        }
View Full Code Here

         {
            java.util.Random rand = new java.util.Random(++SEED);
            for (int i = 0; i < LOOPS; i++) {
               int duration = rand.nextInt((int) SLEEP_MSECS);
               _sleep(SLEEP_MSECS);
               Sync rlock = null;
               try {
                  rlock = lock_.readLock();
                  if (!rlock.attempt(msecs)) {
                     log("Read lock attempt failed.");
//                     fail("Read lock attempt failed.");
                     counter++;
                     continue;
                  }
                  log("acquired read lock");
                  _sleep(duration);
                  log("released read lock");
               } catch (Exception ex) {
               }
               finally {
                  rlock.release();
               }
            }
         }
      };
   }
View Full Code Here

         {
            java.util.Random rand = new java.util.Random(++SEED);
            for (int i = 0; i < LOOPS; i++) {
               int duration = rand.nextInt((int) SLEEP_MSECS);
               _sleep(SLEEP_MSECS + duration);
               Sync wlock = null;
               try {
                  wlock = lock_.writeLock();
                  if (!wlock.attempt(msecs)) {
                     log("Write lock attempt failed.");
//                     fail("Write lock attempt failed.");
                     counter++;
                     continue;
                  }
                  log("acquired write lock");
                  _sleep(duration);
                  log("released write lock");
               } catch (Exception ex) {
               }
               finally {
                  wlock.release();
               }
            }
         }
      };
   }
View Full Code Here

         {
            java.util.Random rand = new java.util.Random(++SEED);
            for (int i = 0; i < LOOPS; i++) {
               int duration = rand.nextInt((int) SLEEP_MSECS);
               _sleep(SLEEP_MSECS);
               Sync rlock = null;
               Sync wlock = null;
               try {
                  rlock = lock_.readLock();
                  if (!wlock.attempt(msecs)) {
                     log("Read lock attempt failed.");
//                   fail("Read lock attempt failed.");
                     counter++;
                     continue;
                  }
                  log("Acquired read lock for upgrade later");
                  _sleep(duration / 2);
                  // upgrade lock. Note that read lock will be released
                  // and write lock be acquired automatically.
                  wlock = lock_.upgradeLockAttempt(msecs);
                  if (wlock == null) {
                     log("upgrade lock attempt failed");
//                     fail("upgrade lock attempt failed");
                     rlock.release();
                     counter++;
                  }

                  log("Upgraded write lock");
                  _sleep(duration);
                  log("released write lock");
               } catch (Exception ex) {
               }
               finally {
                  if(wlock != null)
                     wlock.release();
               }
            }
         }
      };
   }
View Full Code Here

      }

      // Check first if we need to upgrade
      if (map_.isOwner(caller, LockMap.OWNER_READ)) {
         // Currently is a reader owner. Obtain the writer ownership then.
         Sync wLock;
         try {
            if(trace)
               log.trace("upgrading RL to WL for " + caller + ", timeout=" + timeout + ", locks: " + map_.printInfo());
            wLock = lock_.upgradeLockAttempt(timeout);
         } catch (UpgradeException ue) {
View Full Code Here

   {
      return new Thread(name)
      {
         public void run()
         {
               Sync rlock = lock_.readLock();
            try {
               if (! rlock.attempt(msecs)) {
                  logX(caseNum+"-"+name+" requesting read lock failed!\n");
                  String str = caseNum + "-" + name + "-RL-0";
                  postLockingResult(str);
                  return;
               }
               // OK, read lock obtained, sleep and release it.
               logX(caseNum+"-"+name+" requesting read lock succeeded!\n");
               String str = caseNum + "-" + name + "-RL-1";
               postLockingResult(str);
               TestingUtil.sleepThread(sleepSecs);

         if (secondOP == INVOKE_READ)
                   acquireReadLock(caseNum, name, msecs, errMsg);
               else if (secondOP == INVOKE_WRITE)
                   acquireWriteLock(caseNum, name, msecs, errMsg);
               else if (secondOP == INVOKE_UPGRADE)
                   acquireUpgradeLock(caseNum, name, msecs, errMsg);
                
               rlock.release();
               logX(caseNum+"-"+name+" releasing read lock.\n");
            } catch (Exception ex) {
            }
         }
      };
View Full Code Here

TOP

Related Classes of EDU.oswego.cs.dl.util.concurrent.Sync

Copyright © 2018 www.massapicom. 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.