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

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


      return new Thread(name)
      {
         public void run()
         {
            try {
               Sync wlock = lock_.writeLock();
               if (! wlock.attempt(msecs)) {
                  logX(caseNum+"-"+name+" requesting write lock failed!\n");
                  String str = caseNum + "-" + name + "-WL-0";
                  postLockingResult(str);
                  return;
               }
               // OK, write lock obtained, sleep and release it.
               logX(caseNum+"-"+name+" requesting write lock succeeded!\n");
               String str = caseNum + "-" + name + "-WL-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);

               wlock.release();
               logX(caseNum+"-"+name+" releasing write lock.\n");
            } catch (Exception ex) {
            }
         }
      };
View Full Code Here


      return new Thread(name)
      {
         public void run()
         {
            try {
               Sync rlock = lock_.readLock();
               Sync wlock = null;
               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 upgrade it later.
               logX(caseNum+"-"+name+" requesting read lock succeeded (upgrade later)!\n");
               TestingUtil.sleepThread(SLEEP_MSECS/2);
               String str = caseNum + "-" + name + "-UL-";
               if ((wlock = lock_.upgradeLockAttempt(msecs)) == null)
               {
                 logX(caseNum+"-"+name+" requesting upgrade lock failed!\n");
                 str += "0";
               }
               else
               {
                 logX(caseNum+"-"+name+" requesting upgrade lock succeeded!\n");
                 str += "1";
               }
               postLockingResult(str);
               // Sleep again and then release the lock.
               TestingUtil.sleepThread(SLEEP_MSECS);
               if (wlock != null)
               {
                 wlock.release();
                 logX(caseNum+"-"+name+" releasing upgrade lock.\n");
               }
               rlock.release();
            } catch (Exception ex) {
            }
View Full Code Here

 
   protected void acquireReadLock(final String caseNum, final String name,
                                  final long msecs, final String errMsg)
   {
            try {
               Sync rlock = lock_.readLock();
               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(SLEEP_MSECS);
               rlock.release();
               logX(caseNum+"-"+name+" releasing read lock.\n");
            } catch (Exception ex) {
            }
   }
View Full Code Here

    */
   protected void acquireWriteLock(final String caseNum, final String name,
                                   final long msecs, final String errMsg)
   {
            try {
               Sync wlock = lock_.writeLock();
               if (! wlock.attempt(msecs)) {
                  logX(caseNum+"-"+name+" requesting write lock failed!\n");
                  String str = caseNum + "-" + name + "-WL-0";
                  postLockingResult(str);
                  return;
               }
               // OK, write lock obtained, sleep and release it.
               logX(caseNum+"-"+name+" requesting write lock succeeded!\n");
               String str = caseNum + "-" + name + "-WL-1";
               postLockingResult(str);
               TestingUtil.sleepThread(SLEEP_MSECS);
               wlock.release();
               logX(caseNum+"-"+name+" releasing write lock.\n");
            } catch (Exception ex) {
            }
   }
View Full Code Here

    */
   protected void acquireUpgradeLock(final String caseNum, final String name,
                                     final long msecs, final String errMsg)
   {
            try {
               Sync ulock = null;
               if ((ulock = lock_.upgradeLockAttempt(msecs)) == null) {
                  logX(caseNum+"-"+name+" requesting upgrade lock failed!\n");
                  String str = caseNum + "-" + name + "-UL-0";
                  postLockingResult(str);
                  return;
               }
               // OK, write lock obtained, sleep and release it.
               logX(caseNum+"-"+name+" requesting upgrade lock succeeded!\n");
               String str = caseNum + "-" + name + "-UL-1";
               postLockingResult(str);
               TestingUtil.sleepThread(SLEEP_MSECS);
               ulock.release();
               logX(caseNum+"-"+name+" releasing upgrade lock.\n");
            } catch (Exception ex) {
            }
   }
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

      return new Thread(name)
      {
         public void run()
         {
            try {
               Sync wlock = lock_.writeLock();
               if (! wlock.attempt(msecs)) {
                  logX(caseNum+"-"+name+" requesting write lock failed!\n");
                  String str = caseNum + "-" + name + "-WL-0";
                  postLockingResult(str);
                  return;
               }
               // OK, write lock obtained, sleep and release it.
               logX(caseNum+"-"+name+" requesting write lock succeeded!\n");
               String str = caseNum + "-" + name + "-WL-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);

               wlock.release();
               logX(caseNum+"-"+name+" releasing write lock.\n");
            } catch (Exception ex) {
            }
         }
      };
View Full Code Here

      return new Thread(name)
      {
         public void run()
         {
            try {
               Sync rlock = lock_.readLock();
               Sync wlock = null;
               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 upgrade it later.
               logX(caseNum+"-"+name+" requesting read lock succeeded (upgrade later)!\n");
               TestingUtil.sleepThread(SLEEP_MSECS/2);
               String str = caseNum + "-" + name + "-UL-";
               if ((wlock = lock_.upgradeLockAttempt(msecs)) == null)
               {
                 logX(caseNum+"-"+name+" requesting upgrade lock failed!\n");
                 str += "0";
               }
               else
               {
                 logX(caseNum+"-"+name+" requesting upgrade lock succeeded!\n");
                 str += "1";
               }
               postLockingResult(str);
               // Sleep again and then release the lock.
               TestingUtil.sleepThread(SLEEP_MSECS);
               if (wlock != null)
               {
                 wlock.release();
                 logX(caseNum+"-"+name+" releasing upgrade lock.\n");
               }
               rlock.release();
            } catch (Exception ex) {
            }
View Full Code Here

 
   protected void acquireReadLock(final String caseNum, final String name,
                                  final long msecs, final String errMsg)
   {
            try {
               Sync rlock = lock_.readLock();
               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(SLEEP_MSECS);
               rlock.release();
               logX(caseNum+"-"+name+" releasing read lock.\n");
            } catch (Exception ex) {
            }
   }
View Full Code Here

    */
   protected void acquireWriteLock(final String caseNum, final String name,
                                   final long msecs, final String errMsg)
   {
            try {
               Sync wlock = lock_.writeLock();
               if (! wlock.attempt(msecs)) {
                  logX(caseNum+"-"+name+" requesting write lock failed!\n");
                  String str = caseNum + "-" + name + "-WL-0";
                  postLockingResult(str);
                  return;
               }
               // OK, write lock obtained, sleep and release it.
               logX(caseNum+"-"+name+" requesting write lock succeeded!\n");
               String str = caseNum + "-" + name + "-WL-1";
               postLockingResult(str);
               TestingUtil.sleepThread(SLEEP_MSECS);
               wlock.release();
               logX(caseNum+"-"+name+" releasing write 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.