Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicInteger.compareAndSet()


    } else {
      Logger.debug("Lock Refused - Realtime " + lockIndex.toString());
      throw FAILURE_EXCEPTION;
    }
   
    boolean isLocked = lock.compareAndSet(val, val | LOCK);
   
    if( !isLocked){
      Logger.debug("Remote Lock Failed: Concurrent Locked object");
      throw FAILURE_EXCEPTION;
    }   
View Full Code Here


        return true;
      Logger.debug("Locally Locked object");
      throw FAILURE_EXCEPTION;
    }
   
    boolean isLocked = lock.compareAndSet(val, val | LOCK);
   
    if( !isLocked){
      Logger.debug("Being Locked object");
      throw FAILURE_EXCEPTION;
    }   
View Full Code Here

      Logger.debug("Lock Refused - Realtime " + lockIndex.toString());
      //System.out.println("Lock Refused - Realtime " + lockIndex.toString());
      throw FAILURE_EXCEPTION;
    }
       
    boolean isLocked = lock.compareAndSet(val, val | LOCK);
   
    if( !isLocked){
      Logger.debug("Being Locked object");
      //System.out.println("Being Locked object");
      throw FAILURE_EXCEPTION;
View Full Code Here

      Logger.debug("Can't unlock remote object");
      return false;
    }
   
    int unlockedValue = val & UNLOCK;
    if(!lock.compareAndSet(val, unlockedValue)){
      Logger.debug("Fail due to concurrent unlock!!");
      return false;
    }
   
    if(contextLocks!=null)
View Full Code Here

      Logger.debug("Can't unlock remote object");
      return false;
    }
   
    int unlockedValue = val & UNLOCK;
    if(!lock.compareAndSet(val, unlockedValue)){
      Logger.fetal("Fail due to concurrent unlock!!");
      return false;
    }
   
    if(contextLocks!=null)
View Full Code Here

  public boolean kill() {
    Object[] metadata = registery.get(txnId);
    if(metadata==null)
      return true;
    AtomicInteger status = ((AtomicInteger)metadata[STATUS_INDEX]);
    return status.get()==ABORTED || status.compareAndSet(ACTIVE, ABORTED);
  }

}
View Full Code Here

      while (true) {
        int oldValue = existingCounter.get();
        if (oldValue != 0) {
          try {
            int newValue = IntMath.checkedAdd(oldValue, occurrences);
            if (existingCounter.compareAndSet(oldValue, newValue)) {
              // newValue can't == 0, so no need to check & remove
              return oldValue;
            }
          } catch (ArithmeticException overflow) {
            throw new IllegalArgumentException("Overflow adding " + occurrences
View Full Code Here

    }
    while (true) {
      int oldValue = existingCounter.get();
      if (oldValue != 0) {
        int newValue = Math.max(0, oldValue - occurrences);
        if (existingCounter.compareAndSet(oldValue, newValue)) {
          if (newValue == 0) {
            // Just CASed to 0; remove the entry to clean up the map. If the removal fails,
            // another thread has already replaced it with a new counter, which is fine.
            countMap.remove(element, existingCounter);
          }
View Full Code Here

      int oldValue = existingCounter.get();
      if (oldValue < occurrences) {
        return false;
      }
      int newValue = oldValue - occurrences;
      if (existingCounter.compareAndSet(oldValue, newValue)) {
        if (newValue == 0) {
          // Just CASed to 0; remove the entry to clean up the map. If the removal fails,
          // another thread has already replaced it with a new counter, which is fine.
          countMap.remove(element, existingCounter);
        }
View Full Code Here

      while (true) {
        int oldValue = existingCounter.get();
        if (oldValue != 0) {
          try {
            int newValue = IntMath.checkedAdd(oldValue, occurrences);
            if (existingCounter.compareAndSet(oldValue, newValue)) {
              // newValue can't == 0, so no need to check & remove
              return oldValue;
            }
          } catch (ArithmeticException overflow) {
            throw new IllegalArgumentException("Overflow adding " + occurrences
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.