|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.resilientedge.util.workerPool.WaitQueue
This class provides a queuing mechanism so threads may wait for
notification of an event, and are notified in FIFO order. A worker thread
is 'added' to this queue with add(...)
method. Notification is
requested through notifyNext()
method, and notification is
provided only for the next item in the queue.
Logically the worker thread may be thought of as being in the queue, but actually a q-item is maintained in the queue. A worker thread that is added to the queue, has a q-item that is associated with the thread that is actually added to the queue. The thread waits for either notification its associated q-item has been removed from the queue, or its wait-time has expired.
It is possible for a worker thread to be 'added' to the queue, right after a notify has been tried for on an empty queue, because of the nature of multi-threaded programs. If no other notifications are attempted the 'added' worker thread will wait until the specified wait-time expires. Therefore if unlimited wait time is supported an external (outside of this class) mechanism must be implemented to ensure this scenario doesn't occur or the worker thread will be in an indefinite wait. Additionally, even if wait-times are used, the object returned when the worker thread completes the 'add' process should always be examined to determine if completion was the result of a wait-time expiration and appropriate action taken if true.
Queue statistics are maintained by an instance of WaitQStats. These
statistics may be examined via getQStats
.
Constructor Summary | |
WaitQueue()
Default constructor. |
|
WaitQueue(java.lang.String id)
Constructor to specify an identifier for the queue. |
Method Summary | |
java.lang.Object |
add()
Add the current thread to the wait queue, and have it wait indefinitely for the resource to become available. |
java.lang.Object |
add(long waitTime)
Add the current thread to the wait queue. |
java.lang.Object |
add(java.lang.Object evtObj,
long waitTime)
Add the current thread to the wait queue. |
protected WaitQStats |
createStats(java.lang.String id)
|
WaitQStats |
getQStats()
|
boolean |
notifyNext(java.lang.Object evtObj)
Remove the next item in the queue and notify the corresponding thread the item has been removed. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public WaitQueue()
public WaitQueue(java.lang.String id)
id
- a queue identifierMethod Detail |
public WaitQStats getQStats()
public java.lang.Object add()
notifyNext()
is
requested. If time-out occurs this value is always null.public java.lang.Object add(long waitTime)
waitTime
- the maximum time to wait in milliseconds, if the value
is zero,the thread waits until notifiednotifyNext()
is requested. If time-out occurs this value is always null.public java.lang.Object add(java.lang.Object evtObj, long waitTime)
notifyNext()
method.evtObj
- an object to be returned if the maximum wait time is
exceeded (or the wait is interrupted), it may be nullwaitTime
- the maximum time to wait in milliseconds, it must be
greater than or equal to zero. if the value is zero, the thread waits
idefinitely until notification is provided.notifyNext()
is requested or the original event object if the the maximum
wait time is exceeded.public boolean notifyNext(java.lang.Object evtObj)
evtObj
- the object that is to be given to the item when it is
removed from the queue. This object is returned when the thread
associated with the q-item awakens. This may be null.protected WaitQStats createStats(java.lang.String id)
id
- Parameter Description
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |