package devmanuals.com; import java.util.concurrent.BlockingDeque; import java.util.concurrent.LinkedBlockingDeque; class Element implements Runnable { BlockingDeque bdq; public Element(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.element(); System.out.println(obj); bol = bdq.contains(4); System.out.println("The element " + obj + " is still present into the deque? "); Thread.sleep(1000); System.out.println(bol); bdq.clear(); System.out.println("The first element of deque is : "); Integer obj1= bdq.element();//This call of element()method will displayed the exception Thread.sleep(2000); System.out.println(obj1); } catch (InterruptedException e) { e.printStackTrace(); } } } public class BdqElement { public static void main(String[] args) { BlockingDeque bdq = new LinkedBlockingDeque(); Runnable a = new Element(bdq); new Thread(a).start(); } }