Or don't interrupt, its nasty.
public class MyQueue<T> extends ArrayBlockingQueue<T> { private static final long serialVersionUID = 1L; private boolean done = false; public ParserQueue(int capacity) { super(capacity); } public void done() { done = true; } public boolean isDone() { return done; } /** * May return null if producer ends the production after consumer * has entered the element-await loopstate. */ public T take() throws InterruptedException { T el; while ((el = super.poll()) == null && !done) { synchronized (this) { wait(); } } return el; } } - when producer puts object to the queue, call
queue.notify(), if it ends, callqueue.done() - loop while (!queue.isDone() || !queue.isEmpty())
- test take() return value for null