Example usage for java.util.concurrent ArrayBlockingQueue add

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

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Inserts the specified element at the tail of this queue if it is possible to do so immediately without exceeding the queue's capacity, returning true upon success and throwing an IllegalStateException if this queue is full.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 10;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);
    }//w  w w  .ja  va  2s  .  co  m
    System.out.println(queue.poll());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 100;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 100; i++) {
        queue.add(i);
    }/*from   w  ww. j ava 2  s  .c om*/

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 100;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 100; i++) {
        queue.add(i);
    }/*from  w ww .  ja v a 2s .  c o m*/
    queue.clear();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 10;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);
    }/*from ww  w  .  ja  va2s  . com*/

    System.out.println(queue.toString());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 10;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);
    }/* w ww  . j  a va 2  s .  c  o  m*/
    queue.offer(9999);
    System.out.println(queue);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 10;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);
    }//from www .j  av a 2 s. c o  m

    System.out.println(Arrays.toString(queue.toArray()));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 10;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);
    }/*from   www.  j ava  2  s  . co  m*/
    queue.offer(9999, 10, TimeUnit.MINUTES);
    System.out.println(queue);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 10;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);
    }//from w w w  .j  ava 2 s .  co m

    System.out.println(queue.remainingCapacity());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 10;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);
    }/*from   www . j  a va2s .c om*/

    System.out.println(Arrays.toString(queue.toArray(new Integer[queue.size()])));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 10;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);
    }/*from   w  ww . ja  va 2 s .  c om*/

    System.out.println(queue.poll(10, TimeUnit.MINUTES));
}