| java.lang.Object net.sourceforge.groboutils.util.thread.v1.LoopThread net.sourceforge.groboutils.util.thread.v1.QueueThread
QueueThread | public class QueueThread extends LoopThread (Code) | | For threads which endlessly process events from a SynchQueue. This
is a common technique for thread pooling.
Users must make a implementation of IObjectListener.
If the user does not give a SynchQueue, it is created for them.
Once the QueueThread is created, the queue and the listener cannot
be changed.
By default, the underlying
LoopThread does not sleep between events,
it is a daemon thread, runs on the lowest thread priority, and has
not started yet. Of course, this can all be changed.
It is advisable not to use the methods
LoopThread.setSleepTime(int) or
LoopThread.setSleepTimeMillis(long) , since these will cause the
QueueThread to not respond to incoming requests during this sleep
time. However, there may be occations when this is necessary, so this is
left available to the user.
Since the
SynchQueue.dequeue method can wait indefinitely, you may
opt to set the dequeue's timeout to something other than 0. Without setting
this, the thread may wait indefinitely for an incoming element to the queue
without ever checking for a
LoopThread.stop or
LoopThread.suspend signal. Thanks to
Dominique Gallot for pointing
this out.
After a
LoopThread.stop is invoked, you may allow the
object listener to finish processing the remaining elements in the
inner queue by calling
QueueThread.processRemaining() .
author: Matt Albrecht groboclown@users.sourceforge.net since: June 4, 2000 version: $Date: 2003/02/10 22:52:48 $ |
Constructor Summary | |
public | QueueThread(IObjectListener ol) | public | QueueThread(IObjectListener ol, SynchQueue sq) | public | QueueThread(IObjectListener ol, ThreadGroup tg) | public | QueueThread(IObjectListener ol, SynchQueue sq, ThreadGroup tg) | public | QueueThread(IObjectListener ol, String threadName) | public | QueueThread(IObjectListener ol, SynchQueue sq, String threadName) | public | QueueThread(IObjectListener ol, ThreadGroup tg, String threadName) | public | QueueThread(IObjectListener ol, SynchQueue sq, ThreadGroup tg, String threadName) |
getQueue | public SynchQueue getQueue()(Code) | | Retrieves the internal listened queue.
|
getTimeoutMilliseconds | public long getTimeoutMilliseconds()(Code) | | Retrieve the millisecond part of the maximum timeout to wait for an
incoming element on the inner queue before checking for thread
event signals.
See Also: QueueThread.setTimeout(long,int) |
getTimeoutNanoseconds | public int getTimeoutNanoseconds()(Code) | | Retrieve the nanosecond part of the maximum timeout to wait for an
incoming element on the inner queue before checking for thread
event signals.
See Also: QueueThread.setTimeout(long,int) |
initializeDefaults | protected void initializeDefaults()(Code) | | |
isProcessingObjects | public boolean isProcessingObjects()(Code) | | false if the thread is waiting for an objectto be placed in the queue and be processed, otherwisetrue. |
processRemaining | public void processRemaining() throws InterruptedException(Code) | | Process all elements in the queue until the queue is empty.
This may only be called while the thread is not running.
This should be invoked with care, as it can cause an infinite
loop if another thread is pushing in data after this processing
thread has finished (but, that could also lead to an out-of-memory
error if this method is never invoked).
|
setTimeout | public void setTimeout(long timeout, int nanos)(Code) | | Set the maximum time (in milliseconds and nanoseconds) to wait for
an incoming element on the inner queue before checking for
LoopThread.stop and
LoopThread.suspend signals.
Parameters: timeout - the maximum time to wait in milliseconds. Parameters: nanos - additional time, in nanoseconds range 0-999999. See Also: SynchQueue.dequeue(longint) |
Fields inherited from net.sourceforge.groboutils.util.thread.v1.LoopThread | final public static long MILLI_IN_SECOND(Code)(Java Doc)
|
|
|