summaryrefslogtreecommitdiffstats
path: root/jrt/src/com/yahoo/jrt/ThreadQueue.java
diff options
context:
space:
mode:
Diffstat (limited to 'jrt/src/com/yahoo/jrt/ThreadQueue.java')
-rw-r--r--jrt/src/com/yahoo/jrt/ThreadQueue.java18
1 files changed, 16 insertions, 2 deletions
diff --git a/jrt/src/com/yahoo/jrt/ThreadQueue.java b/jrt/src/com/yahoo/jrt/ThreadQueue.java
index 119008d835d..b758a30214a 100644
--- a/jrt/src/com/yahoo/jrt/ThreadQueue.java
+++ b/jrt/src/com/yahoo/jrt/ThreadQueue.java
@@ -21,8 +21,22 @@ class ThreadQueue
* was closed
* @param obj the object to enqueue
**/
- public synchronized boolean enqueue(Object obj) {
- if (closed) {
+ public boolean enqueue(Object obj) {
+ return enqueue(obj, Integer.MAX_VALUE);
+ }
+
+ /**
+ * Enqueue an object on this queue. If the queue has been closed or
+ * the queue already contains too many items, the object will not be
+ * queued, and this method will return false.
+ *
+ * @return true if the object was enqueued, false if this queue
+ * was closed or too large
+ * @param obj the object to enqueue
+ * @param limit more elements than this means the queue is too large
+ **/
+ public synchronized boolean enqueue(Object obj, int limit) {
+ if (closed || (queue.size() > limit)) {
return false;
}
queue.enqueue(obj);