Example usage for java.util.concurrent ArrayBlockingQueue ArrayBlockingQueue

List of usage examples for java.util.concurrent ArrayBlockingQueue ArrayBlockingQueue

Introduction

In this page you can find the example usage for java.util.concurrent ArrayBlockingQueue ArrayBlockingQueue.

Prototype

public ArrayBlockingQueue(int capacity, boolean fair, Collection<? extends E> c) 

Source Link

Document

Creates an ArrayBlockingQueue with the given (fixed) capacity, the specified access policy and initially containing the elements of the given collection, added in traversal order of the collection's iterator.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    List<Integer> list = Arrays.asList(new Integer[] { 0, 1, 2, 3 });

    int capacity = 100;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity, true, list);
    queue.put(0);/*  www. j a v  a 2s. c o  m*/
    queue.put(1);
    queue.put(2);
    System.out.println(queue);
    System.out.println(list);
}

From source file:Main.java

public static <E> ArrayBlockingQueue<E> newArrayBlockingQueue(final int capacity, final boolean fair,
        final Collection<? extends E> c) {
    return new ArrayBlockingQueue<E>(capacity, fair, c);
}

From source file:org.jiemamy.utils.collection.CollectionsUtil.java

/**
 * {@link ArrayBlockingQueue}?????//  w  w w  .  j  a v a  2s. c om
 * 
 * @param <E> {@link ArrayBlockingQueue}??
 * @param capacity ??
 * @param fair {@code true}???????????
 * @param c ?????
 * @return {@link ArrayBlockingQueue}???
 * @throws IllegalArgumentException {@code c}?{@code null}???
 * @throws IllegalArgumentException if {@code capacity} is less than {@code c.size()}, or less than 1.
 * @see ArrayBlockingQueue#ArrayBlockingQueue(int, boolean, Collection)
 */
public static <E> ArrayBlockingQueue<E> newArrayBlockingQueue(int capacity, boolean fair,
        Collection<? extends E> c) {
    Validate.notNull(c);
    return new ArrayBlockingQueue<E>(capacity, fair, c);
}