|
qflib 0.99 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.qfs.lib.util.ResourceWaiter
This class is useful in cases where several Threads are waiting for a limited number of resources. Instead of simply calling wait, a ResourceWaiter can be pushed onto a queue. When a resource becomes available, the next waiter is popped from the queue and handed the resource, so no other Thread can grab it first.
The ThreadPool
is an example for a class that makes use
of a ResourceWaiter.
Constructor Summary | |
ResourceWaiter()
Create a new ResourceWaiter |
|
ResourceWaiter(java.lang.Object lock)
Create a new ResourceWaiter |
Method Summary | |
void |
handResource(java.lang.Object object)
Pass an Object to the ResourceWaiter. |
java.lang.Object |
waitFor(long timeout)
Wait until either someone hands an Object to the waiter or a timeout is reached. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ResourceWaiter()
public ResourceWaiter(java.lang.Object lock)
lock
- The object to wait on. When using a ResourceWaiter from
a synchronized method, make sure to use the same lock
for the ResourceWaiter that the caller owns, otherwise
deadlocks will occur.Method Detail |
public java.lang.Object waitFor(long timeout)
timeout
- The maximum time to wait in milliseconds. Negative
means wait indefinitely.
public void handResource(java.lang.Object object)
object
- The Object that the ResourceWaiter waited for. This
will cause the waitFor method of the ResourceWaiter
to continue and hand the object back to its caller.
|
qflib 0.99 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |