java.util.concurrent.LinkedBlockingQueue.put()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中java.util.concurrent.LinkedBlockingQueue.put()方法的一些代码示例,展示了LinkedBlockingQueue.put()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LinkedBlockingQueue.put()方法的具体详情如下:
包路径:java.util.concurrent.LinkedBlockingQueue
类名称:LinkedBlockingQueue
方法名:put

LinkedBlockingQueue.put介绍

[英]Inserts the specified element at the tail of this queue, waiting if necessary for space to become available.
[中]

代码示例

代码示例来源:origin: alibaba/canal

public void execute(Runnable runnable) throws InterruptedException {
  taskQueue.put(runnable);
}

代码示例来源:origin: apache/storm

/**
 * The tuple emitted by this spout with the msgId identifier has failed to be
 * fully processed. Typically, an implementation of this method will put that
 * message back on the queue to be replayed at a later time.
 *
 * @param msgId
 */
public void fail(Object msgId) {
  try {
    this.incoming.put(this.pending.remove(msgId));
  } catch (InterruptedException e) {
    LOG.warn("Interrupted while re-queueing message.", e);
  }
}

代码示例来源:origin: apache/storm

/**
 * put bolt message to its queue
 *
 * @param boltMsg BoltMsg to pass to subprocess
 * @throws InterruptedException
 */
public void putBoltMsg(BoltMsg boltMsg) throws InterruptedException {
  boltMsgQueue.put(boltMsg);
  takeLock.lock();
  try {
    notEmpty.signal();
  } finally {
    takeLock.unlock();
  }
}

代码示例来源:origin: crossoverJie/JCSprout

private void init() throws InterruptedException {
  loadingCache = CacheBuilder.newBuilder()
      .expireAfterWrite(2, TimeUnit.SECONDS)
      .removalListener(new RemovalListener<Object, Object>() {
        @Override
        public void onRemoval(RemovalNotification<Object, Object> notification) {
          LOGGER.info("删除原因={},删除 key={},删除 value={}",notification.getCause(),notification.getKey(),notification.getValue());
        }
      })
      .build(new CacheLoader<Integer, AtomicLong>() {
        @Override
        public AtomicLong load(Integer key) throws Exception {
          return new AtomicLong(0);
        }
      });
  for (int i = 10; i < 15; i++) {
    QUEUE.put(i);
  }
}

代码示例来源:origin: apache/incubator-druid

public void announceSegment(final DataSegment segment) throws InterruptedException
{
 if (finished) {
  throw new ISE("Announce segment called after finishAnnouncing");
 }
 queue.put(segment);
}

代码示例来源:origin: apache/rocketmq

public void executePullRequestImmediately(final PullRequest pullRequest) {
  try {
    this.pullRequestQueue.put(pullRequest);
  } catch (InterruptedException e) {
    log.error("executePullRequestImmediately pullRequestQueue.put", e);
  }
}

代码示例来源:origin: alibaba/jstorm

@Override
  public void execute(String stream, List<Integer> outTasks, List values) {
    if (shellMsg.areTaskIdsNeeded()) {
      try {
        _pendingWrites.put(outTasks);
      } catch (InterruptedException e) {
        LOG.warn("Skip write outTasks", e);
      }
    }
  }
}

代码示例来源:origin: apache/incubator-druid

@Override
 public void onChannelMessage(ChannelPrivMsg aMsg)
 {
  try {
   queue.put(Pair.of(DateTimes.nowUtc(), aMsg));
  }
  catch (InterruptedException e) {
   throw new RuntimeException("interrupted adding message to queue", e);
  }
 }
}

代码示例来源:origin: apache/zookeeper

@Override
  public void process(WatchedEvent event) {
    try {
      states.put(event.getState());
    } catch (InterruptedException e) {}
  }
});

代码示例来源:origin: apache/storm

public void onPublish(UTF8Buffer topic, Buffer payload, Runnable ack) {
  LOG.debug("Received message: topic={}, payload={}", topic.toString(), new String(payload.toByteArray()));
  try {
    this.incoming.put(new AckableMessage(topic.toString(), payload.toByteArray(), ack));
  } catch (InterruptedException e) {
    LOG.warn("Interrupted while queueing an MQTT message.");
  }
}

代码示例来源:origin: apache/zookeeper

public void process(WatchedEvent event) {
    super.process(event);
    if (event.getType() != EventType.None) {
      try {
        events.put(event);
      } catch (InterruptedException e) {
        LOG.warn("ignoring interrupt during event.put");
      }
    }
  }
}

代码示例来源:origin: apache/zookeeper

public void process(WatchedEvent event) {
    super.process(event);
    if (event.getType() != Event.EventType.None) {
      timeOfLastWatcherInvocation = System.currentTimeMillis();
      try {
        events.put(event);
      } catch (InterruptedException e) {
        LOG.warn("ignoring interrupt during event.put");
      }
    }
  }
}

代码示例来源:origin: apache/zookeeper

public void process(WatchedEvent event) {
    super.process(event);
    if (event.getType() != Event.EventType.None) {
      try {
        events.put(event);
      } catch (InterruptedException e) {
        LOG.warn("ignoring interrupt during event.put");
      }
    }
  }
}

代码示例来源:origin: apache/zookeeper

public void process(WatchedEvent event) {
    super.process(event);
    if (event.getType() != Event.EventType.None) {
      try {
        events.put(event);
      } catch (InterruptedException e) {
        LOG.warn("ignoring interrupt during event.put");
      }
    }
  }
}

代码示例来源:origin: apache/zookeeper

synchronized public void process(WatchedEvent event) {
 try {
  System.out.println("Got an event " + event.toString());
  events.put(event);
 } catch (InterruptedException e) {
  e.printStackTrace();
 }
}

代码示例来源:origin: apache/zookeeper

@Override
public void process(WatchedEvent event) {
  super.process(event);
  try {
    if (event.getType() != Event.EventType.None) {
      dataEvents.put(event);
    }
  } catch (InterruptedException e) {
    LOG.warn("ignoring interrupt during EventsWatcher process");
  }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

public State onBodyPartReceived(HttpResponseBodyPart e) throws Exception {
 byte[] bytes = e.getBodyPartBytes();
 if (bytes.length != 0) {
  String s = new String(bytes);
  logger.info("got part: {}", s);
  logger.warn("Sampling stacktrace.", new Throwable("trace that, we should not get called for empty body."));
  queue.put(s);
 }
 return State.CONTINUE;
}

代码示例来源:origin: jankotek/mapdb

public void realRun() throws InterruptedException {
      threadsStarted.await();
      q.put(one);
    }});
}

代码示例来源:origin: AsyncHttpClient/async-http-client

public State onBodyPartReceived(HttpResponseBodyPart e) throws Exception {
 if (e.length() != 0) {
  String s = new String(e.getBodyPartBytes());
  logger.info("got part: {}", s);
  queue.put(s);
 }
 return State.CONTINUE;
}

代码示例来源:origin: jankotek/mapdb

/**
 * all elements successfully put are contained
 */
public void testPut() throws InterruptedException {
  LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
  for (int i = 0; i < SIZE; ++i) {
    Integer x = new Integer(i);
    q.put(x);
    assertTrue(q.contains(x));
  }
  assertEquals(0, q.remainingCapacity());
}

相关文章

微信公众号

最新文章

更多