Class WorkQueue<T>

  • Type Parameters:
    T - The work unit type.
    All Implemented Interfaces:
    AutoCloseable

    public class WorkQueue<T>
    extends Object
    implements AutoCloseable
    A parallel work queue.
    • Method Detail

      • addWorkUnit

        public void addWorkUnit​(T workUnit)
        Add a unit of work. May be called by workers to add more work units to the tail of the queue.
      • addWorkUnits

        public void addWorkUnits​(Collection<T> workUnits)
        Add multiple units of work. May be called by workers to add more work units to the tail of the queue.
        Parameters:
        workUnits - The work units to add to the tail of the queue.
      • close

        public void close()
        Ensure that there are no work units still uncompleted. This should be called after runWorkLoop() exits on the main thread (e.g. using try-with-resources, since this class is AutoCloseable). If any work units are still uncompleted (e.g. in the case of an exception), will shut down remaining workers.
        Specified by:
        close in interface AutoCloseable