Package java.util.concurrent.atomic

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


    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


           */
          try {
            startSignal.countDown();
            startSignal.await();
            long now = System.currentTimeMillis();
            startTime.compareAndSet(0, now);
            task.run();
          } catch (Throwable e) {
            Logger threadLog = Logger.getLogger(ConfigUtil.LINKBENCH_LOGGER);
            threadLog.error("Unrecoverable exception in worker thread:", e);
            Runtime.getRuntime().halt(1);
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

         log.debug("Building the index");
         forEachOnDisk(false, false, new EntryFunctor() {
            @Override
            public boolean apply(int file, int offset, int size, byte[] serializedKey, byte[] serializedMetadata, byte[] serializedValue, long seqId, long expiration) throws IOException, ClassNotFoundException {
               long prevSeqId;
               while (seqId > (prevSeqId = maxSeqId.get()) && !maxSeqId.compareAndSet(prevSeqId, seqId));
               Object key = marshaller.objectFromByteBuffer(serializedKey);
               if (trace) log.tracef("Loaded %d:%d (seqId %d, expiration %d)", file, offset, seqId, expiration);
               try {
                  // We may check the seqId safely as we are the only thread writing to index
                  EntryPosition entry = temporaryTable.get(key);
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

            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

            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 MailboxAdded) {
View Full Code Here

                public ServerCache call() throws Exception {
                    QueryPlan hashPlan = hashPlans[index];
                    ServerCache cache = hashClient.addHashCache(ranges, hashPlan.iterator(),
                            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

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.