package devmanuals.com; import java.util.concurrent.BlockingDeque; import java.util.concurrent.LinkedBlockingDeque; class Poll implements Runnable { BlockingDeque bdq; public Poll(BlockingDeque bdq) { this.bdq = bdq; } public void run() { System.out.println("Elements of deque are : "); int i; boolean bol = false; for (i = 0; i < 5; i++) { bdq.add(i); } System.out.println(bdq); System.out.println("Size of deque = "+ bdq.size()); try { Thread.sleep(500); System.out.println("The first element of deque is = "); Thread.sleep(1000); Integer obj = bdq.poll(); System.out.println(obj); bol = bdq.contains(obj); System.out.println("The element " + obj + " is still present into the deque :"); Thread.sleep(1000); System.out.println(bol); System.out.println("Now removed all the elements from the deque"); bdq.clear(); System.out.println("Therefore the deque is "+bdq+" empty"); obj=bdq.poll();//Calling of this method will return 'null' System.out.println("The head element = "+obj); } catch (InterruptedException e) { e.getMessage(); } } } public class BdqPoll { public static void main(String[] args) { BlockingDeque bdq = new LinkedBlockingDeque(); Runnable a = new Poll(bdq); new Thread(a).start(); } }