本文整理了Java中java.util.concurrent.LinkedBlockingQueue.poll()
方法的一些代码示例,展示了LinkedBlockingQueue.poll()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LinkedBlockingQueue.poll()
方法的具体详情如下:
包路径:java.util.concurrent.LinkedBlockingQueue
类名称:LinkedBlockingQueue
方法名:poll
暂无
代码示例来源:origin: code4craft/webmagic
public ScriptEngine getEngine() {
availableCount.decrementAndGet();
return scriptEngines.poll();
}
代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba
public static void addReceiveMessageEntity(
ReceiveMessageEntity receiveMessageEntity) {
if (RECEIVE_MESSAGE_ENTITIES.offer(receiveMessageEntity)) {
return;
}
RECEIVE_MESSAGE_ENTITIES.poll();
RECEIVE_MESSAGE_ENTITIES.offer(receiveMessageEntity);
}
代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba
public static void addSendSmsRequest(SendSmsRequest sendSmsRequest) {
if (SEND_SMS_REQUESTS.offer(sendSmsRequest)) {
return;
}
try {
SEND_REENTRANT_LOCK.lock();
SEND_SMS_REQUESTS.poll();
SEND_SMS_REQUESTS.offer(sendSmsRequest);
}
finally {
SEND_REENTRANT_LOCK.unlock();
}
}
代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba
public static void addSendBatchSmsRequest(SendBatchSmsRequest sendBatchSmsRequest) {
if (SEND_BATCH_SMS_REQUESTS.offer(sendBatchSmsRequest)) {
return;
}
try {
SEND_BATCH_REENTRANT_LOCK.lock();
SEND_BATCH_SMS_REQUESTS.poll();
SEND_BATCH_SMS_REQUESTS.offer(sendBatchSmsRequest);
}
finally {
SEND_BATCH_REENTRANT_LOCK.unlock();
}
}
代码示例来源:origin: apache/zookeeper
public void run() {
while (!stop) {
try {
ToSend m = sendqueue.poll(3000, TimeUnit.MILLISECONDS);
if(m == null) continue;
process(m);
} catch (InterruptedException e) {
break;
}
}
LOG.info("WorkerSender is down");
}
代码示例来源:origin: crossoverJie/JCSprout
public static void main(String[] args) throws InterruptedException {
CacheLoaderTest cacheLoaderTest = new CacheLoaderTest() ;
cacheLoaderTest.init();
while (true) {
try {
Integer integer = QUEUE.poll(200, TimeUnit.MILLISECONDS);
if (null == integer) {
break;
}
//TimeUnit.SECONDS.sleep(5);
cacheLoaderTest.checkAlert(integer);
LOGGER.info("job running times={}", integer);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: apache/zookeeper
private WatchedEvent getEvent(int numTries) throws InterruptedException {
WatchedEvent event = null;
for (int i = 0; i < numTries; i++) {
System.out.println("i = " + i);
event = events.poll(10, TimeUnit.SECONDS);
if (event != null) {
break;
}
Thread.sleep(5000);
}
return event;
}
代码示例来源:origin: apache/storm
public static Object pollMessage(int port) {
readerArrived(port);
return getQueue(port).poll();
}
代码示例来源:origin: apache/storm
/**
* Get an assignments from the target queue with the specific index.
* @param queueIndex index of the queue
* @return an {@link NodeAssignments}
* @throws InterruptedException
*/
public NodeAssignments nextAssignments(Integer queueIndex) throws InterruptedException {
NodeAssignments target = null;
while (true) {
target = getQueueById(queueIndex).poll();
if (target != null) {
return target;
}
Time.sleep(100L);
}
}
代码示例来源:origin: apache/hive
public synchronized void setRecordReader(LlapBaseRecordReader recordReader) {
this.recordReader = recordReader;
if (recordReader == null) {
return;
}
// If any events were queued by the responder, give them to the record reader now.
while (!queuedEvents.isEmpty()) {
ReaderEvent readerEvent = queuedEvents.poll();
LOG.debug("Sending queued event to record reader: " + readerEvent.getEventType());
recordReader.handleEvent(readerEvent);
}
}
代码示例来源:origin: jankotek/mapdb
/**
* Queue contains all elements of collection used to initialize
*/
public void testConstructor6() {
Integer[] ints = new Integer[SIZE];
for (int i = 0; i < SIZE; ++i)
ints[i] = new Integer(i);
LinkedBlockingQueue q = new LinkedBlockingQueue(Arrays.asList(ints));
for (int i = 0; i < SIZE; ++i)
assertEquals(ints[i], q.poll());
}
代码示例来源:origin: apache/zookeeper
public void assertEvent(long timeout, EventType eventType) {
try {
WatchedEvent event = dataEvents.poll(timeout,
TimeUnit.MILLISECONDS);
Assert.assertNotNull("do not receive a " + eventType, event);
Assert.assertEquals(eventType, event.getType());
} catch (InterruptedException e) {
LOG.warn("ignoring interrupt during EventsWatcher assertEvent");
}
}
}
代码示例来源:origin: apache/zookeeper
public void verify(List<EventType> expected) throws InterruptedException{
WatchedEvent event;
int count = 0;
while (count < expected.size()
&& (event = events.poll(30, TimeUnit.SECONDS)) != null)
{
Assert.assertEquals(expected.get(count), event.getType());
count++;
}
Assert.assertEquals(expected.size(), count);
events.clear();
}
}
代码示例来源:origin: jankotek/mapdb
/**
* poll succeeds unless empty
*/
public void testPoll() {
LinkedBlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.poll());
}
assertNull(q.poll());
}
代码示例来源:origin: jankotek/mapdb
/**
* timed poll with zero timeout succeeds when non-empty, else times out
*/
public void testTimedPoll0() throws InterruptedException {
LinkedBlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.poll(0, MILLISECONDS));
}
assertNull(q.poll(0, MILLISECONDS));
}
代码示例来源:origin: jankotek/mapdb
public void realRun() throws InterruptedException {
assertNull(q.poll());
threadsStarted.await();
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
checkEmpty(q);
}});
代码示例来源:origin: jankotek/mapdb
/**
* toArray contains all elements in FIFO order
*/
public void testToArray() {
LinkedBlockingQueue q = populatedQueue(SIZE);
Object[] o = q.toArray();
for (int i = 0; i < o.length; i++)
assertSame(o[i], q.poll());
}
代码示例来源:origin: jankotek/mapdb
/**
* contains(x) reports true when elements added but not yet removed
*/
public void testContains() {
LinkedBlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.contains(new Integer(i)));
q.poll();
assertFalse(q.contains(new Integer(i)));
}
}
代码示例来源:origin: jankotek/mapdb
/**
* toArray(a) contains all elements in FIFO order
*/
public void testToArray2() throws InterruptedException {
LinkedBlockingQueue<Integer> q = populatedQueue(SIZE);
Integer[] ints = new Integer[SIZE];
Integer[] array = q.toArray(ints);
assertSame(ints, array);
for (int i = 0; i < ints.length; i++)
assertSame(ints[i], q.poll());
}
代码示例来源:origin: jankotek/mapdb
/**
* peek returns next element, or null if empty
*/
public void testPeek() {
LinkedBlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.peek());
assertEquals(i, q.poll());
assertTrue(q.peek() == null ||
!q.peek().equals(i));
}
assertNull(q.peek());
}
内容来源于网络,如有侵权,请联系作者删除!