package com.example.data; public class DualStackQueue> { private GenericStack producerStack; private GenericStack consumerStack; DualStackQueue() { producerStack = new GenericStack(); consumerStack = new GenericStack(); } public void write(T data) { synchronized (producerStack) { producerStack.push(data); producerStack.notify(); } } public T read() { if (consumerStack.isEmpty()) { transfer(); } return consumerStack.pop(); } private void transfer() { synchronized (producerStack) { while (producerStack.isEmpty()) { try { producerStack.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } do { consumerStack.push(producerStack.pop()); } while (!producerStack.isEmpty()); producerStack.notify(); } } }