Code example for Queue

Methods: add

0
    buf.clear(); // reset mark, limit, etc
    int size = buf.capacity();
    Queue<WeakReference<ByteBuffer>> list = buffersBySize.get(size);
    if (list == null) {
      list = new ConcurrentLinkedQueue<WeakReference<ByteBuffer>>();
      Queue<WeakReference<ByteBuffer>> prev = buffersBySize.putIfAbsent(size, list);
      // someone else put a queue in the map before we did 
      if (prev != null) {
        list = prev;
      } 
    } 
    list.add(new WeakReference<ByteBuffer>(buf));
  } 
   
  /** 
   * Return the number of available buffers of a given size. 
   * This is used only for tests. 
   */ 
  @VisibleForTesting 
  int countBuffersOfSize(int size) {