Java ArrayBlockingQueue.offer(E e)

Syntax

ArrayBlockingQueue.offer(E e) has the following syntax.

public boolean offer(E e)

Example

In the following code shows how to use ArrayBlockingQueue.offer(E e) method.


import java.util.Iterator;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
/*from www  .  ja  v  a 2  s.c  o  m*/
public class Main {
  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);
    }
    queue.offer(9999);
    System.out.println(queue);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.util.concurrent »




ArrayBlockingQueue
BlockingDeque
CountDownLatch
CyclicBarrier
TimeUnit