Java 8 AtomicLongArray - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 AtomicLongArray class.

This code example shows how to use the following methods:set
        String text = JSON.toJSONString(array);
        Assert.assertEquals("[1,2,3]", text);
    } 
 
    public void test_AtomicLongArray() throws Exception {
        AtomicLongArray array = new AtomicLongArray(3);
        array.set(0, 1);
        array.set(1, 2);
        array.set(2, 3);
        String text = JSON.toJSONString(array);
        Assert.assertEquals("[1,2,3]", text);
    } 
} 
    
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:length, set
  } 
 
  @Override 
  public void update(long value) {
    final long c = count.incrementAndGet();
    if (c <= values.length()) {
      values.set((int) c - 1, value);
    } else { 
      final long r = nextLong(c);
      if (r < values.length()) {
        values.set((int) r, value);
      } 
    } 
  } 
 
  /** 
   * Get a pseudo-random long uniformly between 0 and n-1. Stolen from 
   * {@link java.util.Random#nextInt()}. 
   * 
   * @param n the bound 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
  private AtomicLongArray bits;
  private int wlen;
   
  public BlockLocks(long numBits) {
    int length = LongBitSet.bits2words(numBits);
    bits = new AtomicLongArray(length);
    wlen = length;
  } 
   
  /** 
   * Find the next clear bit in the bit set. 
   *  
   * @param index 
   *          index 
   * @return next next bit 
   */ 
  public int nextClearBit(int index) {
    int i = index >> 6;
    if (i >= wlen) return -1;
    int subIndex = index & 0x3f; // index within the word
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:compareAndSet, get
   * @param delta the value to add 
   * @return the previous value 
   */ 
  public final double getAndAdd(int i, double delta) {
    while (true) { 
      long current = longs.get(i);
      double currentVal = longBitsToDouble(current);
      double nextVal = currentVal + delta;
      long next = doubleToRawLongBits(nextVal);
      if (longs.compareAndSet(i, current, next)) {
        return currentVal;
      } 
    } 
  } 
 
  /** 
   * Atomically adds the given value to the element at index {@code i}. 
   * 
   * @param i the index 
   * @param delta the value to add 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:compareAndSet
	public boolean isEmptyValue(short value) {
		return value == EMPTY_VALUE;
	} 
 
	private boolean setEntry(int index, int key, short value) {
		return array.compareAndSet(index, EMPTY_ENTRY, pack(key, value));
	} 
 
	private int hash(int h) {
		h ^= (h >>> 20) ^ (h >>> 12);
		h = (h ^ (h >>> 7) ^ (h >>> 4));
		h = (h & 0x7FFFFFFF) % length;
		return h;
	} 
 
	private static int getKey(long entry) {
		return (int) (entry >> 16);
	} 
 
	private static short getValue(long entry) {
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get, length
    /** 
     * @return true if this histogram has overflowed -- that is, a value larger than our largest bucket could bound was added 
     */ 
    public boolean isOverflowed() 
    { 
        return buckets.get(buckets.length() - 1) > 0;
    } 
 
    @Override 
    public boolean equals(Object o)
    { 
        if (this == o)
            return true; 
 
        if (!(o instanceof EstimatedHistogram))
            return false; 
 
        EstimatedHistogram that = (EstimatedHistogram) o;
        return Arrays.equals(getBucketOffsets(), that.getBucketOffsets()) &&
               Arrays.equals(getBuckets(false), that.getBuckets(false));
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:compareAndSet, get
            count.incrementAndGet();
        } 
    } 
 
    private void free(int index) {
        long address = addresses.get(index);
        if (address > 0 && addresses.compareAndSet(index, address, 0)) {
            malloc.free(address);
            count.decrementAndGet();
        } 
    } 
 
    public static void main(String[] args) throws Exception {
        Thread[] threads = new Thread[THREAD_COUNT];
        for (int i = 0; i < THREAD_COUNT; i++) {
            threads[i] = new MallocTest();
        } 
 
        for (Thread thread : threads) {
            thread.start();
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:set
 
    /** The lock type to use with the sequence. */ 
    private final LockType myLockType;
 
    /** The atomic array of long values. */ 
    private final AtomicLongArray myPaddedValue = new AtomicLongArray(30);
 
    /** 
     * The map of waiters and the condition they are waiting on to avoid the 
     * thundering herd. Only access while holding the {@link #myLock lock}. 
     */ 
    private final SortedMap<Long, Condition> myWaiters;
 
    /** Tracks how many threads are waiting for a message or a space to open. */ 
    private final AtomicInteger myWaiting;
 
    /** 
     * Create a sequence with a specified initial value. 
     *  
     * @param initialValue 

4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:length
   * Returns the length of the array. 
   * 
   * @return the length of the array 
   */ 
  public final int length() { 
    return longs.length();
  } 
 
  /** 
   * Gets the current value at position {@code i}. 
   * 
   * @param i the index 
   * @return the current value 
   */ 
  public final double get(int i) {
    return longBitsToDouble(longs.get(i));
  } 
 
  /** 
   * Sets the element at position {@code i} to the given value. 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:compareAndSet, get
	 * third element if the new lock value (if available). 
	 */ 
	public static final long[] lock(int hash, int owner, int ownerClock) {
		// read the lock 
		int lockIndex = hash & HASH_MASK;
		long lock = locks.get(lockIndex);
 
		// prepare the result object 
		long[] res = new long[3];
		res[1] = lock;
		 
		// try to acquire the lock if it is free  
		if (!isLocked(lock)) {
			long newLock = generateLock(owner, ownerClock, getVersion(lock));
			boolean cas = locks.compareAndSet(lockIndex, lock, newLock);
			if (cas) {
				// 0 means lock acquired 
				res[0] = 0L;
				res[2] = newLock;
			} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 AtomicLongArray Methods: