我正在寻找一个队列,它应该是
如果有影响的话,应该只有一个轮询线程,并且轮询应该按顺序进行(在进行轮询时不会调用
我原以为在JVM中已经存在这个功能,但我找不到它,当然我更愿意使用JVM中的东西而不是自己编写。
另一个限制是,我被困在Java 8中(尽管我肯定很想知道在更近期的版本中存在什么)。
java.util.concurrent.BlockingQueue
的异步(非阻塞)等价物。其接口应包括以下内容:public interface AsynchronousBlockingQueue<E> {
// - if the queue is empty, return a new CompletableFuture,
// that will be completed next time `add` is called
// - if the queue is not empty, return a completed CompletableFuture,
containing the first element of the list
public CompletableFuture<E> poll();
// if polling is in progress, complete the ongoing polling CompletableFuture.
// otherwise, add the element to the queue
public synchronized void add(E element);
}
如果有影响的话,应该只有一个轮询线程,并且轮询应该按顺序进行(在进行轮询时不会调用
poll
)。我原以为在JVM中已经存在这个功能,但我找不到它,当然我更愿意使用JVM中的东西而不是自己编写。
另一个限制是,我被困在Java 8中(尽管我肯定很想知道在更近期的版本中存在什么)。