当前位置 : 主页 > 网络编程 > 其它编程 >

com.google.common.collect.Queues.drainUninterruptibly()方法的使用及代码示例

来源:互联网 收集:自由互联 发布时间:2023-07-02
本文整理了Java中com.google.common.collect.Queues.drainUninterruptibly方法的一些代码示例,展示了Qu 本文整理了Java中com.google.common.collect.Queues.drainUninterruptibly方法的一些代码示例,展示了Queues.dra
本文整理了Java中com.google.common.collect.Queues.drainUninterruptibly方法的一些代码示例,展示了Qu

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

Queues.drainUninterruptibly介绍

[英]Drains the queue as #drain(BlockingQueue,Collection,int,long,TimeUnit), but with a different behavior in case it is interrupted while waiting. In that case, the operation will continue as usual, and in the end the thread's interruption status will be set (no InterruptedException is thrown).[中]将队列作为#drain(BlockingQueue、Collection、int、long、TimeUnit)排出,但如果在等待时被中断,则使用不同的行为。在这种情况下,操作将照常继续,最后将设置线程的中断状态(不会引发InterruptedException)。

代码示例

代码示例来源:origin: google/guava

private static int drain( BlockingQueue q, Collection buffer, int maxElements, long timeout, TimeUnit unit, boolean interruptibly) throws InterruptedException { return interruptibly ? Queues.drain(q, buffer, maxElements, timeout, unit) : Queues.drainUninterruptibly(q, buffer, maxElements, timeout, unit);}

代码示例来源:origin: google/guava

private void assertUninterruptibleDrained(BlockingQueue q) { assertEquals(0, Queues.drainUninterruptibly(q, ImmutableList.of(), 0, 10, MILLISECONDS)); // but does the wait actually occurs? @SuppressWarnings("unused") // go/futurereturn-lsc Future possiblyIgnoredError = threadPool.submit(new Interrupter(currentThread())); Stopwatch timer = Stopwatch.createStarted(); Queues.drainUninterruptibly(q, newArrayList(), 1, 10, MILLISECONDS); assertThat(timer.elapsed(MILLISECONDS)).isAtLeast(10L); // wait for interrupted status and clear it while (!Thread.interrupted()) { Thread.yield(); }}

代码示例来源:origin: google/guava

private void testDrainUninterruptibly_doesNotThrow(final BlockingQueue q) { final Thread mainThread = currentThread(); @SuppressWarnings("unused") // go/futurereturn-lsc Future possiblyIgnoredError = threadPool.submit( new Callable() { public Void call() throws InterruptedException { new Producer(q, 50).call(); new Interrupter(mainThread).run(); new Producer(q, 50).call(); return null; } }); List buf = newArrayList(); int elements = Queues.drainUninterruptibly(q, buf, 100, MAX_VALUE, NANOSECONDS); // so when this drains all elements, we know the thread has also been interrupted in between assertTrue(Thread.interrupted()); assertEquals(100, elements); assertEquals(100, buf.size());}

代码示例来源:origin: com.google.guava/guava-tests

private static int drain( BlockingQueue q, Collection buffer, int maxElements, long timeout, TimeUnit unit, boolean interruptibly) throws InterruptedException { return interruptibly ? Queues.drain(q, buffer, maxElements, timeout, unit) : Queues.drainUninterruptibly(q, buffer, maxElements, timeout, unit);}

代码示例来源:origin: apache/jackrabbit-oak

@Overridepublic void run() { startLatch.countDown(); while (!stop.get()) { List revs = Lists.newArrayList(); Queues.drainUninterruptibly(revisionQueue, revs, 5, 100, TimeUnit.MILLISECONDS); record(revs); } List revs = Lists.newArrayList(); revisionQueue.drainTo(revs); record(revs);}

代码示例来源:origin: com.google.guava/guava-tests

private void assertUninterruptibleDrained(BlockingQueue q) { assertEquals(0, Queues.drainUninterruptibly(q, ImmutableList.of(), 0, 10, MILLISECONDS)); // but does the wait actually occurs? @SuppressWarnings("unused") // go/futurereturn-lsc Future possiblyIgnoredError = threadPool.submit(new Interrupter(currentThread())); Stopwatch timer = Stopwatch.createStarted(); Queues.drainUninterruptibly(q, newArrayList(), 1, 10, MILLISECONDS); assertThat(timer.elapsed(MILLISECONDS)).isAtLeast(10L); // wait for interrupted status and clear it while (!Thread.interrupted()) { Thread.yield(); }}

代码示例来源:origin: com.google.guava/guava-tests

private void testDrainUninterruptibly_doesNotThrow(final BlockingQueue q) { final Thread mainThread = currentThread(); @SuppressWarnings("unused") // go/futurereturn-lsc Future possiblyIgnoredError = threadPool.submit( new Callable() { public Void call() throws InterruptedException { new Producer(q, 50).call(); new Interrupter(mainThread).run(); new Producer(q, 50).call(); return null; } }); List buf = newArrayList(); int elements = Queues.drainUninterruptibly(q, buf, 100, MAX_VALUE, NANOSECONDS); // so when this drains all elements, we know the thread has also been interrupted in between assertTrue(Thread.interrupted()); assertEquals(100, elements); assertEquals(100, buf.size());}

上一篇:CSSfloat定位和缩放问题
下一篇:没有了
网友评论