Package java.util.concurrent.atomic

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


          // atomic replaced
          continue outer;
        }

        long newValue = oldValue + delta;
        if (atomic.compareAndSet(oldValue, newValue)) {
          return oldValue;
        }
        // value changed
      }
    }
View Full Code Here


          }
          // atomic replaced
          continue outer;
        }

        if (atomic.compareAndSet(oldValue, newValue)) {
          return oldValue;
        }
        // value changed
      }
    }
View Full Code Here

      return 0L;
    }

    for (;;) {
      long oldValue = atomic.get();
      if (oldValue == 0L || atomic.compareAndSet(oldValue, 0L)) {
        // only remove after setting to zero, to avoid concurrent updates
        map.remove(key, atomic);
        // succeed even if the remove fails, since the value was already adjusted
        return oldValue;
      }
View Full Code Here

  boolean replace(K key, long expectedOldValue, long newValue) {
    if (expectedOldValue == 0L) {
      return putIfAbsent(key, newValue) == 0L;
    } else {
      AtomicLong atomic = map.get(key);
      return (atomic == null) ? false : atomic.compareAndSet(expectedOldValue, newValue);
    }
  }

  /**
   * If {@code (key, value)} is currently in the map, this method removes it and returns
View Full Code Here

    long oldValue = atomic.get();
    if (oldValue != value) {
      return false;
    }

    if (oldValue == 0L || atomic.compareAndSet(oldValue, 0L)) {
      // only remove after setting to zero, to avoid concurrent updates
      map.remove(key, atomic);
      // succeed even if the remove fails, since the value was already adjusted
      return true;
    }
View Full Code Here

                public ServerCache call() throws Exception {
                    QueryPlan hashPlan = hashPlans[index];
                    ServerCache cache = hashClient.addHashCache(ranges, hashPlan.iterator(),
                            clientProjectors[index], hashPlan.getEstimatedSize(), hashExpressions[index], plan.getTableRef());
                    long endTime = System.currentTimeMillis();
                    boolean isSet = firstJobEndTime.compareAndSet(0, endTime);
                    if (!isSet && (endTime - firstJobEndTime.get()) > maxServerCacheTimeToLive) {
                        LOG.warn("Hash plan [" + index + "] execution seems too slow. Earlier hash cache(s) might have expired on servers.");
                    }
                    return cache;
                }
View Full Code Here

        long oldseed, nextseed;
        AtomicLong seed = this.seed;
        do {
            oldseed = seed.get();
            nextseed = (oldseed * multiplier + addend) & mask;
        } while (!seed.compareAndSet(oldseed, nextseed));
        return (int)(nextseed >>> (48 - bits));
    }

    /**
     * Generates random bytes and places them into a user-supplied
View Full Code Here

            AtomicLong size = sizes.get(id);
            if (size != null) {
                while(true) {
                    long expected = size.get();
                    long newValue = expected + s;
                    if (size.compareAndSet(expected, newValue)) {
                        break;
                    }
                }
            }
           
View Full Code Here

            AtomicLong count = counts.get(id);
            if (count != null) {
                while(true) {
                    long expected = count.get();
                    long newValue = expected + c;
                    if (count.compareAndSet(expected, newValue)) {
                        break;
                    }
                }
            }
        } else if (event instanceof Expunged) {
View Full Code Here

            AtomicLong size = sizes.get(id);
            if (size != null) {
                while(true) {
                    long expected = size.get();
                    long newValue = expected - s;
                    if (size.compareAndSet(expected, newValue)) {
                        break;
                    }
                }
            }
           
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.