Code example for BlockingQueue

Methods: take

0
  public PoolQueue(Collection<? extends T> objects) {
    this.objects = new ArrayBlockingQueue<T>(objects.size(), false, objects);
  } 
 
  public T request() throws InterruptedException { 
    return this.objects.take();
  } 
 
  /** 
   * Request an object, with a timeout 
   * @param timeout in milliseconds 
   * @return the requested object 
   * @throws InterruptedException 
   */ 
  public T request(long timeout) throws InterruptedException {
    return this.objects.poll(timeout, TimeUnit.MILLISECONDS);
  } 
 
  public void release(T object) throws InterruptedException {
    if (object != null) {
      this.objects.put(object);