Package com.globalmentor.collections
Class ThreadedQueue
- java.lang.Object
-
- com.globalmentor.collections.ThreadedQueue
-
- All Implemented Interfaces:
ObjectProcessor
,java.lang.Runnable
public class ThreadedQueue extends java.lang.Object implements java.lang.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 theObjectProcessor
constructor, specifying itself or another class as the object processor.- Author:
- Garret Wilson
-
-
Constructor Summary
Constructors Constructor Description ThreadedQueue()
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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(java.lang.Object object)
Deprecated.Adds an object to the end of the queue and notifies the processing thread.protected void
finalize()
Deprecated.Cleans up the queue when it is garbage collected.java.lang.Object
get()
Deprecated.Gets the next object from the queue in first in, first out sequence.void
process()
Deprecated.Processes any objects in the queue.void
process(java.lang.Object object)
Deprecated.Processes a single object in the queue.void
run()
Deprecated.The method which executes as the processing thread.int
size()
Deprecated.void
start()
Deprecated.Causes this queue to begin processing its contents, if any, in a separate thread of execution.void
stop()
Deprecated.Stops the thread that is processing this queue's contents.
-
-
-
Constructor Detail
-
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, ornull
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, ornull
if this class should be used as the object processor.autoStart
-true
if the processing thread should start automatically.
-
-
Method Detail
-
finalize
protected void finalize() throws java.lang.Throwable
Deprecated.Cleans up the queue when it is garbage collected. Allows the queue processing thread to stop.- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.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:
Thread.start()
-
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(java.lang.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 java.lang.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 interfacejava.lang.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 theprocess(Object)
method be overridden instead of this method.
-
process
public void process(java.lang.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 interfaceObjectProcessor
- Parameters:
object
- The object to process.
-
-