121 * added to this queue. If zero, block indefinitely.
122 *
123 * @return A reference object, if one was available within the specified
124 * timeout period, otherwise <code>null</code>
125 *
126 * @throws IllegalArgumentException
127 * If the value of the timeout argument is negative
128 *
129 * @throws InterruptedException
130 * If the timeout wait is interrupted
131 */
132 public Reference<? extends T> remove(long timeout)
133 throws IllegalArgumentException, InterruptedException
134 {
135 if (timeout < 0) {
136 throw new IllegalArgumentException("Negative timeout value");
137 }
138 synchronized (lock) {
139 Reference<? extends T> r = reallyPoll();
140 if (r != null) return r;
141 for (;;) {
142 lock.wait(timeout);
143 r = reallyPoll();
144 if (r != null) return r;
145 if (timeout != 0) return null;
146 }
147 }
148 }
149
150 /**
151 * Removes the next reference object in this queue, blocking until one
152 * becomes available.
153 *
154 * @return A reference object, blocking until one becomes available
155 * @throws InterruptedException If the wait is interrupted
156 */
157 public Reference<? extends T> remove() throws InterruptedException {
158 return remove(0);
159 }
160
161 }
|
121 * added to this queue. If zero, block indefinitely.
122 *
123 * @return A reference object, if one was available within the specified
124 * timeout period, otherwise <code>null</code>
125 *
126 * @throws IllegalArgumentException
127 * If the value of the timeout argument is negative
128 *
129 * @throws InterruptedException
130 * If the timeout wait is interrupted
131 */
132 public Reference<? extends T> remove(long timeout)
133 throws IllegalArgumentException, InterruptedException
134 {
135 if (timeout < 0) {
136 throw new IllegalArgumentException("Negative timeout value");
137 }
138 synchronized (lock) {
139 Reference<? extends T> r = reallyPoll();
140 if (r != null) return r;
141 long start = (timeout == 0) ? 0 : System.nanoTime();
142 for (;;) {
143 lock.wait(timeout);
144 r = reallyPoll();
145 if (r != null) return r;
146 if (timeout != 0) {
147 long end = System.nanoTime();
148 timeout -= (end - start) / 1000_000;
149 if (timeout <= 0) return null;
150 start = end;
151 }
152 }
153 }
154 }
155
156 /**
157 * Removes the next reference object in this queue, blocking until one
158 * becomes available.
159 *
160 * @return A reference object, blocking until one becomes available
161 * @throws InterruptedException If the wait is interrupted
162 */
163 public Reference<? extends T> remove() throws InterruptedException {
164 return remove(0);
165 }
166
167 }
|