package devmanuals.com; import java.util.concurrent.BlockingDeque; import java.util.concurrent.LinkedBlockingDeque; class TakeFirst implements Runnable { BlockingDeque bdq; String name; public TakeFirst(String name, BlockingDeque bdq) { this.bdq = bdq; this.name = name; } public void run() { int i; System.out.println(name + " inserted the element into the deque"); for (i = 0; i < 5; i++) { bdq.add(i); System.out.println(i); try { Thread.sleep(400); } catch (InterruptedException e) { e.printStackTrace(); } } } } class TakeFirst1 implements Runnable { String name; BlockingDeque bdq; public TakeFirst1(String name, BlockingDeque bdq) { this.bdq = bdq; this.name = name; } public void run() { try { //Implementation of the method int j = bdq.takeFirst(); Thread.sleep(1500); System.out.println(name + " deleted the first element then remaining deque = " + bdq); System.out.println("The deleted element is = "+j); System.out.println("Size of remaining deque = "+bdq.size()); } catch (InterruptedException e) { e.printStackTrace(); } } } public class BdqTakeFirst { public static void main(String args[]) { BlockingDeque bdq = new LinkedBlockingDeque(5); Runnable a = new TakeFirst("A", bdq); new Thread(a).start(); try { Thread.sleep(400); } catch (InterruptedException e) { e.printStackTrace(); } Runnable b = new TakeFirst1("B", bdq); new Thread(b).start(); } }