All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.linkedin.dagli.objectio.ArrayAlwaysBlockingQueue Maven / Gradle / Ivy

Go to download

DAG-oriented machine learning framework for bug-resistant, readable, efficient, maintainable and trivially deployable models in Java and other JVM languages

There is a newer version: 15.0.0-beta9
Show newest version
package com.linkedin.dagli.objectio;

import com.concurrentli.UncheckedInterruptedException;
import java.util.concurrent.ArrayBlockingQueue;


/**
 * ArrayBlockingQueue, despite its misleading name, will not actually block when excessive work is scheduled on a client
 * ThreadPoolExecutor (which calls offer rather than put).  This class, however, will always block; its offer method
 * thus always returns true.
 *
 * @param  the type of element to enqueue
 */
class ArrayAlwaysBlockingQueue extends ArrayBlockingQueue {
  /**
   * Creates a new instance with the specified capacity.
   *
   * @param capacity the capacity of the queue.
   */
  public ArrayAlwaysBlockingQueue(int capacity) {
    super(capacity);
  }

  @Override
  public boolean add(T item) {
    return offer(item);
  }

  @Override
  public boolean offer(T item) {
    try {
      put(item);
      return true;
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new UncheckedInterruptedException(e);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy