Code example for BlockingQueue

Methods: take

  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) {
Stop searching for code, let great code find you!  Add Codota to your java IDE