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) 

Source Link

Document

Creates an ArrayBlockingQueue with the given (fixed) capacity and default access policy.

Usage

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 w w .  j  a v  a  2 s  .c om*/
    }
    System.out.println(queue.contains(5));
    queue.clear();
    System.out.println(queue.contains(5));
}

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  .j  a v a2s.com
    }

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

From source file:Main.java

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

    int numWorkers = 2;
    Worker[] workers = new Worker[numWorkers];
    for (int i = 0; i < workers.length; i++) {
        workers[i] = new Worker(queue);
        workers[i].start();//from  www .  j  a  v  a 2  s.  c  o  m
    }

    for (int i = 0; i < 100; i++) {
        queue.put(i);
    }
}

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  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;
    BlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);/*from  w  w  w  . j av a2s. c o m*/
    }
    Iterator<Integer> it = queue.iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

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  v  a 2  s  .com
    }
    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);// w w w  .  j  a  v a 2 s.c om
    }
    Iterator<Integer> it = queue.iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

From source file:Main.java

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

    int numWorkers = 2;
    Worker[] workers = new Worker[numWorkers];
    for (int i = 0; i < workers.length; i++) {
        workers[i] = new Worker(queue);
        workers[i].start();/*ww  w .  j ava2  s. c  o m*/
    }

    for (int i = 0; i < 100; i++) {
        queue.put(i);
    }
}

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  .j a v  a2s.  c  om
    }
    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.ja  va2 s .c o m*/
    }

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