Class ThreadedQueue

java.lang.Object
com.globalmentor.collections.ThreadedQueue
All Implemented Interfaces:
ObjectProcessor, Runnable

public class ThreadedQueue extends Object implements Runnable, ObjectProcessor
Deprecated.
A queue of objects that, once an object is added to a queue, will process the queue contents in a separate thread. Once all objects in the queue have been processed, the separate thread will block until more objects are added to the queue.

The queue does not start processing automatically unless constructed with the autostart constructor. Otherwise, it must first be started by calling its start() method.

A subclass may override process(Object), or use the ObjectProcessor constructor, specifying itself or another class as the object processor.

Author:
Garret Wilson
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
    Default constructor that does not start the processing thread and uses this class as an object processor.
    ThreadedQueue(boolean autoStart)
    Deprecated.
    Autostart constructor that uses this class as the object processor.
    ThreadedQueue(ObjectProcessor newObjectProcessor)
    Deprecated.
    Object processor that does not automatically start the processing thread.
    ThreadedQueue(ObjectProcessor newObjectProcessor, boolean autoStart)
    Deprecated.
    Object processor autostart constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(Object object)
    Deprecated.
    Adds an object to the end of the queue and notifies the processing thread.
    protected void
    Deprecated.
    Cleans up the queue when it is garbage collected.
    get()
    Deprecated.
    Gets the next object from the queue in first in, first out sequence.
    void
    Deprecated.
    Processes any objects in the queue.
    void
    process(Object object)
    Deprecated.
    Processes a single object in the queue.
    void
    run()
    Deprecated.
    The method which executes as the processing thread.
    int
    Deprecated.
     
    void
    Deprecated.
    Causes this queue to begin processing its contents, if any, in a separate thread of execution.
    void
    Deprecated.
    Stops the thread that is processing this queue's contents.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ThreadedQueue

      public ThreadedQueue()
      Deprecated.
      Default constructor that does not start the processing thread and uses this class as an object processor.
    • ThreadedQueue

      public ThreadedQueue(ObjectProcessor newObjectProcessor)
      Deprecated.
      Object processor that does not automatically start the processing thread.
      Parameters:
      newObjectProcessor - The object responsible for processing objects as they are added to the queue, or null if this class should be used as the object processor.
    • ThreadedQueue

      public ThreadedQueue(boolean autoStart)
      Deprecated.
      Autostart constructor that uses this class as the object processor.
      Parameters:
      autoStart - true if the processing thread should start automatically.
    • ThreadedQueue

      public ThreadedQueue(ObjectProcessor newObjectProcessor, boolean autoStart)
      Deprecated.
      Object processor autostart constructor.
      Parameters:
      newObjectProcessor - The object responsible for processing objects as they are added to the queue, or null if this class should be used as the object processor.
      autoStart - true if the processing thread should start automatically.
  • Method Details

    • finalize

      protected void finalize() throws Throwable
      Deprecated.
      Cleans up the queue when it is garbage collected. Allows the queue processing thread to stop.
      Overrides:
      finalize in class Object
      Throws:
      Throwable - Thrown if any error occurs during the method.
    • start

      public void start()
      Deprecated.
      Causes this queue to begin processing its contents, if any, in a separate thread of execution. If the queue is already started, no action is performed. //TODO del @throws IllegalThreadStateException Thrown if the processing thread was //TODO del already started.
      See Also:
    • stop

      public void stop()
      Deprecated.
      Stops the thread that is processing this queue's contents. This method blocks until the processing thread has processed all remaining objects in the queue. If the queue is already stopped, no action occurs.
    • add

      public void add(Object object)
      Deprecated.
      Adds an object to the end of the queue and notifies the processing thread. Nothing can be added to the queue while the queue is being started or stopped.
      Parameters:
      object - The object to add to the queue.
    • get

      public Object get()
      Deprecated.
      Gets the next object from the queue in first in, first out sequence.
      Returns:
      The first object waiting in the queue.
    • size

      public int size()
      Deprecated.
      Returns:
      The number of objects in the queue.
    • run

      public void run()
      Deprecated.
      The method which executes as the processing thread.
      Specified by:
      run in interface Runnable
    • process

      public void process()
      Deprecated.
      Processes any objects in the queue. Called from the processing thread when objects are added to the queue. It is recommended that the process(Object) method be overridden instead of this method.
    • process

      public void process(Object object)
      Deprecated.
      Processes a single object in the queue. Called from the processing thread when objects are added to the queue. The default constructor specifies this class as the object processor, so child classes can override this method to process each object if a separate object processor is not specified.
      Specified by:
      process in interface ObjectProcessor
      Parameters:
      object - The object to process.