|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.groboutils.util.thread.v1.LoopThread
net.sourceforge.groboutils.util.thread.v1.QueueThread
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 processRemaining()
.
Field Summary |
Fields inherited from class net.sourceforge.groboutils.util.thread.v1.LoopThread |
MILLI_IN_SECOND |
Constructor Summary | |
QueueThread(IObjectListener ol)
|
|
QueueThread(IObjectListener ol,
java.lang.String threadName)
|
|
QueueThread(IObjectListener ol,
SynchQueue sq)
|
|
QueueThread(IObjectListener ol,
SynchQueue sq,
java.lang.String threadName)
|
|
QueueThread(IObjectListener ol,
SynchQueue sq,
java.lang.ThreadGroup tg)
|
|
QueueThread(IObjectListener ol,
SynchQueue sq,
java.lang.ThreadGroup tg,
java.lang.String threadName)
|
|
QueueThread(IObjectListener ol,
java.lang.ThreadGroup tg)
|
|
QueueThread(IObjectListener ol,
java.lang.ThreadGroup tg,
java.lang.String threadName)
|
Method Summary | |
SynchQueue |
getQueue()
Retrieves the internal listened queue. |
long |
getTimeoutMilliseconds()
Retrieve the millisecond part of the maximum timeout to wait for an incoming element on the inner queue before checking for thread event signals. |
int |
getTimeoutNanoseconds()
Retrieve the nanosecond part of the maximum timeout to wait for an incoming element on the inner queue before checking for thread event signals. |
protected void |
initialize(IObjectListener ol,
SynchQueue sq)
|
protected void |
initializeDefaults()
|
boolean |
isProcessingObjects()
|
void |
processRemaining()
Process all elements in the queue until the queue is empty. |
void |
setTimeout(long timeout)
Set the maximum time (in milliseconds) to wait for an incoming element on the inner queue before checking for LoopThread.stop() and LoopThread.suspend()
signals. |
void |
setTimeout(long timeout,
int nanos)
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. |
Methods inherited from class net.sourceforge.groboutils.util.thread.v1.LoopThread |
getPriority, getSleepTime, getSleepTimeMillis, getThreadGroup, isAlive, isDaemon, isPaused, isRunning, join, resume, setDaemon, setPriority, setRunnable, setSleepTime, setSleepTimeMillis, start, stop, suspend, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public QueueThread(IObjectListener ol)
public QueueThread(IObjectListener ol, SynchQueue sq)
public QueueThread(IObjectListener ol, java.lang.ThreadGroup tg)
public QueueThread(IObjectListener ol, SynchQueue sq, java.lang.ThreadGroup tg)
public QueueThread(IObjectListener ol, java.lang.String threadName)
public QueueThread(IObjectListener ol, SynchQueue sq, java.lang.String threadName)
public QueueThread(IObjectListener ol, java.lang.ThreadGroup tg, java.lang.String threadName)
public QueueThread(IObjectListener ol, SynchQueue sq, java.lang.ThreadGroup tg, java.lang.String threadName)
Method Detail |
public SynchQueue getQueue()
public boolean isProcessingObjects()
public void setTimeout(long timeout, int nanos)
LoopThread.stop()
and LoopThread.suspend()
signals.
timeout
- the maximum time to wait in milliseconds.nanos
- additional time, in nanoseconds range 0-999999.SynchQueue.dequeue( long, int )
public void setTimeout(long timeout)
LoopThread.stop()
and LoopThread.suspend()
signals.
timeout
- the maximum time to wait in milliseconds.SynchQueue.dequeue( long, int )
,
setTimeout( long, int )
public long getTimeoutMilliseconds()
setTimeout( long, int )
public int getTimeoutNanoseconds()
setTimeout( long, int )
public void processRemaining() throws java.lang.InterruptedException
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).
java.lang.InterruptedException
protected void initialize(IObjectListener ol, SynchQueue sq)
protected void initializeDefaults()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |