package devmanuals.com; import java.util.concurrent.BlockingDeque; import java.util.concurrent.LinkedBlockingDeque; class Push implements Runnable { String name; BlockingDeque bdq; public Push(String name, BlockingDeque bdq) { this.name = name; this.bdq = bdq; } public void run() { System.out.println(name + " inserted the element into the deque"); for (int i = 1; i < 6; i++) { bdq.offer(i); try { System.out.println(i); Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } // Here the implementation of this method will insert a new element into // the deque. bdq.push(11); System.out .println("After inserting the new element \n at first position deque = " + bdq); } } class Push1 implements Runnable { String name; BlockingDeque bdq; public Push1(String name, BlockingDeque bdq) { this.name = name; this.bdq = bdq; } public void run() { try { Thread.sleep(1500); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Therfore deque = " + bdq); System.out.println("Size of deque = " + bdq.size()); int j = bdq.pollFirst(); System.out.println("After removing the first element (" + j + "), the remaining \n elements of deque = " + bdq + " and size = " + bdq.size()); } } public class BdqPush { public static void main(String[] args) { BlockingDeque bdq = new LinkedBlockingDeque(5); Runnable a = new Push("A", bdq); Runnable b = new Push1("B", bdq); new Thread(a).start(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } new Thread(b).start(); } }