Java ArrayBlockingQueue.poll(long timeout, TimeUnit unit)

Syntax

ArrayBlockingQueue.poll(long timeout, TimeUnit unit) has the following syntax.

public E poll(long timeout, TimeUnit unit) throws InterruptedException

Example

In the following code shows how to use ArrayBlockingQueue.poll(long timeout, TimeUnit unit) method.


import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
/*  w  w w .j  a v  a2 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);
    }
    
    System.out.println(queue.poll(10,TimeUnit.MINUTES));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.util.concurrent »




ArrayBlockingQueue
BlockingDeque
CountDownLatch
CyclicBarrier
TimeUnit