本文整理汇总了Java中java.util.concurrent.BlockingQueue.peek方法的典型用法代码示例。如果您正苦于以下问题:Java BlockingQueue.peek方法的具体用法?Java BlockingQueue.peek怎么用?Java BlockingQueue.peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.BlockingQueue
的用法示例。
在下文中一共展示了BlockingQueue.peek方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
BlockingQueue<String> queue = new ArrayBlockingQueue<>(1);
queue.add("add");
//
String peek = queue.peek();
System.out.println(peek);
queue.poll();
boolean offer = queue.offer("offer");
if (!offer) {
System.out.println("it is't possible to do so immediately");
}
System.out.println(queue.take());
queue.put("put operation");
System.out.println(queue.take());
}
示例2: peek
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
* Peek, like poll, provides no strict consistency.
*/
@Override
public E peek() {
BlockingQueue<E> q = this.getFirstNonEmptyQueue(0);
if (q == null) {
return null;
} else {
return q.peek();
}
}
示例3: headSlowTimeMills
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
public long headSlowTimeMills(BlockingQueue<Runnable> q) {
long slowTimeMills = 0;
final Runnable peek = q.peek();
if (peek != null) {
RequestTask rt = BrokerFastFailure.castRunnable(peek);
slowTimeMills = rt == null ? 0 : this.messageStore.now() - rt.getCreateTimestamp();
}
if (slowTimeMills < 0)
slowTimeMills = 0;
return slowTimeMills;
}