本文整理了Java中java.util.concurrent.BlockingQueue.add()
方法的一些代码示例,展示了BlockingQueue.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BlockingQueue.add()
方法的具体详情如下:
包路径:java.util.concurrent.BlockingQueue
类名称:BlockingQueue
方法名:add
[英]Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available. When using a capacity-restricted queue, it is generally preferable to use #offer(Object).
[中]如果可以在不违反容量限制的情况下立即将指定元素插入此队列,则会在成功时返回true,如果当前没有可用空间,则会引发IllegalStateException。使用容量受限队列时,通常最好使用#offer(Object)。
代码示例来源:origin: google/guava
@Override
public void run() {
queue.add(future);
}
},
代码示例来源:origin: square/okhttp
public void enqueueResponse(MockResponse response) {
responseQueue.add(response);
}
代码示例来源:origin: square/okhttp
@Override public void shutdown() {
responseQueue.add(DEAD_LETTER);
}
代码示例来源:origin: prestodb/presto
@Override
public void run() {
queue.add(future);
}
},
代码示例来源:origin: redisson/redisson
@Override
public void operationComplete(io.netty.util.concurrent.Future<V> future) throws Exception {
completionQueue.add(f);
}
});
代码示例来源:origin: redisson/redisson
@Override
public void operationComplete(io.netty.util.concurrent.Future<V> future) throws Exception {
completionQueue.add(f);
}
});
代码示例来源:origin: netty/netty
/**
* Add a task to the task queue, or throws a {@link RejectedExecutionException} if this instance was shutdown
* before.
*/
private void addTask(Runnable task) {
if (task == null) {
throw new NullPointerException("task");
}
taskQueue.add(task);
}
代码示例来源:origin: greenrobot/greenDAO
public void enqueue(AsyncOperation operation) {
synchronized (this) {
operation.sequenceNumber = ++lastSequenceNumber;
queue.add(operation);
countOperationsEnqueued++;
if (!executorRunning) {
executorRunning = true;
executorService.execute(this);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
this.receivedMessages.add(message);
}
代码示例来源:origin: netty/netty
@Override
public void run() {
final SecureRandom random = new SecureRandom(); // Get the real random seed from /dev/random
final byte[] seed = random.generateSeed(8);
seedGeneratorEndTime = System.nanoTime();
long s = ((long) seed[0] & 0xff) << 56 |
((long) seed[1] & 0xff) << 48 |
((long) seed[2] & 0xff) << 40 |
((long) seed[3] & 0xff) << 32 |
((long) seed[4] & 0xff) << 24 |
((long) seed[5] & 0xff) << 16 |
((long) seed[6] & 0xff) << 8 |
(long) seed[7] & 0xff;
seedQueue.add(s);
}
};
代码示例来源:origin: apache/incubator-druid
@Override
public void statusChanged(String taskId, TaskStatus status)
{
notices.add(new RunNotice());
}
}, Execs.directExecutor()
代码示例来源:origin: square/okhttp
private void dispatchBookkeepingRequest(int sequenceNumber, Socket socket)
throws InterruptedException {
RecordedRequest request = new RecordedRequest(
null, null, null, -1, null, sequenceNumber, socket);
requestCount.incrementAndGet();
requestQueue.add(request);
dispatcher.dispatch(request);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void publishEvent(Object event) {
logger.debug("Processing ApplicationEvent " + event);
if (event instanceof BrokerAvailabilityEvent) {
this.eventQueue.add((BrokerAvailabilityEvent) event);
}
}
代码示例来源:origin: square/okhttp
@Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
// To permit interactive/browser testing, ignore requests for favicons.
final String requestLine = request.getRequestLine();
if (requestLine != null && requestLine.equals("GET /favicon.ico HTTP/1.1")) {
logger.info("served " + requestLine);
return new MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND);
}
if (failFastResponse != null && responseQueue.peek() == null) {
// Fail fast if there's no response queued up.
return failFastResponse;
}
MockResponse result = responseQueue.take();
// If take() returned because we're shutting down, then enqueue another dead letter so that any
// other threads waiting on take() will also return.
if (result == DEAD_LETTER) responseQueue.add(DEAD_LETTER);
return result;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void handleMessage(Message<?> message) throws MessagingException {
if (SimpMessageType.HEARTBEAT == SimpMessageHeaderAccessor.getMessageType(message.getHeaders())) {
return;
}
this.queue.add(message);
}
代码示例来源:origin: netty/netty
private void fetchFromScheduledTaskQueue() {
long nanoTime = AbstractScheduledEventExecutor.nanoTime();
Runnable scheduledTask = pollScheduledTask(nanoTime);
while (scheduledTask != null) {
taskQueue.add(scheduledTask);
scheduledTask = pollScheduledTask(nanoTime);
}
}
代码示例来源:origin: prestodb/presto
public synchronized void addPage(Page page)
{
checkState(completed.get() != Boolean.TRUE, "Location %s is complete", location);
serializedPages.add(PAGES_SERDE.serialize(page));
}
代码示例来源:origin: redisson/redisson
private void fetchFromScheduledTaskQueue() {
long nanoTime = AbstractScheduledEventExecutor.nanoTime();
Runnable scheduledTask = pollScheduledTask(nanoTime);
while (scheduledTask != null) {
taskQueue.add(scheduledTask);
scheduledTask = pollScheduledTask(nanoTime);
}
}
代码示例来源:origin: code4craft/webmagic
@Override
public void pushWhenNoDuplicate(Request request, Task task) {
if (request.getPriority() == 0) {
noPriorityQueue.add(request);
} else if (request.getPriority() > 0) {
priorityQueuePlus.put(request);
} else {
priorityQueueMinus.put(request);
}
}
代码示例来源:origin: square/okhttp
private void pushPromises(Http2Stream stream, RecordedRequest request,
List<PushPromise> promises) throws IOException {
for (PushPromise pushPromise : promises) {
List<Header> pushedHeaders = new ArrayList<>();
pushedHeaders.add(new Header(Header.TARGET_AUTHORITY, url(pushPromise.path()).host()));
pushedHeaders.add(new Header(Header.TARGET_METHOD, pushPromise.method()));
pushedHeaders.add(new Header(Header.TARGET_PATH, pushPromise.path()));
Headers pushPromiseHeaders = pushPromise.headers();
for (int i = 0, size = pushPromiseHeaders.size(); i < size; i++) {
pushedHeaders.add(new Header(pushPromiseHeaders.name(i), pushPromiseHeaders.value(i)));
}
String requestLine = pushPromise.method() + ' ' + pushPromise.path() + " HTTP/1.1";
List<Integer> chunkSizes = Collections.emptyList(); // No chunked encoding for HTTP/2.
requestQueue.add(new RecordedRequest(requestLine, pushPromise.headers(), chunkSizes, 0,
new Buffer(), sequenceNumber.getAndIncrement(), socket));
boolean hasBody = pushPromise.response().getBody() != null;
Http2Stream pushedStream =
stream.getConnection().pushStream(stream.getId(), pushedHeaders, hasBody);
writeResponse(pushedStream, request, pushPromise.response());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!