Class SyncProcessingQueue<T>


  • public class SyncProcessingQueue<T>
    extends java.lang.Object
    Multiple producer-single consumer queue. The producers are expected to call pushAndWait(), the consumer should call pop() in a loop and if a null is returned (meaning that the queue is either empty or the limit of elements processed in a loop has been reached, to call notifyAndWait(). Example: while (running) { T element = queue.pop(); if (element != null) { process(element); } else { flush(); queue.notifyAndWait(); } } // terminate producers and process the rest of the queue queue.notifyNoWait();
    Author:
    Radim Vansa <rvansa@redhat.com>
    • Constructor Detail

      • SyncProcessingQueue

        public SyncProcessingQueue()
      • SyncProcessingQueue

        public SyncProcessingQueue​(int maxPoppedInRow)
    • Method Detail

      • pushAndWait

        public void pushAndWait​(T element)
                         throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • push

        public long push​(T element)
      • waitFor

        protected void waitFor​(long myIndex)
                        throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • pop

        public T pop()
      • notifyAndWait

        public void notifyAndWait()
      • notifyNoWait

        public void notifyNoWait()
      • notifyError

        public void notifyError()