本文整理了Java中java.util.Deque.offer()
方法的一些代码示例,展示了Deque.offer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Deque.offer()
方法的具体详情如下:
包路径:java.util.Deque
类名称:Deque
方法名:offer
[英]Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and false if no space is currently available. When using a capacity-restricted deque, this method is generally preferable to the #add method, which can fail to insert an element only by throwing an exception.
This method is equivalent to #offerLast.
[中]如果可以在不违反容量限制的情况下立即将指定元素插入此deque表示的队列(换句话说,在该deque的末尾),则在成功时返回true,如果当前没有可用空间,则返回false。当使用容量受限的deque时,这种方法通常比#add方法更可取,后者只能通过抛出异常才能插入元素。
此方法相当于#offerLast。
代码示例来源:origin: netty/netty
/**
* Offer a {@link Channel} back to the internal storage. This will return {@code true} if the {@link Channel}
* could be added, {@code false} otherwise.
*
* Sub-classes may override {@link #pollChannel()} and {@link #offerChannel(Channel)}. Be aware that
* implementations of these methods needs to be thread-safe!
*/
protected boolean offerChannel(Channel channel) {
return deque.offer(channel);
}
代码示例来源:origin: google/guava
public void testHoldsLockOnAllOperations() {
create().element();
create().offer("foo");
create().peek();
create().poll();
代码示例来源:origin: redisson/redisson
/**
* Offer a {@link Channel} back to the internal storage. This will return {@code true} if the {@link Channel}
* could be added, {@code false} otherwise.
*
* Sub-classes may override {@link #pollChannel()} and {@link #offerChannel(Channel)}. Be aware that
* implementations of these methods needs to be thread-safe!
*/
protected boolean offerChannel(Channel channel) {
return deque.offer(channel);
}
代码示例来源:origin: wildfly/wildfly
/**
* Offer a {@link Channel} back to the internal storage. This will return {@code true} if the {@link Channel}
* could be added, {@code false} otherwise.
*
* Sub-classes may override {@link #pollChannel()} and {@link #offerChannel(Channel)}. Be aware that
* implementations of these methods needs to be thread-safe!
*/
protected boolean offerChannel(Channel channel) {
return deque.offer(channel);
}
代码示例来源:origin: btraceio/btrace
@Override
public synchronized boolean offer(V e) {
return delegate.offer(e);
}
代码示例来源:origin: graphql-java/graphql-java
public void enqueue(DeferredCall deferredCall) {
deferDetected.set(true);
deferredCalls.offer(deferredCall);
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public boolean offer(E e) {
boolean res = deque.offer(e);
if (res)
adder.increment();
return res;
}
代码示例来源:origin: EngineHub/WorldEdit
/**
* Add a new operation to the queue.
*
* @param operation the operation
*/
public void offer(Operation operation) {
checkNotNull(operation);
queue.offer(operation);
}
代码示例来源:origin: neo4j/neo4j
private void flush()
{
if ( chunkCursor > 0 )
{
synchronized ( chunks )
{
Chunk<T> chunkToAdd = new Chunk<>( thresholdSupplier.get(), copyOf( chunk, chunkCursor ) );
chunks.offer( chunkToAdd );
}
chunkCursor = 0;
}
}
代码示例来源:origin: google/guava
@Override
public boolean offer(E o) {
assertTrue(Thread.holdsLock(mutex));
return delegate.offer(o);
}
代码示例来源:origin: graphql-java/graphql-java
/**
* Called from the producing code to offer data up ready for a subscriber to read it
*
* @param data the data to offer
*/
public void offer(T data) {
mutex.execute(() -> dataQ.offer(data));
}
代码示例来源:origin: k9mail/k-9
void releaseConnection(ImapConnection connection) {
if (connection != null && connection.isConnected()) {
synchronized (connections) {
connections.offer(connection);
}
}
}
代码示例来源:origin: wildfly/wildfly
private void enqueueFrameWithoutMerge(FlowControlled frame) {
pendingWriteQueue.offer(frame);
// This must be called after adding to the queue in order so that hasFrame() is
// updated before updating the stream state.
incrementPendingBytes(frame.size(), true);
}
代码示例来源:origin: ReactiveX/RxJava
case DROP_LATEST:
dq.pollLast();
dq.offer(t);
callOnOverflow = true;
break;
case DROP_OLDEST:
dq.poll();
dq.offer(t);
callOnOverflow = true;
break;
dq.offer(t);
代码示例来源:origin: apache/rocketmq
/**
* It's a heavy init method.
*/
public void init() {
for (int i = 0; i < poolSize; i++) {
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fileSize);
final long address = ((DirectBuffer) byteBuffer).address();
Pointer pointer = new Pointer(address);
LibC.INSTANCE.mlock(pointer, new NativeLong(fileSize));
availableBuffers.offer(byteBuffer);
}
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public void onMessage(UUID nodeId, Message msg, IgniteRunnable msgC) {
msgC.run();
if (msg instanceof GridTestMessage) {
GridTestMessage testMsg = (GridTestMessage)msg;
if (!testMsg.getSourceNodeId().equals(nodeId))
fail("Listener nodeId is not equal to message nodeId.");
if (!reject)
rcvdMsgs.offer(testMsg);
if (!locNodeId.equals(nodeId))
rmtMsgCnt.incrementAndGet();
}
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public void onMessage(UUID nodeId, Message msg, IgniteRunnable msgC) {
msgC.run();
if (msg instanceof GridTestMessage) {
GridTestMessage testMsg = (GridTestMessage)msg;
if (!testMsg.getSourceNodeId().equals(nodeId))
fail("Listener nodeId is not equal to message nodeId.");
if (!reject)
rcvdMsgs.offer(testMsg);
if (!locNodeId.equals(nodeId))
rmtMsgCnt.incrementAndGet();
}
else
fail();
}
代码示例来源:origin: netty/netty
cachedNioBuffers.offer(nioBuffer);
代码示例来源:origin: redisson/redisson
cachedNioBuffers.offer(nioBuffer);
代码示例来源:origin: Netflix/zuul
else if (connections.offer(conn)) {
conn.setInPool(true);
connsInPool.incrementAndGet();
内容来源于网络,如有侵权,请联系作者删除!