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


        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));
    }

    private static final int BITS_PER_BYTE = 8;
    private static final int BYTES_PER_INT = 4;
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

        if (!this.map.replace(paramObject, localAtomicLong, new AtomicLong(paramLong)))
          break;
        return paramLong;
      }
      long l2 = l1 + paramLong;
      if (localAtomicLong.compareAndSet(l1, l2))
        return l2;
    }
  }

  public long getAndIncrement(Object paramObject)
View Full Code Here

        if (!this.map.replace(paramObject, localAtomicLong, new AtomicLong(paramLong)))
          break;
        return 0L;
      }
      long l2 = l1 + paramLong;
      if (localAtomicLong.compareAndSet(l1, l2))
        return l1;
    }
  }

  public long put(Object paramObject, long paramLong)
View Full Code Here

      {
        if (!this.map.replace(paramObject, localAtomicLong, new AtomicLong(paramLong)))
          break;
        return 0L;
      }
      if (localAtomicLong.compareAndSet(l, paramLong))
        return l;
    }
  }

  public void putAll(Map paramMap)
View Full Code Here

    if (localAtomicLong == null)
      return 0L;
    while (true)
    {
      long l = localAtomicLong.get();
      if ((l == 0L) || (localAtomicLong.compareAndSet(l, 0L)))
      {
        this.map.remove(paramObject, localAtomicLong);
        return l;
      }
    }
View Full Code Here

  boolean replace(Object paramObject, long paramLong1, long paramLong2)
  {
    if (paramLong1 == 0L)
      return putIfAbsent(paramObject, paramLong2) == 0L;
    AtomicLong localAtomicLong = (AtomicLong)this.map.get(paramObject);
    return localAtomicLong == null ? false : localAtomicLong.compareAndSet(paramLong1, paramLong2);
  }

  boolean remove(Object paramObject, long paramLong)
  {
    AtomicLong localAtomicLong = (AtomicLong)this.map.get(paramObject);
View Full Code Here

    if (localAtomicLong == null)
      return false;
    long l = localAtomicLong.get();
    if (l != paramLong)
      return false;
    if ((l == 0L) || (localAtomicLong.compareAndSet(l, 0L)))
    {
      this.map.remove(paramObject, localAtomicLong);
      return true;
    }
    return false;
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.